Trying to setup karma to unit test my ES6 transpiled code. The full tool chain is: Typescript -> ES6 -> Babel -> browserify.
Outside of Karma I have this chain working fine (using Gulp).
With my Karma setup I'm getting errors on the Typescript step:
error TS2318: Cannot find global type 'IterableIterator'. 12 03 2016 16:52:09.323:ERROR [preprocessor.typescript]: error TS2318: Cannot find global type 'Iterator'.
error TS2318: Cannot find global type 'Iterator'. 12 03 2016 16:52:09.323:ERROR [preprocessor.typescript]: error TS2318: Cannot find global type 'Symbol'.`
Here's my karma.conf
module.exports = function(config) {
config.set({
// base path, that will be used to resolve files and exclude
basePath: '',
// frameworks to use
frameworks: ['browserify','jasmine'],
preprocessors: {
'src/**/test.ts' : ['typescript', 'babel', 'browserify'],
'tests/**/tests.spec.js' : ['babel', 'browserify']
},
typescriptPreprocessor: {
options: {
target: 'es6'
}
},
babelPreprocessor: {
options: {
presets: ['es2015'],
sourceMap: 'inline'
}
},
browserify: {
debug:true
},
files: [
'src/**/test.ts',
'tests/**/*.js'
],
// list of files to exclude
exclude: [
],
// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters: ['progress'],
// web server port
port: 9876,
plugins: [
'karma-typescript-preprocessor',
'karma-babel-Preprocessor',
'karma-browserify',
'karma-jasmine',
'karma-firefox-launcher',
'karma-chrome-launcher'
],
// enable / disable colors in the output (reporters and logs)
colors: false,
// 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,
browsers: ['Chrome'],
// If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000,
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false
});
};
And here's my test.ts file:
"use strict"
function thisIsAtest(myParam:string) {
const pi = 3.14;
}
New to Typescript and my google powers are failing me ):
Update: So the above configuration makes use of the babel and typescript karma preprocessors. I am still unable to get that toolchain to work. But I was able accomplish my end goal by having karma-browserify handle the transformations directly. So my browserify section now looks like this:
browserify: {
debug: true,
plugin: ['tsify'],
transform: [['babelify', {presets:["es2015"], extensions:[".ts",".js"] }]]
},
Notice the double brackets within the transform section -- forgetting those tripped me up when I initially started down this path.