jest 대 angularfire2에 문제가 있습니다. 농담을 설정 한 다음 오류가 발생했습니다 SyntaxError: Unexpected token export
. 전체 출력 :
PASS src/app/diary/components/diary.spec.ts
FAIL src/app/diary/containers/my-dairy-page.spec.ts
● Test suite failed to run
/Users/svlad/dev/ng2-diary-book/node_modules/angularfire2/auth.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export * from './auth/auth';
^^^^^^
SyntaxError: Unexpected token export
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
at Object.<anonymous> (src/app/core/containers/app.ts:18:14)
at Object.<anonymous> (src/app/core/core.module.ts:15:13)
Test Suites: 1 failed, 1 passed, 2 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 2.467s
디버그 모드에서 출력하여 전체 jest 구성을 볼 수 있습니다.
sharikovvlad:ng2-diary-book svlad$ npm run jest -- --debug
> [email protected] jest /Users/svlad/dev/ng2-diary-book
> jest "--debug"
{
"config": {
"automock": false,
"browser": false,
"cache": true,
"cacheDirectory": "/var/folders/pf/510z0sc56zq3hvfb7lyr0jlr0000gn/T/jest_dx",
"clearMocks": false,
"coveragePathIgnorePatterns": [
"/node_modules/"
],
"globals": {
"ts-jest": {
"tsConfigFile": "src/tsconfig.spec.json"
},
"__TRANSFORM_HTML__": true
},
"haste": {
"providesModuleNodeModules": []
},
"moduleDirectories": [
"node_modules"
],
"moduleFileExtensions": [
"ts",
"js",
"html",
"json"
],
"moduleNameMapper": [
[
"(.*)",
"/Users/svlad/dev/ng2-diary-book/src/$1"
]
],
"modulePathIgnorePatterns": [],
"name": "520410dc90eed72792e9fd01593c2a6d",
"resetMocks": false,
"resetModules": false,
"rootDir": "/Users/svlad/dev/ng2-diary-book",
"roots": [
"/Users/svlad/dev/ng2-diary-book"
],
"setupFiles": [],
"setupTestFrameworkScriptFile": "/Users/svlad/dev/ng2-diary-book/src/setupJest.ts",
"snapshotSerializers": [],
"testEnvironment": "jest-environment-jsdom",
"testMatch": [],
"testPathIgnorePatterns": [
"/node_modules/"
],
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|js)$",
"testRunner": "/Users/svlad/dev/ng2-diary-book/node_modules/jest-jasmine2/build/index.js",
"testURL": "about:blank",
"timers": "real",
"transform": [
[
"^.+\\.(ts|js|html)$",
"/Users/svlad/dev/ng2-diary-book/node_modules/jest-preset-angular/preprocessor.js"
]
],
"transformIgnorePatterns": [
"/Users/svlad/dev/ng2-diary-book/node_modules/(?!@ngrx|angularfire2)"
]
},
"framework": "jasmine2",
"globalConfig": {
"bail": false,
"coverageReporters": [
"json",
"text",
"lcov",
"clover"
],
"expand": false,
"mapCoverage": true,
"noStackTrace": false,
"notify": false,
"projects": [
"/Users/svlad/dev/ng2-diary-book"
],
"rootDir": "/Users/svlad/dev/ng2-diary-book",
"testPathPattern": "",
"testResultsProcessor": null,
"updateSnapshot": "new",
"useStderr": false,
"verbose": null,
"watch": false,
"watchman": true
},
"version": "20.0.4"
}
PASS src/app/diary/components/diary.spec.ts
FAIL src/app/diary/containers/my-dairy-page.spec.ts
● Test suite failed to run
/Users/svlad/dev/ng2-diary-book/node_modules/angularfire2/auth.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export * from './auth/auth';
^^^^^^
SyntaxError: Unexpected token export
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
at Object.<anonymous> (src/app/core/containers/app.ts:18:14)
at Object.<anonymous> (src/app/core/core.module.ts:15:13)
Test Suites: 1 failed, 1 passed, 2 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 2.709s
Ran all test suites.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] jest: `jest "--debug"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] jest script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/svlad/.npm/_logs/2017-08-20T21_09_30_035Z-debug.log
sharikovvlad:ng2-diary-book svlad$
이 코드는 ES5로 트랜스 파일되어야하므로 구문 오류가 발생하지 않아야합니다 (config에서 그렇게 말 했으므로). 나는 그것을 왜 얻습니까?
또한 이상한 것은 내가 아무것도 무시하지 않는다는transformIgnorePatterns
것을 의미하는 빈 배열로 설정하더라도 동일한 오류가 발생 한다는 것 입니다.
각도 : 4.3.5
Firebase : 4.2.0
AngularFire : 4.0.0-rc0
기타 (예 : Ionic / Cordova, Node, 브라우저, 운영 체제) :
sharikovvlad:~ svlad$ node -v
v8.3.0
sharikovvlad:~ svlad$ yarn --version
0.27.5
sharikovvlad:~ svlad$ macosVersion
10.12.6
설정 및 재현 단계
<rootDir>/src/setupJest.ts
내용이있는 파일 추가 :import 'jest-preset-angular';
"jest": { "preset": "jest-preset-angular", "setupTestFrameworkScriptFile": "<rootDir>/src/setupJest.ts", "transformIgnorePatterns": [ "<rootDir>/node_modules/(?!@ngrx|angularfire2)" ] },
그러나 실제로 다음과 같이 할 수 있습니다.
핵심 문제는 ts-jest (jest-preset-angular는 ts-jest를 기반으로 함)가 JS 파일을 트랜스 파일하지 않는다는 것입니다.
그래서 나는 그 일을 할 무언가가 필요합니다. Jest는 babel-jest
즉시 트랜스 파일러를 제공합니다 . 그래서 jest를 구성하여 js와 ts 파일을 모두 트랜스 파일 할 것입니다.
다음은 마지막 jest 구성 (package.json)입니다.
"jest": {
"preset": "jest-preset-angular",
"setupTestFrameworkScriptFile": "<rootDir>/src/setupJest.ts",
"transform": {
"^.+\\.(ts|html)$": "<rootDir>/node_modules/jest-preset-angular/preprocessor.js",
"^.+\\.js$": "babel-jest"
},
"transformIgnorePatterns": [
"node_modules/(?!(@ngrx|angularfire2))"
],
"globals": {
"ts-jest": {
"tsConfigFile": "src/tsconfig.spec.json",
"useBabelrc": true
},
"__TRANSFORM_HTML__": true
}
},
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다