Skip to content

Instantly share code, notes, and snippets.

@dgp1130
Last active August 7, 2016 07:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgp1130/297f13a6176488bb1e09ac5f180895cc to your computer and use it in GitHub Desktop.
Save dgp1130/297f13a6176488bb1e09ac5f180895cc to your computer and use it in GitHub Desktop.
Karma Babel Preprocessor cannot parse ES6 lambda syntax () -> {};
window.temp = "world";
let test = "hello";
window.test = test;
var { one, two } = { one: 1, two: 2 };
window.one = one;
window.two = two;
window.foo = function (bar = "bar") {
return bar;
};
//window.bar = () -> "foo"; // breaks
// Karma configuration
// Generated on Sat Aug 06 2016 23:33:56 GMT-0700 (Pacific Daylight Time)
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
plugins: [ "karma-jasmine", "karma-phantomjs-launcher", "karma-babel-preprocessor" ],
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'file.js',
'test.js'
],
// 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: {
'*.js': ['babel']
},
babelPreprocessor: {
options: {
presets: ['es2015'],
sourceMap: 'inline'
}
},
// 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: false,
// 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: true,
// Concurrency level
// how many browser should be started simultaneously
concurrency: Infinity
});
};
{
"name": "karma-es6",
"version": "1.0.0",
"scripts": {
"test": "node ./node_modules/karma/bin/karma start"
},
"devDependencies": {
"babel": "^6.5.2",
"babel-preset-es2015": "^6.13.2",
"jasmine-core": "^2.4.1",
"karma": "^1.1.2",
"karma-babel-preprocessor": "^6.0.1",
"karma-jasmine": "^1.0.2",
"karma-phantomjs-launcher": "^1.0.1"
}
}
describe("Jasmine", function () {
it("runs es5 source code", function () {
expect(window.temp).toBe("world");
});
it("runs es6-compiled source code with let", function () {
expect(window.test).toBe("hello");
});
it("runs es6-compiled source code with expansion", function () {
expect(window.one).toBe(1);
expect(window.two).toBe(2);
});
it("runs es6-compiled source code with default parameters", function () {
expect(window.foo()).toBe("bar");
});
it("runs es6-compiled source code with lambda notation", function () {
expect(window.bar()).toBe("foo");
});
it("runs es6-compiled tests with let", function () {
let value = window.test;
expect(value).toBe("hello");
});
it("runs es6-compiled tests with expansion", function () {
var { one, two } = { one: 1, two: 2 };
expect(one).toBe(1);
expect(two).toBe(2);
});
it("runs es6-compiled tests with default parameters", function () {
var foo = function (bar = "bar") { return bar; };
expect(foo()).toBe("bar");
});
it("runs es6-compiled tests with lambda notation", function () {
//var bar = () -> "foo"; // breaks
expect(bar()).toBe("foo");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment