簡體   English   中英

如何處理Wallabyjs和業力配置(with requirejs)

[英]How to handle wallabyjs and karma configuration (with requirejs)

在閱讀有關構建服務器(CI)上的Wallaby主題的答案和評論之后,我接受了wallabyjs當前尚未准備好用於ci場景。 好的,但是我仍然在問自己如何處理典型場景,即在客戶端上使用wallabyjs,在ci系統上使用karma(或另一測試運行程序)。 特別是在使用requirejs時。 正如這里所解釋的有一個

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();
});

使用此處說明的業力,它看起來或多或少像這樣

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',
  ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM