(Little bit demoralising to seethat there are no answers to similar questions)
Have a folder/file setup where the tests sit side-by-side the modules in typescript. Trying to get something simple working, but not getting very far.
Typescript config:
{ "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 Config:
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'] }); };
Test file: 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 (sitting in the root)
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 });
When i run the test using karma start
the browser reports: Uncaught Error: Module name "stockmarket-service" has not been loaded yet for context: _. Use require([])
That's weird because I included it in the spec.
Full project is here (WIP): https://github.com/sidouglas/riot-ts
0 comments:
Post a Comment