karma-jspm
karma-jspm copied to clipboard
Uncaught SyntaxError: Unexpected token import
I have the following error : Uncaught SyntaxError: Unexpected token import at path/test/BootStrapFormView.Test.js:3
Here my Karma configuration file and my package.json
karma.conf.js
// Karma configuration
// Generated on Wed Mar 02 2016 17:09:45 GMT+0100 (CET)
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'],
plugins: ['karma-jspm', 'karma-chrome-launcher', 'karma-jasmine'],
jspm: {
// Edit this to your needs
loadFiles: ['src/**/*.js', 'test/*.js']
},
// list of files / patterns to load in the browser
files: [
'test/*'
],
// 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: {
},
// 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_DEBUG,
// 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,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
})
}
package.json
{
"name": "whatever",
"version": "1.0.0",
"description": "Nice Description",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Me",
"license": "UNLICENSED",
"devDependencies": {
"babel-eslint": "^5.0.0",
"eslint": "^2.2.0",
"gulp": "^3.9.1",
"gulp-html-replace": "^1.5.5",
"jspm": "^0.16.30",
"karma": "^0.13.21",
"karma-chrome-launcher": "^0.2.2",
"karma-jasmine": "^0.3.7",
"karma-jspm": "^2.0.2"
},
"jspm": {
"dependencies": {
"backbone": "github:typhonjs-backbone-parse/backbone-parse-es6@master",
"blueimp-file-upload": "npm:blueimp-file-upload@^9.12.1",
"components/jqueryui": "github:components/jqueryui@^1.11.4",
"jquery": "npm:jquery@^2.2.1",
"parse": "npm:parse@^1.7.1",
"text": "github:systemjs/plugin-text@^0.0.7",
"typhonjs-core-parse-init": "github:typhonjs-backbone-parse/typhonjs-core-parse-init@master",
"underscore": "npm:underscore@^1.8.3"
},
"devDependencies": {
"babel": "npm:babel-core@^5.8.24",
"babel-runtime": "npm:babel-runtime@^5.8.24",
"core-js": "npm:core-js@^1.1.4"
}
}
}
You also need karma-babel-preprocessor
to work with ES6 via Karma.
https://github.com/babel/karma-babel-preprocessor
I forgot to put my test file
"use strict";
import BootstrapFormView from "../src/js/views/BootstrapFormView.js";
describe("BootstrapFormView", function() {
var bootstrapFormView = new BootstrapFormView();
it("can convert error strings to errors", function() {
var errorString = "|This is an error message";
expect(bootstrapFormView.errorStringToErrors(errorString)).toBe("This is an error message");
});
});
I installed karma-babel-preprocessor
and added it to the plugging list and I still have the same issue.
I'm running into this issue too. Was there any resolution?
I also have the same issue. Is there no solution out there?
Sorry guys I can't help much cause I'm using Webpack now.
I'm also having this issue. Anyone resolve this?
@AlexisBarta I have also this error under Webpack with Karma :/, do you have to ? or did you have find a trick to fix it ? Thank you
@AlexisBarta using webpack
and babel
you should be able to transpile the ES6.
preprocessors: { 'tests/jasmine/**/*.js': ['webpack','babel'] }