尝试使用Karma和Jasmine设置测试。
想设置gulp watch任务 - 我的gulp文件包含以下任务:
gulp.task('default', ['browserify','css','karma'], function () {
gulp.watch('../App/src/**/*.js', ['browserify']);
gulp.watch('../App/src/**/*.css', ['css']);
gulp.watch('../App/src/tests/**/*.js', ['rewireAndSetupTests']);
gulp.watch('../App/src/tests/**/*.js', ['karma']);
});
我的所有测试目前都失败了并出现错误:
[08:46:15] Starting Karma server...
INFO [karma]: Karma v0.12.37 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.8 (Windows 8 0.0.0)]: Connected on socket 3xjo1pLi0mPkCJQlk9Cd with id 68708323
PhantomJS 1.9.8 (Windows 8 0.0.0) ERROR
ReferenceError: Can't find variable: module
at d:/Source/tests/stub/channelStub.js:25
谁能告诉我如何设置我的测试?
这是我的业力配置:
var webpack = require("webpack"),
path = require("path");
module.exports = function (config) {
config.set({
basePath: "",
frameworks: ["jasmine"],
files: [
"node_modules/phantomjs-polyfill/bind-polyfill.js",
"./App/src/tests/bundle.js"
],
webpack: {
module: {
loaders: [
{ test: /\.js$/, loader: "jsx-loader" }
]
},
plugins: [
new webpack.ResolverPlugin([
new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin("bower.json", ["main"])
])
],
resolve: {
root: [path.join(__dirname, "./bower_components"), path.join(__dirname, "./src")]
}
},
webpackMiddleware: {
noInfo: true
},
plugins: [
require("karma-webpack"),
require("karma-jasmine"),
require("rewire-webpack"),
require("phantomjs"),
require("karma-phantomjs-launcher"),
require("karma-chrome-launcher")
],
reporters: ["dots"],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ["PhantomJS"],
singleRun: false
});
};
更新:似乎是乙烯基变换的问题,有谁知道我可以解决这个问题?
gulp.task('rewireAndSetupTests', function () {
var browserified = transform(function(filename) {
console.log(filename);
var b = browserify(filename);
b.transform({ global: true }, reactify);
b.transform({ global: true }, rewireify);
return b;
});
return gulp.src(['./app/src/tests/**/*.js'])
.pipe(concat('suite.js'))
.pipe(browserified)
.pipe(gulp.dest('./dist/'));
});