【发布时间】:2016-02-29 10:53:36
【问题描述】:
在阅读了关于 Wallaby on a build server (CI) 主题的答案和 cmets 之后,我接受了 wallabyjs 目前还没有为 ci 场景做好准备。好的,但我仍然在质疑自己如何处理典型场景,即在客户端使用 wallabyjs,在 ci 系统上使用 karma(或另一个测试运行器)。特别是在使用 requirejs 时。正如here所解释的那样,有一个
test-main.js — 为测试配置 require.js
使用 wallabyjs 这看起来或多或少像
// delaying wallaby automatic start
wallaby.delayStart();
requirejs.config({
baseUrl: '/src',
paths: {
'jquery': '../lib/jquery',
'underscore': '../lib/underscore'
},
shim: {
'underscore': {
exports: '_'
}
}
});
require(wallaby.tests, function () {
wallaby.start();
});
使用因果报应here,看起来或多或少像这样
var TEST_REGEXP = /(spec|test)\.js$/i;
var allTestFiles = [];
// Get a list of all the test files to include
Object.keys(window.__karma__.files).forEach(function(file) {
if (TEST_REGEXP.test(file)) {
// Normalize paths to RequireJS module names.
// If you require sub-dependencies of test files to be loaded as-is (requiring file extension)
// then do not normalize the paths
var normalizedTestModule = file.replace(/^\/base\/|\.js$/g, '');
allTestFiles.push(normalizedTestModule);
}
});
require.config({
// Karma serves files under /base, which is the basePath from your config file
baseUrl: '/base/src',
// example of using a couple path translations (paths), to allow us to refer to different library dependencies, without using relative paths
paths: {
'jquery': '../lib/jquery',
'underscore': '../lib/underscore',
},
// example of using a shim, to load non AMD libraries (such as underscore)
shim: {
'underscore': {
exports: '_'
}
},
// dynamically load all test files
deps: allTestFiles,
// we have to kickoff jasmine, as it is asynchronous
callback: window.__karma__.start
});
我必须维护两个文件吗?是否需要某种有条件的构建?有没有人经历过这种情况?
非常感谢。
【问题讨论】: