Karma没有运行简单的打字稿测试(使用SystemJS + Jasmine)

时间:2017-10-24 09:43:11

标签: typescript jasmine karma-jasmine aurelia karma-systemjs

我一直在努力运行一个非常简单的打字稿单元测试,使用Karma,Jasmine,SystemJs返回“hello”。

从Aurelia Typescript ASP.NET核心骨架here抓住了这个项目,但从那时起我就没有运气单元测试,即使是那些包含在骨架中的单元测试,更不用说e2e测试了。

由于它来自aurelia骨架,我正在使用'gulp test'来进行单元测试。

感谢您的帮助!!

因此在跑步时我得到了:

665:DEBUG [config]: autoWatch set to false, because of singleRun
667:DEBUG [plugin]: Loading karma-* from C:\Devtfs\PartnerPortal\Development\Dev\src\PartnerPortal.Web\node_modules
669:DEBUG [plugin]: Loading plugin C:\Devtfs\PartnerPortal\Development\Dev\src\PartnerPortal.Web\node_modules/karma-chrome-launcher.
676:DEBUG [plugin]: Loading plugin C:\Devtfs\PartnerPortal\Development\Dev\src\PartnerPortal.Web\node_modules/karma-jasmine.
679:DEBUG [plugin]: Loading plugin C:\Devtfs\PartnerPortal\Development\Dev\src\PartnerPortal.Web\node_modules/karma-systemjs.
755:DEBUG [web-server]: Instantiating middleware
226:INFO [karma]: Karma v1.7.0 server started at http://0.0.0.0:9876/
227:INFO [launcher]: Launching browser Chrome with unlimited concurrency
234:INFO [launcher]: Starting browser Chrome
235:DEBUG [temp-dir]: Creating temp dir at C:\Users\hargom01\AppData\Local\Temp\karma-96822788
236:DEBUG [launcher]: C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --user-data-dir=C:\Users\hargom01\AppData\Local\Temp\karma-96822788 --no-default-browser-check --no-first-run --
disable-default-apps --disable-popup-blocking --disable-translate --disable-background-timer-throttling http://localhost:9876/?id=96822788
072:DEBUG [web-server]: serving: C:\Devtfs\PartnerPortal\Development\Dev\src\PartnerPortal.Web\node_modules\karma\static/client.html
107:DEBUG [web-server]: serving: C:\Devtfs\PartnerPortal\Development\Dev\src\PartnerPortal.Web\node_modules\karma\static/karma.js
211:DEBUG [karma]: A browser has connected on socket 8mBiIQtKCp05QnePAAAA
222:DEBUG [web-server]: serving: C:\Devtfs\PartnerPortal\Development\Dev\src\PartnerPortal.Web\node_modules\karma\static/favicon.ico
253:INFO [Chrome 60.0.3112 (Windows 10 0.0.0)]: Connected on socket 8mBiIQtKCp05QnePAAAA with id 96822788
253:DEBUG [launcher]: Chrome (id 96822788) captured in 3.026 secs
283:DEBUG [middleware:karma]: custom files null null null
284:DEBUG [middleware:karma]: Serving static request /context.html
297:DEBUG [web-server]: serving: C:\Devtfs\PartnerPortal\Development\Dev\src\PartnerPortal.Web\node_modules\karma\static/context.html
310:DEBUG [web-server]: serving: C:\Devtfs\PartnerPortal\Development\Dev\src\PartnerPortal.Web\node_modules\karma\static/context.js
319:DEBUG [middleware:source-files]: Requesting /base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?a462fdca9c003f57f07430376abd0e8850056f99 /
320:DEBUG [middleware:source-files]: Fetching C:/Devtfs/PartnerPortal/Development/Dev/src/PartnerPortal.Web/node_modules/jasmine-core/lib/jasmine-core/jasmine.js
324:DEBUG [web-server]: serving (cached): C:/Devtfs/PartnerPortal/Development/Dev/src/PartnerPortal.Web/node_modules/jasmine-core/lib/jasmine-core/jasmine.js
328:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-jasmine/lib/boot.js?945a38bf4e45ad2770eb94868231905a04a0bd3e /
329:DEBUG [middleware:source-files]: Fetching C:/Devtfs/PartnerPortal/Development/Dev/src/PartnerPortal.Web/node_modules/karma-jasmine/lib/boot.js
331:DEBUG [web-server]: serving (cached): C:/Devtfs/PartnerPortal/Development/Dev/src/PartnerPortal.Web/node_modules/karma-jasmine/lib/boot.js
332:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-jasmine/lib/adapter.js?7a813cc290d592e664331c573a1a796192cdd1ad /
332:DEBUG [middleware:source-files]: Fetching C:/Devtfs/PartnerPortal/Development/Dev/src/PartnerPortal.Web/node_modules/karma-jasmine/lib/adapter.js
333:DEBUG [web-server]: serving (cached): C:/Devtfs/PartnerPortal/Development/Dev/src/PartnerPortal.Web/node_modules/karma-jasmine/lib/adapter.js
335:DEBUG [middleware:source-files]: Requesting /base/node_modules/es6-module-loader/dist/es6-module-loader.js?39e16893eb134085a3ab101994c649fc7c9d587c /
335:DEBUG [middleware:source-files]: Fetching C:/Devtfs/PartnerPortal/Development/Dev/src/PartnerPortal.Web/node_modules/es6-module-loader/dist/es6-module-loader.js
336:DEBUG [web-server]: serving (cached): C:/Devtfs/PartnerPortal/Development/Dev/src/PartnerPortal.Web/node_modules/es6-module-loader/dist/es6-module-loader.js
338:DEBUG [middleware:source-files]: Requesting /base/node_modules/systemjs/dist/system-polyfills.js?0333d4f4b6e07d4158215c443c628f698a6507da /
339:DEBUG [middleware:source-files]: Fetching C:/Devtfs/PartnerPortal/Development/Dev/src/PartnerPortal.Web/node_modules/systemjs/dist/system-polyfills.js
340:DEBUG [web-server]: serving (cached): C:/Devtfs/PartnerPortal/Development/Dev/src/PartnerPortal.Web/node_modules/systemjs/dist/system-polyfills.js
341:DEBUG [middleware:source-files]: Requesting /base/node_modules/systemjs/dist/system.js?7d38fa8346b0412fe85b898d4b3deca102ad456c /
342:DEBUG [middleware:source-files]: Fetching C:/Devtfs/PartnerPortal/Development/Dev/src/PartnerPortal.Web/node_modules/systemjs/dist/system.js
344:DEBUG [web-server]: serving (cached): C:/Devtfs/PartnerPortal/Development/Dev/src/PartnerPortal.Web/node_modules/systemjs/dist/system.js
346:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-systemjs/lib/adapter.js?2a4f81c2bf7b0d88ae1aee0a13e56d0fce8e9c6e /
346:DEBUG [middleware:source-files]: Fetching C:/Devtfs/PartnerPortal/Development/Dev/src/PartnerPortal.Web/node_modules/karma-systemjs/lib/adapter.js
348:DEBUG [web-server]: serving (cached): C:/Devtfs/PartnerPortal/Development/Dev/src/PartnerPortal.Web/node_modules/karma-systemjs/lib/adapter.js
412:DEBUG [middleware:source-files]: Requesting /base/test/unit/setup.ts /
413:DEBUG [middleware:source-files]: Fetching C:/Devtfs/PartnerPortal/Development/Dev/src/PartnerPortal.Web/test/unit/setup.ts
414:DEBUG [web-server]: serving (cached): C:/Devtfs/PartnerPortal/Development/Dev/src/PartnerPortal.Web/test/unit/setup.ts
415:DEBUG [middleware:source-files]: Requesting /base/test/unit/hello.spec.ts /
415:DEBUG [middleware:source-files]: Fetching C:/Devtfs/PartnerPortal/Development/Dev/src/PartnerPortal.Web/test/unit/hello.spec.ts
416:DEBUG [web-server]: serving (cached): C:/Devtfs/PartnerPortal/Development/Dev/src/PartnerPortal.Web/test/unit/hello.spec.ts
421:DEBUG [middleware:source-files]: Requesting /base/node_modules/typescript/lib/typescript.js /
422:DEBUG [middleware:source-files]: Fetching C:/Devtfs/PartnerPortal/Development/Dev/src/PartnerPortal.Web/node_modules/typescript/lib/typescript.js
423:DEBUG [web-server]: serving (cached): C:/Devtfs/PartnerPortal/Development/Dev/src/PartnerPortal.Web/node_modules/typescript/lib/typescript.js
521:DEBUG [web-server]: upgrade /socket.io/?EIO=3&transport=websocket&sid=8mBiIQtKCp05QnePAAAA
254:WARN [Chrome 60.0.3112 (Windows 10 0.0.0)]: Disconnected (1 times), because no message in 10000 ms.
Chrome 60.0.3112 (Windows 10 0.0.0) ERROR
Disconnected, because no message in 10000 ms.


