Abbiamo installato karma, che utilizza moka e chai per i test. Stiamo cercando di integrare Babele direttamente nel karma usando il preprocessore karma-babel, per eseguire la conversione dei nostri file ES6 in ES5. Usando moka individualmente funziona con babel, cioè un comando di test moka, ma proviamo a usare il karma invece non funziona.Babel [preprocessore karma-babel] Non conversione ES6-> ES5 per test karma
karma.conf.js snippet:
frameworks: ['mocha', 'chai'],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'src/**/*.js': ['babel'],
'test/**/*_spec.js': ['babel']
},
"babelPreprocessor": {
options: {
presets: ['es2015'],
sourceMap: 'inline'
},
filename: function(file) {
return file.originalPath.replace(/\.js$/, '.es5.js');
},
sourceFileName: function(file) {
return file.originalPath;
}
},
// list of files/patterns to load in the browser
files: [
'src/**/*.js',
'test/**/*_spec.js'
],
frammenti package.json:
"scripts": {
"test": "./node_modules/karma/bin/karma start karma.conf.js"
},
"babel": {
"presets": ["es2015"]
},
"devDependencies": {
"babel-preset-es2015": "^6.1.18",
"chai": "^3.4.1",
"karma": "^0.13.15",
"karma-babel-preprocessor": "^6.0.1",
"karma-chai": "^0.1.0",
"karma-mocha": "^0.2.1",
"karma-phantomjs-launcher": "^0.2.1",
"phantomjs": "^1.9.18",
"redux": "^3.0.4"
}
Otteniamo il seguente errore:
PhantomJS 1.9.8 (Mac OS X 0.0.0) ERROR
ReferenceError: Can't find variable: exports
at Users/alexgurr/BT/FutureVoice/trunk/Portal/server/src/login.es5.js:3
Quando valutiamo i file JS essere caricato, non sono stati convertiti in ES5, quindi la sintassi 'export' è ancora presente.
Non vogliamo utilizzare altri framework per la conversione, ad es. webpack, browserify, ecc.
Grazie!
Ovviamente, i file _was_ transpiled. Probabilmente Babel è stato installato a livello globale ('npm install -g babel') per evitare che i' node_modules' locali crescessero in modo incontrollabile – ankhzet