I've recently added testing to my ionic app using karma + jasmine, along with a typescript pre-processor. Below are the dependencies I have, most of which were added specifically for testing:
"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
}
}
This is my karma.conf.js
file:
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
})
}
The Issue at Hand
While running tests using the command:
./node_modules/karma/bin/karma start karma.conf.js
Everything works fine. But when I try to run ionic serve
, I encounter confusing error messages like:
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'.
It seems that the devDependencies are causing issues with the application's load path. I'm now looking for a solution to get my app back up and running smoothly again.