Angular 开玩笑测试`测试套件未能 运行`
Angular Jest testing `Test suite failed to run`
我无法从我的 npm run test
中获得任何正确的测试结果。出现以下错误。如何解决?
FAIL src/app/shared-components/services/shared-service.spec.ts
● Test suite failed to run
D:\IBO\Project\IBO-UI\NG-IBO\src\setup-jest.ts:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import 'jest-preset-angular';
^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Unexpected string
at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:471:17)
at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:513:25)
at Array.forEach (<anonymous>)
有人帮我解决这个问题吗?
这是日志文件
0 info it worked if it ends with ok
1 verbose cli [ 'C:\Program Files\nodejs\node.exe',
1 verbose cli 'C:\Users\722333\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'test' ]
2 info using npm@6.9.1-next.0
3 info using node@v11.10.0
4 verbose run-script [ 'pretest', 'test', 'posttest' ]
5 info lifecycle ibo@0.0.0~pretest: ibo@0.0.0
6 info lifecycle ibo@0.0.0~test: ibo@0.0.0
7 verbose lifecycle ibo@0.0.0~test: unsafe-perm in lifecycle true
8 verbose lifecycle ibo@0.0.0~test: PATH: C:\Users2333\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;D:\IBO\Project\IBO-UI\NG-IBO\node_modules\.bin;C:\Users2333\AppData\Local\Programs\Python\Python37-32\Scripts\;C:\Users2333\AppData\Local\Programs\Python\Python37-32\;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\system32\config\systemprofile\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files\Microsoft SQL Server0\Tools\Binn\;C:\Program Files\Microsoft SQL Server0\Tools\Binn\;C:\Program Files\Git\cmd;C:\Program Files\nodejs\;C:\Users2333\AppData\Local\Microsoft\WindowsApps;D:\mongodb\bin;D:\Git\bin;C:\Users2333\AppData\Local\Programs\Common\Microsoft VS Code\bin;C:\Users2333\AppData\Roaming\npm;C:\Users2333\AppData\Local\Programs\Python\Python37-32;
9 verbose lifecycle ibo@0.0.0~test: CWD: D:\IBO\Project\IBO-UI\NG-IBO
10 silly lifecycle ibo@0.0.0~test: Args: [ '/d /s /c', 'jest' ]
11 silly lifecycle ibo@0.0.0~test: Returned: code: 1 signal: null
12 info lifecycle ibo@0.0.0~test: Failed to exec test script
13 verbose stack Error: ibo@0.0.0 test: `jest`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (C:\Users2333\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\index.js:301:16)
13 verbose stack at EventEmitter.emit (events.js:197:13)
13 verbose stack at ChildProcess.<anonymous> (C:\Users2333\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:197:13)
13 verbose stack at maybeClose (internal/child_process.js:984:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:265:5)
14 verbose pkgid ibo@0.0.0
15 verbose cwd D:\IBO\Project\IBO-UI\NG-IBO
16 verbose Windows_NT 10.0.15063
17 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Users\722333\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js" "run" "test"
18 verbose node v11.10.0
19 verbose npm v6.9.1-next.0
20 error code ELIFECYCLE
21 error errno 1
22 error ibo@0.0.0 test: `jest`
22 error Exit status 1
23 error Failed at the ibo@0.0.0 test script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
在不知道您的 jest.config.js 文件或您的全局 jest 配置的情况下,我会说您没有正确配置 exposed configuration。更具体地说 transform 属性。它应该是这样的:
module.exports = {
...
transform: {
"^.+\.(ts|js|html)$": "ts-jest"
},
};
有关该主题的更多帮助,请阅读 this。
希望对您有所帮助!
我无法从我的 npm run test
中获得任何正确的测试结果。出现以下错误。如何解决?
FAIL src/app/shared-components/services/shared-service.spec.ts
● Test suite failed to run
D:\IBO\Project\IBO-UI\NG-IBO\src\setup-jest.ts:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import 'jest-preset-angular';
^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Unexpected string
at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:471:17)
at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:513:25)
at Array.forEach (<anonymous>)
有人帮我解决这个问题吗?
这是日志文件
0 info it worked if it ends with ok
1 verbose cli [ 'C:\Program Files\nodejs\node.exe',
1 verbose cli 'C:\Users\722333\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'test' ]
2 info using npm@6.9.1-next.0
3 info using node@v11.10.0
4 verbose run-script [ 'pretest', 'test', 'posttest' ]
5 info lifecycle ibo@0.0.0~pretest: ibo@0.0.0
6 info lifecycle ibo@0.0.0~test: ibo@0.0.0
7 verbose lifecycle ibo@0.0.0~test: unsafe-perm in lifecycle true
8 verbose lifecycle ibo@0.0.0~test: PATH: C:\Users2333\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;D:\IBO\Project\IBO-UI\NG-IBO\node_modules\.bin;C:\Users2333\AppData\Local\Programs\Python\Python37-32\Scripts\;C:\Users2333\AppData\Local\Programs\Python\Python37-32\;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\system32\config\systemprofile\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files\Microsoft SQL Server0\Tools\Binn\;C:\Program Files\Microsoft SQL Server0\Tools\Binn\;C:\Program Files\Git\cmd;C:\Program Files\nodejs\;C:\Users2333\AppData\Local\Microsoft\WindowsApps;D:\mongodb\bin;D:\Git\bin;C:\Users2333\AppData\Local\Programs\Common\Microsoft VS Code\bin;C:\Users2333\AppData\Roaming\npm;C:\Users2333\AppData\Local\Programs\Python\Python37-32;
9 verbose lifecycle ibo@0.0.0~test: CWD: D:\IBO\Project\IBO-UI\NG-IBO
10 silly lifecycle ibo@0.0.0~test: Args: [ '/d /s /c', 'jest' ]
11 silly lifecycle ibo@0.0.0~test: Returned: code: 1 signal: null
12 info lifecycle ibo@0.0.0~test: Failed to exec test script
13 verbose stack Error: ibo@0.0.0 test: `jest`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (C:\Users2333\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\index.js:301:16)
13 verbose stack at EventEmitter.emit (events.js:197:13)
13 verbose stack at ChildProcess.<anonymous> (C:\Users2333\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:197:13)
13 verbose stack at maybeClose (internal/child_process.js:984:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:265:5)
14 verbose pkgid ibo@0.0.0
15 verbose cwd D:\IBO\Project\IBO-UI\NG-IBO
16 verbose Windows_NT 10.0.15063
17 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Users\722333\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js" "run" "test"
18 verbose node v11.10.0
19 verbose npm v6.9.1-next.0
20 error code ELIFECYCLE
21 error errno 1
22 error ibo@0.0.0 test: `jest`
22 error Exit status 1
23 error Failed at the ibo@0.0.0 test script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
在不知道您的 jest.config.js 文件或您的全局 jest 配置的情况下,我会说您没有正确配置 exposed configuration。更具体地说 transform 属性。它应该是这样的:
module.exports = {
...
transform: {
"^.+\.(ts|js|html)$": "ts-jest"
},
};
有关该主题的更多帮助,请阅读 this。 希望对您有所帮助!