[英]How to handle wallabyjs and karma configuration (with requirejs)
After reading the answers and comments on the topic Wallaby on a build server (CI) I accepted that wallabyjs is currently not ready for a ci scenario. 在阅读有关构建服务器(CI)上的Wallaby主题的答案和评论之后,我接受了wallabyjs当前尚未准备好用于ci场景。 Ok, but I am still questioning myself how to handle the typical scenario, that one uses wallabyjs on the client and karma (or another test runner) on the ci system.
好的,但是我仍然在问自己如何处理典型场景,即在客户端上使用wallabyjs,在ci系统上使用karma(或另一测试运行程序)。 Especially when using requirejs.
特别是在使用requirejs时。 As it is explained here there is a
正如这里所解释的,有一个
test-main.js — which configures require.js for the tests
test-main.js —为测试配置require.js
Using wallabyjs this looks more or less like 使用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();
});
Using karma as it is explained here , it looks more or less like this 使用此处说明的业力,它看起来或多或少像这样
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
});
Do I have to maintain two files? 我必须维护两个文件吗? Is there a need for some kind of conditional build?
是否需要某种条件构建? Has anyone experience with this scenario?
有没有人遇到过这种情况?
Thanks a lot. 非常感谢。
You may merge these two files into one to reuse the common part and add some logic to execute certain bits based on the current runner. 您可以将这两个文件合并为一个以重用公共部分,并添加一些逻辑以基于当前运行器执行某些位。
window.wallaby && wallaby.delayStart();
...
if (window.__karma__) {
...
}
...
require.config({
baseUrl: window.__karma__ ? '/base/src' : '/src',
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.