eleduck / maskhero

与子同袍-援助海外华人计划
https://eleduck.com/maskhero
33 stars 12 forks source link

Jest 测试不通过 #68

Closed baibonjwa closed 4 years ago

baibonjwa commented 4 years ago

执行 npm run test 或 yarn test

错误信息如下:

FAIL src/App.test.js ● 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:

/Users/lele88lala/eleduck/maskhero/node_modules/@amcharts/amcharts4/core.js:8
export { System, system } from "./.internal/core/System";
^^^^^^

SyntaxError: Unexpected token export

> 1 | import * as am4core from "@amcharts/amcharts4/core";
    | ^
  2 | import * as am4maps from "@amcharts/amcharts4/maps";
  3 | import am4geodata_worldLow from "@amcharts/amcharts4-geodata/worldLow";
  4 | import am4geodata_data_countries2 from "@amcharts/amcharts4-geodata/data/countries2";

  at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
  at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25)
  at Object.<anonymous> (src/utils/chartUtils.js:1:1)

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

Watch Usage: Press w to show more

hereiskeith commented 4 years ago

https://stackoverflow.com/questions/52984652/node-js-amcharts4-import-error-unexpected-token-export-using-typesript-or

https://github.com/amcharts/amcharts4/issues/2133

https://stackoverflow.com/questions/58968701/trying-to-integrate-jest-and-react-with-amchart-but-getting-an-error-what-coul

很奇怪 按照stackoverflow和github两个解答方法都弄不出来,不知为什么那个文件就是没有被babel-jest transform

hereiskeith commented 4 years ago

第一个link的答案是他们团队的人写的好像 但第一个link情况跟我们不一样毕竟他是在node下运行的

YuniorZen commented 4 years ago

第一个link的答案是他们团队的人写的好像 但第一个link情况跟我们不一样毕竟他是在node下运行的

"transformIgnorePatterns": [ "[/\\]node_modules[/\\].+\.(js|jsx|ts|tsx)$" ] 同样也不行,没找到答案

hereiskeith commented 4 years ago

第一个link的答案是他们团队的人写的好像 但第一个link情况跟我们不一样毕竟他是在node下运行的

"transformIgnorePatterns": [ "[/\]node_modules[/\].+.(js|jsx|ts|tsx)$" ] 同样也不行,没找到答案

嗯我再想想 明明逻辑和方法思路是对的 不知为什么不行

hereiskeith commented 4 years ago
 PASS  src/App.test.js (9.579s)
  √ renders root component with no error (146ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        12.201s
Ran all test suites.