At the moment, I'm trying to setup a demo project with Node/AngularJs/JSPM with ES6 transpiler Babel and Karma.
The serving part is working. I need to improve it later but the first 'hello world' from angular is working.
I'd like to add Karma to run unit tests for the angular app. But I'm getting a 404 warning for jspm_packages
, see screenshot below.
My test is not running because it will always fail. My test file looks like this (no angular specific part in there yet):
// HomeController.spec.js
import 'angular-mocks';
describe('Test suite for HomeController', function() {
it('dummy test', function() {
expect(true).toBe(true); // will not fail
});
});
Not sure what's wrong and I've tried many things with-out success maybe I did something wrong. But here is what I've tried in the Karma config:
- Tried many different path setting because I think it's an issue with the path
- Used proxies
- Browserify and Bablify to transpile the sources
- JSPM plugin to load the dependencies for testing
You can find the code I'm currently working on here at bitbucket.
The directory structure of my app looks like this:
Here is a screenshot of Karma:
Here is my current Karma config file:
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '.',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jspm', 'jasmine'],
// list of files / patterns to load in the browser
files: [
//'client/test-unit/**/*.test.js'
],
jspm: {
paths: {
// '*': 'client/app/**/*.js'
},
// Edit this to your needs
// config: 'client/app/jspm.config.js',
// Edit this to your needs
loadFiles: ['client/test-unit/**/*.spec.js'],
serveFiles: ['client/app/**/*.js', 'client/app/**/*.css', 'client/app/**/*.html']
},
proxies: {
// '/assets/jspm_packages/': '/client/app/assets/jspm_packages/'
},
plugins:[
'karma-jasmine',
'karma-coverage',
'karma-jspm',
'karma-chrome-launcher'
],
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
// 'client/app/**/*.js': ['browserify'],
// 'client/test-unit/**/*.js': ['browserify']
},
/*browserify: {
debug: true,
transform: [ 'babelify' ]
},*/
// babelPreprocessor: {
// options: {
// sourceMap: 'inline'
// },
// filename: function (file) {
// return file.originalPath.replace(/\.js$/, '.es5.js');
// },
// sourceFileName: function (file) {
// return file.originalPath;
// }
// },
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
});
};