尚未为context _加载typescript + karma模块。使用require([])

时间:2016-06-12 09:54:48

标签: typescript requirejs karma-runner riot

(对于类似问题没有答案,有点士气低落)

有一个文件夹/文件设置,其中测试与打字稿中的模块并排放置。试图让一些简单的工作,但不是很远。

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"
  ]
}

Karma配置:

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([])

这很奇怪,因为我把它包含在规范中。

enter image description here

完整项目在这里(WIP):https://github.com/sidouglas/riot-ts

0 个答案:

没有答案