Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestRunner.mock.module problem while importing playwright/test #53691

Closed
AcePeed opened this issue Jul 2, 2024 · 4 comments
Closed

TestRunner.mock.module problem while importing playwright/test #53691

AcePeed opened this issue Jul 2, 2024 · 4 comments
Labels
wrong repo Issues that should be opened in another repository.

Comments

@AcePeed
Copy link

AcePeed commented Jul 2, 2024

Version

v22.3.0

Platform

Darwin MacBook-Pro.local 23.5.0 Darwin Kernel Version 23.5.0: Wed May  1 20:13:18 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6030 arm64

Subsystem

No response

What steps will reproduce the bug?

  1. Run these commands
npm init
npm install plawright
touch main.js
touch module.js
  1. Add "type":"module" in package.json
  2. Paste this code into module.js
import { test } from "playwright/test";

export const dummy = ''
  1. Paste this code into main.js
import {mock} from "node:test";

// The module to mock could be anything
mock.module('node:fs')

const {dummy} = await import("./module.js");
  1. Run node --experimental-test-module-mocks --experimental-require-module --experimental-detect-module module.js. Normally everything worked correctly

Note: the flags are needed to be able to use mock.module

  1. Run node --experimental-test-module-mocks --experimental-require-module --experimental-detect-module main.js. Here you should see an error:
import { test } from "playwright/test";
         ^^^^
SyntaxError: The requested module 'playwright/test' does not provide an export named 'test'

What if I use const { test } = await import("playwright/test") instead

Now module.js is:

const { test } = await import("playwright/test");

export const dummy = ''

I get a new error:

node:internal/util:399
  validateFunction(original, 'original');
  ^

TypeError [ERR_INVALID_ARG_TYPE]: The "original" argument must be of type function. Received undefined
    at promisify (node:internal/util:399:3)
    at /path_to_project/node_modules/playwright/lib/utilsBundleImpl.js:51:24844
    at /path_to_project/node_modules/playwright/lib/utilsBundleImpl.js:1:222
    at /path_to_project/node_modules/playwright/lib/utilsBundleImpl.js:52:19158
    at /path_to_project/node_modules/playwright/lib/utilsBundleImpl.js:1:222
    at Object.<anonymous> (/path_to_project/node_modules/playwright/lib/utilsBundleImpl.js:52:30370)
    at Module._compile (node:internal/modules/cjs/loader:1460:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1544:10)
    at Module.load (node:internal/modules/cjs/loader:1275:32)
    at Module._load (node:internal/modules/cjs/loader:1091:12) {
  code: 'ERR_INVALID_ARG_TYPE'
}

Node.js v22.3.0

How often does it reproduce? Is there a required condition?

It is reproduced every single time, normally without a condition.

What is the expected behavior? Why is that the expected behavior?

The expected behaviour is that the import occurs correctly and playwright is imported

What do you see instead?

An error (with import { test } from "playwright/test"):

import { test } from "playwright/test";
         ^^^^
SyntaxError: The requested module 'playwright/test' does not provide an export named 'test'

With const { test } = await import("playwright/test")

node:internal/util:399
  validateFunction(original, 'original');
  ^

TypeError [ERR_INVALID_ARG_TYPE]: The "original" argument must be of type function. Received undefined
    at promisify (node:internal/util:399:3)
    at /path_to_project/mock-issue/node_modules/playwright/lib/utilsBundleImpl.js:51:24844
    at /path_to_project/node_modules/playwright/lib/utilsBundleImpl.js:1:222
    at /path_to_project/node_modules/playwright/lib/utilsBundleImpl.js:52:19158
    at /path_to_project/node_modules/playwright/lib/utilsBundleImpl.js:1:222
    at Object.<anonymous> (/path_to_project/node_modules/playwright/lib/utilsBundleImpl.js:52:30370)
    at Module._compile (node:internal/modules/cjs/loader:1460:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1544:10)
    at Module.load (node:internal/modules/cjs/loader:1275:32)
    at Module._load (node:internal/modules/cjs/loader:1091:12) {
  code: 'ERR_INVALID_ARG_TYPE'
}

Node.js v22.3.0

Additional information

No response

@AcePeed AcePeed changed the title TestRunner.Mock.module problem with importing playwright/test TestRunner.mock.module problem with importing playwright/test Jul 2, 2024
@AcePeed AcePeed changed the title TestRunner.mock.module problem with importing playwright/test TestRunner.mock.module problem while importing playwright/test Jul 2, 2024
@RedYetiDev
Copy link
Member

Hi! Can this be reproduced without any dependencies (such as playwright)?

@RedYetiDev RedYetiDev added loaders Issues and PRs related to ES module loaders test_runner Issues and PRs related to the test runner subsystem. labels Jul 2, 2024
@AcePeed
Copy link
Author

AcePeed commented Jul 2, 2024

I've tried with some node packages, it seems to work fine.

Note: It works fine with playwright, the problem is with playwright/test

@MoLow
Copy link
Member

MoLow commented Jul 2, 2024

Please open an issue in the playwright repository, this is not an issue in node's core

@MoLow MoLow closed this as not planned Won't fix, can't repro, duplicate, stale Jul 2, 2024
@cjihrig
Copy link
Contributor

cjihrig commented Jul 2, 2024

Are we sure this isn't the issue @GeoffreyBooth is fixing in #53642?

@RedYetiDev RedYetiDev added wrong repo Issues that should be opened in another repository. and removed loaders Issues and PRs related to ES module loaders test_runner Issues and PRs related to the test runner subsystem. labels Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wrong repo Issues that should be opened in another repository.
Projects
None yet
Development

No branches or pull requests

4 participants