Karma + Jasmine 测试设置打破了离子包装
Karma + Jasmine Testing setup breaks the ionic packaging
我有一个 ionic 应用程序,我介绍了使用 karma + jasmine 进行测试。我还使用打字稿预处理器进行测试。
我有以下依赖项,其中除前两个外的所有依赖项都必须添加以进行测试:
"devDependencies": {
"@ionic/app-scripts": "1.0.0",
"typescript": "2.0.9"
"@types/core-js": "^0.9.35",
"@types/jasmine": "^2.5.41",
"angular-cli": "^1.0.0-beta.26",
"jasmine-core": "^2.5.2",
"karma": "^1.4.0",
"karma-jasmine": "^1.1.0",
"karma-safari-launcher": "^1.0.0",
"karma-typescript": "^2.1.6",
"reflect-metadata": "^0.1.9",
},
tsconfig.json
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"dom",
"es2015"
],
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"target": "es5"
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules"
],
"compileOnSave": false,
"atom": {
"rewriteTsconfig": false
}
}
这是我的 karma.conf.js
文件:
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ["jasmine", "karma-typescript"],
files: [
{pattern: "src/**/*.spec.ts"},
{pattern: "test/**/*.spec.ts"},
{pattern: 'node_modules/reflect-metadata/Reflect.js', included: true, watched: true}
],
preprocessors: {
"**/*.ts": ["karma-typescript"], // *.tsx for React Jsx
},
reporters: ["progress", "karma-typescript"],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
browsers: ['Safari'],
singleRun: true,
concurrency: Infinity
})
}
问题
现在使用命令测试工作正常:
./node_modules/karma/bin/karma start karma.conf.js
但是当我现在 运行 ionic serve
时,我收到了非常神秘的错误消息,如下所示:
Subsequent variable declarations must have the same type. Variable '[Symbol.unscopables]' must be of type '{ copyWithin: boolean; entries: boolean; fill: boolean; find: boolean; findIndex: boolean; keys: ...', but here has type 'any'.
Typescript Error
All declarations of 'name' must have identical modifiers.
Typescript Error
Duplicate identifier 'PropertyKey'.
我的看法是 devDependencies 弄乱了应用程序其余部分的 "load path"。所以我想知道如何让我的应用程序再次运行。
问题是您正在使用 es2015
定义和 core-js
定义。
Core-JS 提供 polyfill,因此与 TypeScript ES6+ 标准定义冲突。
删除 @types/core-js
并将 karmaTypescriptConfig: { compilerOptions: { lib: ['dom', 'es2015'] } }
添加到您的 karma.conf.js
以使 Karma-Typescript 使用 es2015
定义。
我有一个 ionic 应用程序,我介绍了使用 karma + jasmine 进行测试。我还使用打字稿预处理器进行测试。
我有以下依赖项,其中除前两个外的所有依赖项都必须添加以进行测试:
"devDependencies": {
"@ionic/app-scripts": "1.0.0",
"typescript": "2.0.9"
"@types/core-js": "^0.9.35",
"@types/jasmine": "^2.5.41",
"angular-cli": "^1.0.0-beta.26",
"jasmine-core": "^2.5.2",
"karma": "^1.4.0",
"karma-jasmine": "^1.1.0",
"karma-safari-launcher": "^1.0.0",
"karma-typescript": "^2.1.6",
"reflect-metadata": "^0.1.9",
},
tsconfig.json
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"dom",
"es2015"
],
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"target": "es5"
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules"
],
"compileOnSave": false,
"atom": {
"rewriteTsconfig": false
}
}
这是我的 karma.conf.js
文件:
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ["jasmine", "karma-typescript"],
files: [
{pattern: "src/**/*.spec.ts"},
{pattern: "test/**/*.spec.ts"},
{pattern: 'node_modules/reflect-metadata/Reflect.js', included: true, watched: true}
],
preprocessors: {
"**/*.ts": ["karma-typescript"], // *.tsx for React Jsx
},
reporters: ["progress", "karma-typescript"],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
browsers: ['Safari'],
singleRun: true,
concurrency: Infinity
})
}
问题
现在使用命令测试工作正常:
./node_modules/karma/bin/karma start karma.conf.js
但是当我现在 运行 ionic serve
时,我收到了非常神秘的错误消息,如下所示:
Subsequent variable declarations must have the same type. Variable '[Symbol.unscopables]' must be of type '{ copyWithin: boolean; entries: boolean; fill: boolean; find: boolean; findIndex: boolean; keys: ...', but here has type 'any'.
Typescript Error All declarations of 'name' must have identical modifiers.
Typescript Error Duplicate identifier 'PropertyKey'.
我的看法是 devDependencies 弄乱了应用程序其余部分的 "load path"。所以我想知道如何让我的应用程序再次运行。
问题是您正在使用 es2015
定义和 core-js
定义。
Core-JS 提供 polyfill,因此与 TypeScript ES6+ 标准定义冲突。
删除 @types/core-js
并将 karmaTypescriptConfig: { compilerOptions: { lib: ['dom', 'es2015'] } }
添加到您的 karma.conf.js
以使 Karma-Typescript 使用 es2015
定义。