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.
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:
some/some.js
file, which seems to exist only in karma memory.Also numerous variations of all above and many more, none of which worked.
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):
Uncaught Error: Can't find entrypoint
for some-test.ts
(mocha works fine with no babel transform).TypeError: global is undefined
.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!
I had in mind testing this with using Babel 7 compiler which itself has support for compiling TypeScript, insted of older Babel 6.
Since I was a bit curious if it works this way I forked your repo and made pull request. I also cleaned some of the setting files. You could read through the changes in pull request to get some idea what was done.
Test seems to pass now as expected, cheers! heres pull request
@babel/core:^7.0.0
-compilerbabel-core": "^7.0.0-bridge.0
-resolution for avoiding issue when - - modules reference older version of babel.tsconfig
optionskarma.conf
EDIT:
I actually do believe you can just drop Babel loader out of the build line and just give karma-typescript
-loader parameter to target es5.
es5 is supported by major browsers for a while now and should work in FF 44 also. Classes have also been introduced in es6 and this is why you had problem with classes before, compiling to es5 transforms classes to functions.
karmaTypescriptConfig: {
compilerOptions: {
sourceMap: true,
target: 'es5' // <-- this here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With