Closed pearljamik closed 7 years ago
Hey @pearljamik, the exclude
property only affects which files the Typescript compiler picks up, it doesn't affect which files Karma picks up for the test run. What does the file
section in your Karma conf look like, which patterns have you specified? It seems Karma has picked a lot of files that the compiler hasn't picked up, that's why you get these error messages. This should probably be clarified in the documentation...
Files section:
> files: [
{ pattern: "node_modules/reflect-metadata/Reflect.js" },
{ pattern: "node_modules/zone.js/dist/zone.js" },
{ pattern: "node_modules/zone.js/dist/long-stack-trace-zone.js" },
{ pattern: "node_modules/zone.js/dist/proxy.js" },
{ pattern: "node_modules/zone.js/dist/sync-test.js" },
{ pattern: "node_modules/zone.js/dist/jasmine-patch.js" },
{ pattern: "node_modules/zone.js/dist/async-test.js" },
{ pattern: "node_modules/zone.js/dist/fake-async-test.js" },
{ pattern: "src/app/**/*.ts" }
],
@pearljamik, it looks like you've found a nasty little bug, so I've added more debug logging because I need more input to fix it...
npm install https://github.com/monounity/karma-typescript
logLevel: config.LOG_DEBUG,
23 11 2016 17:18:59.188:ERROR [compiler.karma-typescript]: No source found for C:/Users/gwk736/Gitlab/Inform/node_modules/rxjs/add/observable/if.d.ts 23 11 2016 17:18:59.248:ERROR [compiler.karma-typescript]: No source found for C:/Users/gwk736/Gitlab/Inform/node_modules/rxjs/add/observable/throw.d.ts 23 11 2016 17:18:59.952:ERROR [compiler.karma-typescript]: No source found for C:/Users/gwk736/Gitlab/Inform/node_modules/common-map/node_modules/rxjs/add/observable/throw.d.ts
Does everything work if you install the latest from main again?
It is happening to me too
Any news? I do have the same problem.
My repo has the following structure:
| backend/
|--karma.conf.js
|--src/
|----app.spec.ts
| frontend/
| package.json
Here's my backend/karma.conf.json
:
module.exports = function(config) {
config.set({
basePath: '..',
frameworks: ['jasmine', 'karma-typescript'],
files: ['./backend/src/**/*spec.ts'],
preprocessors: {
'./backend/src/**/*spec.ts': 'karma-typescript',
},
reporters: ['progress', 'karma-typescript'],
browsers: ['Chromium'],
karmaTypescriptConfig: {
compilerOptions: {
include: ['./backend/src/**/*spec.ts'],
exclude: ['../node_modules'],
},
},
karmaTypescriptConfig: { exclude: ['../node_modules'] },
});
};
Within package.json
I have the following script:
"back:test": "karma start backend/karma.conf.js --auto-watch",
My test is a dumb one just to make sure it's working:
describe('Test', () => {
it('should be true', () => {
expect(true).toBe(true);
});
});
The test run and succeed :tada: BUT...
I still have some Typescript errors:
1) Why do I have errors from node_modules? 2) Why do I have errors from the frontend?
I'm not including them, only backend/
...
Thanks for the good work btw :)
@maxime1992, you need to include all .ts files you want to compile and test in the files
and preprocessors
section of the Karma config: ./backend/src/**/*.ts
.
Also, you need to fix this in your tsconfig:
error TS2705: An async function or method in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your --lib option
@erikbarke thanks :)
So I did try to include all the TS files (files + tests) and target to ES6 but still no luck, I think it's even worse as now:
Stacktrace from node_modules:
Stacktrace after node_modules:
In case it helps, I've pushed my current work as WIP so you can give a try on your own if you want.
The commit can be seen here: https://github.com/maxime1992/nest-angular-starter/commit/1c4f82b444a724dc716bdecbb1ae48d6ac9b00bc
If you want to try it locally:
git clone https://github.com/maxime1992/nest-angular-starter.git
git checkout feat/init-repo
yarn
yarn run back:test
(or same with npm if you prefer :+1:)
This is how far I got:
module.exports = function(config) {
config.set({
basePath: '.',
frameworks: ['jasmine', 'karma-typescript'],
files: ['./src/**/*.ts'],
preprocessors: {
'./src/**/*.ts': 'karma-typescript',
},
reporters: ['progress', 'karma-typescript'],
browsers: ['Chrome'],
karmaTypescriptConfig: {
bundlerOptions: {
resolve: {
alias: {
'util': 'node_modules/util/util.js'
}
}
},
compilerOptions: {
lib: ['ES2015', 'DOM'],
types : ['jasmine']
}
}
});
};
This compiles without errors, but when running the tests the package express
crashes when trying to do Object.create(http.IncomingMessage.prototype)
because the prototype is undefined on http.IncomingMessage
.
Since the tests are running in a browser (not in Node.js) the karma-typescript
bundler loads a browser shim for the module http
called stream-http
and it seems that shim isn't fully compatible with it's Node.js counterpart yet 🤔
This breaks in browserify
bundles too, this isn't a karma-typescript
bug 😞
Thanks a lot for your investigation :pray:
So I'm kinda stuck here, I guess I'll have to open few issues around :sweat_smile: If you found anything at some point just let me know
Anyway thanks a lot for your help on that already, cheers
Since the tests are running in a browser (not in Node.js) the karma-typescript bundler loads a browser shim for the module http called stream-http and it seems that shim isn't fully compatible with it's Node.js counterpart yet thinking
I figured out yesterday that I'm absolutely not supposed to use karma for E2E testing... :sweat_smile: how embarrassing uhm uhm... :yum:
Anyway you helped me a lot to figure things out @erikbarke, thanks
Config is like:
When running: