別のnode_modulesを使っていくつかの例があると、phantomjsでkarmaテストを実行しようとすると問題が発生します。例えばkarma.jsのフォルダをphantomjsとangular2で除外する
:
MyComponent
└── node_modules
└── examples
└── node_modules
└── src
└── app
└── app.component.ts
└── app.component.html
└── app.component.css
└── app.component.spec
└── app.module.ts
└── assets
└── index.html
└── angular-cli.json
└── karma.conf.js
└── package.json
└── src
└── app
└── my.component.ts
└── my.component.html
└── my.component.css
└── my.component.spec.ts
└── assets
└── base.spec.ts
└── karma.conf.js
└── package.json
package.json
"dependencies": {
"@angular/common": "2.4.9",
"@angular/compiler": "2.4.9",
"@angular/core": "2.4.9",
"@angular/http": "2.4.9",
"@angular/platform-browser": "2.4.9",
"@angular/platform-browser-dynamic": "2.4.9",
"@angular/router": "3.4.9",
"@types/core-js": "0.9.36",
"@types/echarts": "0.0.5",
"angular-in-memory-web-api": "0.3.1",
"core-js": "2.4.1",
"echarts": "3.4.0",
"rxjs": "5.0.1",
"systemjs": "0.19.40",
"zone.js": "0.7.4"
},
"devDependencies": {
"@types/jasmine": "2.5.44",
"@types/node": "6.0.65",
"typescript": "2.2.1",
"jasmine-core": "2.5.2",
"karma": "1.5.0",
"karma-chrome-launcher": "2.0.0",
"karma-jasmine": "1.1.0",
"karma-typescript": "3.0.0-beta.1",
"karma-typescript-angular2-transform": "1.0.0-beta.5",
"karma-phantomjs-launcher": "1.0.4"
}
karma.conf.js
module.exports = function(config) {
config.set({
frameworks: ["jasmine", "karma-typescript"],
files: [
{ pattern: "base.spec.ts" },
{ pattern: "src/app/**/*.+(ts|html)" }
],
exclude: [
'examples/**/*.js',
'examples/**/*.ts'
],
preprocessors: {
"**/*.ts": ["karma-typescript"]
},
karmaTypescriptConfig: {
bundlerOptions: {
entrypoints: /\.spec\.ts$/,
transforms: [
require("karma-typescript-angular2-transform")
]
},
coverageOptions: {
instrumentation: true
}
},
reporters: ["progress", "karma-typescript"],
browsers: ["Chrome"]
});
};
私はexamplesフォルダなしでテストを実行し、すべてがうまくいきますが、もし私がo内部のサンプルを使ってテストを実行し、それが動作しない場合は無視します。
私は次のエラーを取得:
14 03 2017 11:15:07.881:ERROR [karma]: TypeError: Cannot read property 'name' of undefined at mergeSymbol (/workspace/node_modules/typescript/lib/typescript.js:25122:46) at /workspace/node_modules/typescript/lib/typescript.js:25146:21 at Map.forEach (native)