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

Running unit tests in watch mode throws error #48427

Open
getdave opened this issue Feb 24, 2023 · 6 comments
Open

Running unit tests in watch mode throws error #48427

getdave opened this issue Feb 24, 2023 · 6 comments
Labels
[Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. [Type] Bug An existing feature does not function as intended

Comments

@getdave
Copy link
Contributor

getdave commented Feb 24, 2023

For a long while now I've tried to run unit tests with watch and it always fails.

Example command:

npm run test:unit:watch packages/block-editor/src/hooks/test/duotone.js

Here's the error (with parts redacted):

Error: Failed to initialize watch plugin "node_modules/jest-watch-typeahead/filename.js":

  ● Test suite failed to run

    file:///{{PATH_TO_MY_REPO}}/gutenberg/node_modules/jest-watch-typeahead/build/file_name_plugin/prompt.js:4
    import { PatternPrompt, printPatternCaret, printRestoredPatternCaret } from 'jest-watcher';
                            ^^^^^^^^^^^^^^^^^
    SyntaxError: Named export 'printPatternCaret' not found. The requested module 'jest-watcher' is a CommonJS module, which may not support all module.exports as named exports.
    CommonJS modules can always be imported via the default export, for example using:

    import pkg from 'jest-watcher';
    const { PatternPrompt, printPatternCaret, printRestoredPatternCaret } = pkg;

      at async requireOrImportModule (node_modules/@jest/core/node_modules/jest-util/build/requireOrImportModule.js:65:32)
      at async watch (node_modules/@jest/core/build/watch.js:337:34)
      at async _run10000 (node_modules/@jest/core/build/cli/index.js:311:7)
      at async runCLI (node_modules/@jest/core/build/cli/index.js:173:3)

I don't understand why this is happening. I wonder if folks experienced in test setup might be able to help. Particularly @kevin940726.

@getdave getdave added [Type] Bug An existing feature does not function as intended [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. labels Feb 24, 2023
@t-hamano
Copy link
Contributor

It appears to be working correctly in my environment.

Example command:

npm run test:unit:watch packages/block-editor/src/hooks/duotone.js

I think you need to specify a test file:

npm run test:unit:watch packages/block-editor/src/hooks/test/duotone.js

The following is how it works. You can see the watch mode starting at around 28 seconds.

3af6bfe660da649d73517a9279e46472.mp4

@kevin940726
Copy link
Member

I'm not getting that error either. Maybe try reinstalling the dependencies to be sure?

@getdave
Copy link
Contributor Author

getdave commented Feb 27, 2023

It's been a problem for a while for me. This isn't a new thing. I'm installed dependencies.

I'm using zsh shell and wondering if that's having any form of impact on watcher or something like that.

@kevin940726
Copy link
Member

kevin940726 commented Feb 27, 2023

I'm also using zsh so I doubt that.

What's your Node.js version? And npm version? I'm not getting the error even when I installed the latest Node version though.

@t-hamano
Copy link
Contributor

Is this due to the Node version being lower than 14.17.0 as reported in create-react-app issue?

@getdave
Copy link
Contributor Author

getdave commented Feb 27, 2023

  • npm 6.14.18
  • node v14.16.1

I'll see if upgrading Node works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

3 participants