私はカルマを使っていくつかのコードに対してテストを実行しています。RequireJSテキストプラグインの使用
カルマによって実行される前に、テストとコードの両方がトランスバースされます(ES6 => ES5、バベルを使用)。
これはうまく動作し、テストは正常に動作します。
しかし、私は試してみて、テストされているファイルのいずれかからtext!
プラグインを使用している場合...
import template from 'text!./template.html';
は...私が取得:なぜこの
There is no timestamp for /base/src/text.js!
Uncaught Error: Script error for "text", needed by: text!app/template.html_unnormalized2
http://requirejs.org/docs/errors.html#scripterror
Uncaught Error: Load timeout for modules: text!app/template.html_unnormalized2
誰がどんな考えを持っていますかもしれない?
dist
フォルダ(テスト対象すなわち項目)で構築されたアーティファクトが正常にエンコードされたテキストRequireJS項目などが含まれます。
define('text!app/template.html',[],function() { return '<div>foo</div>';});
追加情報
テストの主を。 js
var TEST_REGEXP = /(spec|test)\.js$/i;
var allTestFiles = [];
Object.keys(window.__karma__.files).forEach(function(file) {
if (TEST_REGEXP.test(file)) {
var normalizedTestModule = file.replace(/^\/base\/|\.js$/g, '');
allTestFiles.push(normalizedTestModule);
}
});
require.config({
baseUrl: '/base/src',
paths: {},
shim: {},
deps: allTestFiles,
callback: window.__karma__.start
});
karma.conf.js
module.exports = function(config) {
'use strict';
var path = require('path');
var cdn = 'http://localhost:55635/modules/';
var basePath = path.dirname(__filename);
config.set({
basePath: '../../..',
frameworks: [
'requirejs',
'jasmine'
],
files: [
{
pattern: path.join(basePath, 'test-transpiled', '*-spec.js'),
included: false
},
path.join(basePath, 'dist', 'artifacts', 'app.js'),
path.join(basePath, 'test', 'unit', 'test-main.js')
],
proxies: {
'/cdn/': cdn
},
exclude: [],
preprocessors: {},
reporters: ['dots'],
colors: true,
autoWatch: false,
singleRun: false,
browsers: ['Chrome'],
});
};
編集:
私はkarma.conf.jsに以下を追加しました:
files: [
{
pattern: path.join(basePath, 'node_modules/require-plugins/text/text.js'),
included: false
},
// ...
],
私はエラーを取得し続けますテストを実行するとき:
There is no timestamp for /base/src/text.js!
おそらく、私はtest-main.jsのパスセクションに "text"を追加する必要があるからでしょうか?
require.config({
baseUrl: '/base/src',
paths: {
'text': '../node_modules/require-plugins/text/text'
},
// ...
});
しかし、私は様々なbaseUrl
の組み合わせとtext
パスにパスを試してみましたが、私はそれは404-INGを停止することができません。
'test-main.js 'の' paths'に項目を追加する必要がありますか? ( '' text ':' ... '') – Ben
私は自分の答えを編集しました。 – Louis
プラグインは 'node_modules/require-plugins/text/text.js'にあります。しかし、私はtest-main内からこの方法をうまく参照する方法がわかりません。私が試したすべてのものは404です。 – Ben