Setup and goal
Typescript project, with typescript mocha tests. Project should be transpiled from Typescript to ES6 and then transformed via Babel for several shippable bundles.
I'd like to run all tests in browser via Karma (and eventually BrowserStack) against same transformed version as will be produced by babel.
Attempts and issues
I have karma-typescript + mocha working, but only in es2017 compatible browsers. The problem is to plug babel in between.
I think I've tried everything I could imagine, but namely:
- karma-typescript-es6-transform: transforms only bundled ES6 modules, not user's code.
- karma-browserify together with babelify transform: browserify seems to be incompatible with karma typescript or at least its transform system. It fails when babel can't find
some/some.js
file, which seems to exist only in karma memory. - karma-babel-preprocessor seems to be right way to do it.
Also numerous variations of all above and many more, none of which worked.
Promising setup with karma-babel-preprocessor
I think this should be a correct way to do it, so I've posted a project with my current state of things: https://github.com/anpur/karma-typescript-babelify.
Here is part of my karma.conf.js
:
frameworks: ['mocha', 'karma-typescript'],
preprocessors: {
'src/*.ts': ['karma-typescript', 'babel'],
},
babelPreprocessor: {
options: {
presets: [
[ 'es2015' ]
]
}
},
karmaTypescriptConfig: {
compilerOptions: {
sourceMap: true,
target: 'es6'
},
bundlerOptions: {
addNodeGlobals: true,
sourceMap: true
},
tsconfig: './tsconfig.json'
},
Karma is able to transpile -> transform -> bundle this in this setup, but I have whole set of different strange issues (no browser works in this state):
- In es2017 browsers (Chrome):
Uncaught Error: Can't find entrypoint
forsome-test.ts
(mocha works fine with no babel transform). - In old Firefox 44
TypeError: global is undefined
. - In IE 10
Unable to get property 'wrappers' of undefined or null reference
.
P.S. - None of aforementioned modules/frameworks is important to me, so I'll be happy with any other working setup, which can do typescript -> babel -> browserstack testing. Thanks!