I'm currently in the process of setting up unit tests for my application. The basic test specification, project.spec.ts
, is structured as follows:
import {Project} from './project';
describe('Project', () => {
let p = new Project('New project');
it('should have the name provided in the constructor', () => {
expect(p.name).toBe('New project');
});
});
The class being tested is called Project
, and it is located in the file app/entities/project.ts
within the same directory.
However, I encounter a 404 error when Karma attempts to import another file in the test spec:
01 03 2016 17:21:04.955:WARN [web-server]: 404: /base/app/entities/project
Chrome 48.0.2564 (Windows 10 0.0.0) ERROR
Error: XHR error (404 Not Found) loading C:/Dev/mps/app/entities/project
Error loading C:/Dev/mps/app/entities/project as "./project" from C:/Dev/mps/app/entities/project.spec.js
It seems that while the compiled file project.spec.js
loads successfully, the file project.js fails to load. Additionally, I am puzzled by the appearance of the prefix /base/
in /base/app/entities/project
.
A similar issue is documented here. Nonetheless, the suggested solution does not remedy the situation for me. Various import variations like the following do not yield successful results:
let Project = require('./project');
let Project = System.import('./project'); // leads to "404: /project" instead
let Project = require('./project.js');
let Project = System.import('./project.js');
My configuration details are outlined below:
karma.conf.js
module.exports = function(config) {
config.set({
basePath: '',
plugins: ['karma-systemjs', 'karma-jasmine', 'karma-chrome-launcher'],
frameworks: ['systemjs', 'jasmine'],
systemjs: {
configFile: 'system.conf.js'
},
files: [
'app/entities/project.spec.js'
],
exclude: [ ],
preprocessors: { },
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
concurrency: Infinity
})
}
system.conf.js
System.config({
paths: {
'traceur': 'node_modules/traceur/bin/traceur.js',
'systemjs': 'node_modules/systemjs/dist/system.js',
'system-polyfills': 'node_modules/systemjs/dist/system-polyfills.js',
'es6-module-loader': 'node_modules/es6-module-loader/dist/es6-module-loader.js'
}
});
Could someone pinpoint the mistake I might be making?