I have been facing some issues while setting up my angular tests. The error message I keep getting is:
PhantomJS 2.1.1 (Windows 8 0.0.0) ERROR
SyntaxError: Unexpected token '/'
at app/components/dropdown/dropdown.spec.ts:1
PhantomJS 2.1.1 (Windows 8 0.0.0) ERROR
SyntaxError: Unexpected token '/'
at app/components/dropdown/dropdown.spec.ts:1
I have checked my files multiple times but can't seem to find what might be causing this issue. Below are the files I am using:
karma.conf.js
var WebpackConfig = require('./webpack.config.js');
// Karma configuration
// Generated on Wed Dec 30 2015 11:13:38 GMT-0500 (EST)
module.exports = function (config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '.',
files: [
'app/**/*.spec.ts'
],
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha', 'chai'],
// list of files to exclude
exclude: [
'node_modules'
],
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress', 'dots'],
// 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: ['PhantomJS'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity,
preprocessors: {
'app/**/*.spec.ts': ['webpack']
},
webpack: WebpackConfig,
webpackMiddleware: {
noInfo: true
},
plugins: [
require('karma-mocha'),
require('karma-chai'),
require('karma-phantomjs-launcher'),
require('karma-webpack')
]
});
};
webpack.config.js
var Loaders = require('./webpack/loaders');
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: {
'bundle': 'app/core/bootstrap.ts'
},
output: {
path: 'public',
library: '[name]',
filename: '[name].js'
},
resolve: {
root: __dirname,
extensions: ['', '.ts', '.js', '.json']
},
resolveLoader: {
modulesDirectories: ['node_modules']
},
devtool: 'source-map',
plugins: [
new HtmlWebpackPlugin({
template: 'app/index.html',
inject: 'body',
hash: true
})
],
module: {
loaders: Loaders
}
};
Currently, I only have one test named: dropdown.spec.ts
import '../../core/tests.ts';
import {chai} from '../../core/tests.ts';
var expect = chai.expect;
describe('Unit tests for DropDown component', () => {
describe('2 + 4', () => {
it('should be 6', (done) => {
expect(2 + 4).to.equal(6);
done();
});
it('should not be 7', (done) => {
expect(2 + 4).to.not.equals(7);
done();
});
it('should be 10', (done) => {
expect(6 + 4).to.equal(10);
done();
});
});
});
tests.ts
require('../../node_modules/mocha/mocha.js');
export var chai = require('../../node_modules/chai/chai.js');
package.json
{
"name": "proj",
"version": "0.0.1-beta2",
"author": "",
"license": "ISC",
"devDependencies": {
"angular-mocks": "^1.5.3",
// All the other dependencies ...
},
"dependencies": {
"angular": "^1.5.8",
"angular-ui-router": "^0.3.1",
"socket.io-client": "^1.5.0"
},
"optionalDependencies": {
"fsevents": "1.0.14"
}
}