4

(同様の質問に対する回答がないことを知ると、少し意気消沈します)

テストが typescript のモジュールと並んで配置されるフォルダー/ファイルをセットアップします。単純なものを機能させようとしていますが、あまりうまくいきません。

Typescript 設定:

{
"compilerOptions": {
  "removeComments": true,
  "module": "amd",
  "target": "ES5",
  "experimentalDecorators": true,
  "sourceMap": false,
  "outDir" : "./public/js/"
},
"files": [
  "./assets/typescript/services/stockmarket-service.ts",
  "./assets/typescript/components/stockmarket-barchart/index.ts",
  "./assets/typescript/components/stockmarket-table/index.ts",
  "./assets/typescript/boot.ts"
  ]
}

カルマ構成:

module.exports = function (config) {
    config.set({
        frameworks: ['jasmine','requirejs'],
        preprocessors: {
            './assets/typescript/**/*.ts': ['typescript']
        },
        // plugins : [
        //     'karma-requirejs',
        //     'karma-jasmine',
        //     'karma-chrome-launcher',
        //     'karma-requirejs'
        // ],
        files: [
            "./public/jspm_packages/bower/riot@2.3.18/riot+compiler.js",
            "./public/jspm_packages/bower/riot-ts@0.0.22/riot-ts.js",
            './assets/**/*_test.ts',
            './test-main.js',
        ],
        pattern: './assets/**/!(*_test).ts',
        typescriptPreprocessor: {
            // options passed to the typescript compiler
            options: {
                sourceMap: false, // (optional) Generates corresponding .map file.
                target: 'ES5', // (optional) Specify ECMAScript target version: 'ES3' (default), or 'ES5'
                module: 'systemjs', // (optional) Specify module code generation: 'commonjs' or 'amd'
                noImplicitAny: true, // (optional) Warn on expressions and declarations with an implied 'any' type.
                noResolve: true, // (optional) Skip resolution and preprocessing.
                removeComments: true, // (optional) Do not emit comments to output.
                concatenateOutput: false // (optional) Concatenate and emit output to single file. By default true if module option is omited, otherwise false.
            },
            // transforming the filenames
            transformPath: function (path) {
                return path.replace(/\.ts$/, '.js');
            }
        },
        port: 9876,
        logLevel: config.LOG_INFO,
        colors: true,
        autoWatch: true,
        usePolling: true,
        singleRun: false,
        browsers: ['Chrome']
    });
};

テスト ファイル: stockmarket-service_test:

/// <reference path="../../../typings/tsd.d.ts" />
import {StockMarketService} from './stockmarket-service';

describe('StockMaketService Tests', () => {
    it('jamsine should be working', () => {expect(true).toEqual(true)});
    it('Should always need a url and an event bus',()=>{
        var sms = new StockMarketService();
        expect(sms).toThrowError();
    })
});

test-main (ルートにある)

var allTestFiles = [];
var TEST_REGEXP = /(spec|test)\.js$/i;

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

  // dynamically load all test files
  deps: allTestFiles,

  // we have to kickoff jasmine, as it is asynchronous
  callback: window.__karma__.start
});

karma startブラウザー レポートを使用してテストを実行すると:Uncaught Error: Module name "stockmarket-service" has not been loaded yet for context: _. Use require([])

仕様に含めたので、それは奇妙です。

ここに画像の説明を入力

完全なプロジェクトはこちら (WIP): https://github.com/sidouglas/riot-ts

4

0 に答える 0