我使用业力进行配置来运行我的测试用例。如果在测试文件或源文件中使用任何ES6代码,我会收到错误。下面我附上我的配置。请帮帮我。
module.exports = function (config) {
config.set({
browsers: ['PhantomJS'],
colors: true,
client: {
clearContext: false
},
failOnEmptyTestSuite: false,
frameworks: [
'mocha',
'chai'
],
files: [
'tests/test.js',
//{pattern: 'tests/globals.js'},
'js/**/*.js'
],
preprocessors: {
'tests/test.js': ['webpack', 'sourcemap'],
'js/**/*.js': ['webpack'],
'tests/**/*.js': ['webpack'],
},
reporters:['spec', 'coverage'],
coverageReporter: {
reporters: [
{ type: 'text' },
{ type: 'html', subdir: 'html' }
],
},
webpack: {
cache: true,
devtool: 'inline-source-map',
module: {
loaders: [
{
enforce: 'pre',
test: /.test\.js$/,
include: /tests/,
exclude: /node_modules/,
use: [{ loader: 'babel-loader' }]
},
{
enforce: 'pre',
test: /\.js$/,
include: /js/,
exclude: /node_modules/,
use: [{ loader: 'istanbul-instrumenter-loader', query: { esModules: true } }]
},
{
test: /\.js$/,
include: /js/,
exclude: /node_modules|tests/,
use: [{ loader: 'babel-loader' }]
},
],
},
},
});
};

我的测试用例文件是
import '../js/help/help.js';
describe("CamelCase Function",()=>{
it("the given text should be a string", () =>{
var str = "satya";
testString = Utility.camelCaseConvertion(str);
expect(testString).to.be.a("string");
});
it("Should convert the first letters to Capital",()=>{
expect(Utility.camelCaseConvertion("test 123test test@123 anywhereworks any")).to.equal("Test 123test Test@123 Anywhereworks Any");
});
it("should not convet to camel case",()=>{
expect(Utility.camelCaseConvertion("@anywhereworks")).to.equal("@anywhereworks");
});
it("should convert to camel case after space",()=>{
expect(Utility.camelCaseConvertion("<h1>aw anywhere")).to.equal("<h1>aw Anywhere")
});
});
&#13;
如果我在help.js中使用任何ES6代码,那么它也会抛出错误。我如何能够转换我的源代码以及使用上述配置进行测试。