0
在閱讀關於主題Wallaby on a build server (CI)的答案和評論後,我接受wallabyjs目前尚未準備好ci場景。好吧,但我仍然在質疑自己如何處理典型的場景,即在客戶端使用wallabyjs,在ci系統上使用karma(或另一個測試運行器)。特別是在使用requirejs時。由於它是解釋here有一個如何處理wallabyjs和業力配置(與requirejs)
測試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
});
我必須維護兩個文件嗎?是否需要某種有條件的構建?有沒有人遇到這種情況?
非常感謝。