268:DEBUG [karma]: Run complete, exiting.
273:DEBUG [launcher]: Disconnecting all browsers
332:DEBUG [launcher]: Process Chrome exited with code 0
333:DEBUG [temp-dir]: Cleaning temp dir C:\Users\hargom01\AppData\Local\Temp\karma-96822788
380:DEBUG [launcher]: Finished all browsers
Finished 'test' after 15 s

代码位于./src/文件夹hello.ts

export class Hello {
  public sayHello() : string {
    return "hello";
  }
}

测试规范是int ./test/unit/文件夹hello.spec.ts

import {Hello} from '../../src/hello'
import {} from 'jasmine';

describe('hello module', () => {
    var sut;

    beforeEach(() => {
      sut = new Hello();
    });

    it('contains a hello', () => {
      expect(sut.sayHello()).toEqual('hello');
    });
});

karma配置文件(Karma.conf.js)

module.exports = function(config) {
  config.set({
    basePath: './',
    frameworks: ['systemjs', 'jasmine'],
    systemjs: {
      configFile: 'wwwroot/config.js',
      config: {
        paths: {
          "*": "*",
          "src/*": "src/*",
          "typescript": "node_modules/typescript/lib/typescript.js",
          "systemjs": "node_modules/systemjs/dist/system.js",
          'system-polyfills': 'node_modules/systemjs/dist/system-polyfills.js',
          'es6-module-loader': 'node_modules/es6-module-loader/dist/es6-module-loader.js',
          'jspm_packages/*': 'wwwroot/jspm_packages/*'
        },
        packages: {
          'test/unit': {
            defaultExtension: 'ts'
          },
          'src': {
            defaultExtension: 'ts'
          }
        },
        transpiler: 'typescript',
        typescriptOptions : {
          "module": "amd",
          "emitDecoratorMetadata": true,
          "experimentalDecorators": true
        }
      },
      serveFiles: [
        'src/**/*',
        'wwwroot/jspm_packages/**/*.js'
      ]
    },
    files: [
      'test/unit/setup.ts',
      'test/unit/*.ts'
    ],
    proxies:{
      '/base/jspm_packages/' : '/base/wwwroot/jspm_packages/'
    },
    exclude: [],
    preprocessors: { },
    reporters: ['progress'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_DEBUG,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: true
  });
};

gulp test.js

var gulp = require('gulp');
var Karma = require('karma').Server;

/**
 * Run test once and exit
 */
gulp.task('test', ['clean'], function (done) {
  let k = new Karma({
    configFile: __dirname + '/../../karma.conf.js',
    singleRun: true
    }, function() {
      done()
    });
  k.start();
});

的package.json

{
  "name": "partner-portalen",
  "version": "1.1.2",
  "private": true,
  "devDependencies": {
    "@types/jasmine": "^2.6.0",
    "@types/node": "^8.0.20",
    "aurelia-binding": "^1.3.0",
    "aurelia-bundler": "^0.4.0",
    "aurelia-pal-browser": "^1.3.0",
    "aurelia-protractor-plugin": "^1.0.5",
    "aurelia-router": "^1.4.0",
    "aurelia-tools": "^0.2.4",
    "browser-sync": "^2.13.0",
    "conventional-changelog": "1.1.0",
    "cross-env": "^3.1.3",
    "del": "^2.2.1",
    "es-module-loader": "^2.2.6",
    "gulp": "^3.9.1",
    "gulp-bump": "^2.2.0",
    "gulp-changed": "^1.3.1",
    "gulp-htmlmin": "^2.0.0",
    "gulp-notify": "^2.2.0",
    "gulp-plumber": "^1.1.0",
    "gulp-protractor": "3.0.0",
    "gulp-sass": "^3.1.0",
    "gulp-sourcemaps": "^1.6.0",
    "gulp-tslint": "^6.0.2",
    "gulp-typescript": "^2.14.1",
    "isparta": "^4.0.0",
    "jasmine": "^2.7.0",
    "jasmine-core": "^2.4.1",
    "jspm": "^0.16.41",
    "karma": "^1.1.2",
    "karma-chrome-launcher": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-systemjs": "^0.14.0",
    "object.assign": "^4.0.4",
    "require-dir": "^0.3.2",
    "run-sequence": "^1.2.2",
    "systemjs": "0.19.35",
    "tslint": "^3.13.0",
    "typescript": "^2.2.1",
    "vinyl-paths": "^2.1.0",
    "whatwg-fetch": "^2.0.3",
    "yargs": "^4.8.1"
  },
  "keywords": [
    "aurelia",
    "navigation",
    "partner portal",
    "typescript",
    "vscode"
  ],
  "scripts": {
    "prepublish": "npm run jspm-install",
    "jspm-install": "cross-env ./node_modules/.bin/jspm install -y",
    "test": "gulp test",
    "e2e": "gulp serve e2e"
  },
  "jspm": {
    "directories": {
      "baseURL": "wwwroot"
    },
    "dependencies": {
      "aurelia-animator-css": "npm:aurelia-animator-css@^1.0.0",
      "aurelia-api": "npm:aurelia-api@^3.1.1",
      "aurelia-authentication": "npm:aurelia-authentication@^3.6.0",
      "aurelia-bootstrapper": "npm:aurelia-bootstrapper@^1.0.0",
      "aurelia-event-aggregator": "npm:aurelia-event-aggregator@^1.0.1",
      "aurelia-fetch-client": "npm:aurelia-fetch-client@^1.0.0",
      "aurelia-framework": "npm:aurelia-framework@^1.1.4",
      "aurelia-history-browser": "npm:aurelia-history-browser@^1.0.0",
      "aurelia-http-client": "npm:aurelia-http-client@^1.1.1",
      "aurelia-i18n": "npm:aurelia-i18n@^1.6.2",
      "aurelia-loader-default": "npm:aurelia-loader-default@^1.0.0",
      "aurelia-logging-console": "npm:aurelia-logging-console@^1.0.0",
      "aurelia-pal-browser": "npm:aurelia-pal-browser@^1.3.0",
      "aurelia-polyfills": "npm:aurelia-polyfills@^1.0.0",
      "aurelia-router": "npm:aurelia-router@^1.3.0",
      "aurelia-templating-binding": "npm:aurelia-templating-binding@^1.0.0",
      "aurelia-templating-resources": "npm:aurelia-templating-resources@^1.4.0",
      "aurelia-templating-router": "npm:aurelia-templating-router@^1.0.0",
      "aurelia-validation": "npm:aurelia-validation@^1.1.1",
      "bluebird": "npm:bluebird@3.4.1",
      "bootstrap": "github:twbs/bootstrap@^3.3.7",
      "fetch": "github:github/fetch@^1.0.0",
      "font-awesome": "npm:font-awesome@4.6.3",
      "i18next-xhr-backend": "npm:i18next-xhr-backend@^1.4.2",
      "jquery": "npm:jquery@^3.2.1",
      "moment": "npm:moment@^2.18.1",
      "numeral": "npm:numeral@^2.0.6",
      "text": "github:systemjs/plugin-text@^0.0.8"
    },
    "devDependencies": {
      "babel": "npm:babel-core@^5.8.24",
      "babel-runtime": "npm:babel-runtime@^5.8.24",
      "core-js": "npm:core-js@^1.1.4"
    }
  },
  "dependencies": {
    "@types/bootstrap": "^3.3.36",
    "@types/jquery": "^3.2.15",
    "@types/numeral": "0.0.22",
    "aurelia-api": "^3.1.1",
    "aurelia-authentication": "^3.7.0",
    "aurelia-bootstrapper": "^2.1.1",
    "aurelia-dependency-injection": "^1.3.1",
    "aurelia-event-aggregator": "^1.0.1",
    "aurelia-fetch-client": "^1.1.2",
    "aurelia-framework": "^1.1.4",
    "aurelia-history": "^1.0.0",
    "aurelia-history-browser": "^1.0.0",
    "aurelia-http-client": "^1.1.1",
    "aurelia-i18n": "^1.6.2",
    "aurelia-loader": "^1.0.0",
    "aurelia-logging": "^1.3.1",
    "aurelia-logging-console": "^1.0.0",
    "aurelia-metadata": "^1.0.3",
    "aurelia-pal": "^1.3.0",
    "aurelia-path": "^1.1.1",
    "aurelia-polyfills": "^1.2.2",
    "aurelia-route-recognizer": "^1.1.0",
    "aurelia-task-queue": "^1.2.0",
    "aurelia-templating": "^1.4.2",
    "aurelia-templating-binding": "^1.3.0",
    "aurelia-templating-resources": "^1.4.0",
    "aurelia-templating-router": "^1.1.0",
    "aurelia-validation": "^1.1.1",
    "es6-module-loader": "^0.17.11",
    "es6-shim": "^0.35.3",
    "gulp-chutzpah": "^1.3.0",
    "i18next": "^8.4.3",
    "i18next-xhr-backend": "^1.4.2",
    "moment": "^2.18.1",
    "numeral": "^2.0.6",
    "serializer.ts": "0.0.12",
    "typescript": "^2.4.2",
    "whatwg-fetch": "^2.0.3"
  }
}

0 个答案:

没有答案