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

All tests fail #1779

Open
FantasqueX opened this issue Jun 26, 2022 · 5 comments · May be fixed by #1781
Open

All tests fail #1779

FantasqueX opened this issue Jun 26, 2022 · 5 comments · May be fixed by #1781

Comments

@FantasqueX
Copy link
Contributor

Device info

  • OS: [ArchLinux]
  • Saladict Version [dev branch]

Describe the bug

When running test suite yarn test, yarn complains that all tests fail.

Test Suites: 35 failed, 35 total
Tests:       0 total
Snapshots:   0 total
Time:        23.444 s
Ran all test suites.

An example log is listed below.

 FAIL  test/specs/_helpers/browser-api.spec.ts
  ● Test suite failed to run

    Jest encountered an unexpected token

    This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

    By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".

    Here's what you can do:
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/en/configuration.html

    Details:

    /home/fanta/tmp/ext-saladict/node_modules/node-fetch/src/index.js:9
    import http from 'node:http';
    ^^^^^^

    SyntaxError: Cannot use import statement outside a module

      at compileFunction (node:vm:352:18)
      at Object.<anonymous> (config/jest/setupTests.js:5:1)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)

It seems that all tests fail because jest fails to recognize import.

@crimx
Copy link
Owner

crimx commented Jun 26, 2022

Looks like an incompatible version of node-fetch is installed.

@FantasqueX
Copy link
Contributor Author

My local node-fetch version is 3.1.1. How to fix this problem? Maybe a patch to downgrade node-fetch?

@crimx
Copy link
Owner

crimx commented Jun 26, 2022

3.1.1 should be compatible.

$ yarn why node-fetch

yarn why v1.22.17
[1/4] 🤔  Why do we have the module "node-fetch"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "[email protected]"
info Has been hoisted to "node-fetch"
info This module exists because it's specified in "devDependencies".
info Disk size without dependencies: "180KB"
info Disk size with unique dependencies: "180KB"
info Disk size with transitive dependencies: "180KB"
info Number of shared dependencies: 3
=> Found "cross-fetch#[email protected]"
info This module exists because "jest-fetch-mock#cross-fetch" depends on it.
info Disk size without dependencies: "120KB"
info Disk size with unique dependencies: "120KB"
info Disk size with transitive dependencies: "120KB"
info Number of shared dependencies: 0
=> Found "@storybook/core#[email protected]"
info This module exists because "@storybook#react#@storybook#core" depends on it.
=> Found "isomorphic-fetch#[email protected]"
info This module exists because "@storybook#components#recompose#fbjs#isomorphic-fetch" depends on it.
info Disk size without dependencies: "172KB"
info Disk size with unique dependencies: "648KB"
info Disk size with transitive dependencies: "1.09MB"
info Number of shared dependencies: 4
✨  Done in 1.15s.

@FantasqueX
Copy link
Contributor Author

According to node-fetch/node-fetch#1391, I think we need to downgrade node-fetch due to old jest

@zwjjiaozhu
Copy link

node-fetch version 2.6.7 is testable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants