ext-saladict icon indicating copy to clipboard operation
ext-saladict copied to clipboard

All tests fail

Open FantasqueX opened this issue 2 years ago • 4 comments

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.

FantasqueX avatar Jun 26 '22 07:06 FantasqueX

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

crimx avatar Jun 26 '22 07:06 crimx

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

FantasqueX avatar Jun 26 '22 07:06 FantasqueX

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.

crimx avatar Jun 26 '22 08:06 crimx

According to https://github.com/node-fetch/node-fetch/issues/1391, I think we need to downgrade node-fetch due to old jest

FantasqueX avatar Jun 26 '22 10:06 FantasqueX

node-fetch version 2.6.7 is testable

zwjjiaozhu avatar Oct 08 '22 03:10 zwjjiaozhu