karma-jspm
karma-jspm copied to clipboard
Provide a demo project
Please provide a minimal demo project which shows how to use this. Thanks! :)
No demo project but I successfully applied it to one of my projects: https://github.com/Reading-eScience-Centre/leaflet-coverage
Key takeaways for me:
- When you test server-side only with Mocha (or something else) (and not use karma, which I'm not sure is combinable), then you import npm-modules and dynamically load jspm-modules. With karma-jspm, you're fully in jspm world, which means that you have to install your assert-libraries etc. as jspm dev dependency to be able to import them in tests.
- Everything is easier when the folder structure is as in many Python packages, at least this makes much sense for libraries. This means, have a "my-package-name" subfolder instead of "src" or putting stuff in the root. This way you can write code like it would be used from someone who installed your package (hopefully under the same alias). By doing that, you can use all the defaults as well and not worry, like
basePath: ''
. - In the package.json, put
"lib": "my-package-name"
underjspm.directories
. - In the generated karma config I had to change the following: 1. frameworks to include "jspm", 2. make "files" an empty array, and 3. use load and serve files:
jspm: {loadFiles: ['test/**/*.js'],serveFiles: 'my-package-name/**/*.js'] }
.
It works quite well. The only major downside is that the error stacktraces don't return original line numbers but the transpiled ones. I don't know how, but this should be fixed in some way. At least the transpiled files should not be deleted (or actually stored on disk if they are in-memory only) so that you can manually look into the transpiled code which actually is more or less readable! (related: #52)
here is another project https://github.com/martinmicunda/employee-scheduling-ui/blob/master/karma.conf.js
I've got a pull request open for this: https://github.com/Workiva/karma-jspm/pull/98
Here is a project boilerplate : https://github.com/topheman/vanilla-es6-jspm
Regarding karma-jspm
, you'll have the following features:
- overriding your jspm configuration (to use stubs and mocks while testing)
- using html fixtures
- Travis CI ready