如何处理 wallabyjs 和 karma 配置(使用 requirejs)
How to handle wallabyjs and karma configuration (with requirejs)
在阅读了关于主题 I accepted that wallabyjs is currently not ready for a ci scenario. 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. Especially when using requirejs. As it is explained here 的答案和评论后,有一个
test-main.js — which configures require.js for the tests
使用 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
});
我必须维护两个文件吗?是否需要某种条件构建?有没有人遇到过这种情况?
非常感谢。
您可以将这两个文件合并为一个文件以重用公共部分并添加一些逻辑以根据当前跑步者执行某些位。
window.wallaby && wallaby.delayStart();
...
if (window.__karma__) {
...
}
...
require.config({
baseUrl: window.__karma__ ? '/base/src' : '/src',
...
在阅读了关于主题
test-main.js — which configures require.js for the tests
使用 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
});
我必须维护两个文件吗?是否需要某种条件构建?有没有人遇到过这种情况?
非常感谢。
您可以将这两个文件合并为一个文件以重用公共部分并添加一些逻辑以根据当前跑步者执行某些位。
window.wallaby && wallaby.delayStart();
...
if (window.__karma__) {
...
}
...
require.config({
baseUrl: window.__karma__ ? '/base/src' : '/src',
...