我正在尝试对业力,摩卡咖啡和柴进行一些测试。我很困惑如何在业力中正确导入es6模块。我已经在使用karma-babel-preprocessor
。谁能帮助我,非常感谢!
这是我的karma.conf.js
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['mocha', 'chai'],
files: ['src/index.js', 'test/test_karma.js'],
exclude: [],
preprocessors: {
'src/index.js': ['babel'],
'test/test_karma.js': ['babel]
},
babelPreprocessor: {
options: {
presets: ['@babel/preset-env']
}
},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['ChromeHeadless', 'Chrome'],
singleRun: false,
concurrency: Infinity
})
}
这是我的index.js
const sayHello = () => {
return 'hello karma'
}
export { sayHello }
这是我的test_karma.js
import {sayHello} from '../src/index';
import chai from 'chai';
describe('test', () => {
it('test', () => {
chai.assert(sayHello() === 'hello', 'say hello')
})
})