使用phantomjs和angular2排除karma.js中的文件夹

时间:2017-03-14 11:32:23

标签: javascript angular typescript karma-runner karma-jasmine

当我尝试使用phantomjs运行karma测试时遇到问题,如果我有一些内部有另一个node_modules的例子。

例如:

source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!

platform :ios, '10.0'

target 'TestAlamofire' do
    pod 'Alamofire', '~> 4.4'
    pod 'AlamofireDomain', '~> 4.1'
    pod 'ObjectMapper', '~> 2.2'
end

的package.json

MyComponent
└── node_modules
└── examples
    └── node_modules
    └── src
        └── app
            └── app.component.ts
            └── app.component.html
            └── app.component.css
            └── app.component.spec
            └── app.module.ts
        └── assets
        └── index.html
        └── angular-cli.json
        └── karma.conf.js
        └── package.json
└── src
    └── app
        └── my.component.ts
        └── my.component.html
        └── my.component.css
        └── my.component.spec.ts
    └── assets
    └── base.spec.ts
    └── karma.conf.js
    └── package.json

karma.conf.js

  "dependencies": {
    "@angular/common": "2.4.9",
    "@angular/compiler": "2.4.9",
    "@angular/core": "2.4.9",
    "@angular/http": "2.4.9",
    "@angular/platform-browser": "2.4.9",
    "@angular/platform-browser-dynamic": "2.4.9",
    "@angular/router": "3.4.9",
    "@types/core-js": "0.9.36",
    "@types/echarts": "0.0.5",
    "angular-in-memory-web-api": "0.3.1",
    "core-js": "2.4.1",
    "echarts": "3.4.0",
    "rxjs": "5.0.1",
    "systemjs": "0.19.40",
    "zone.js": "0.7.4"
  },
  "devDependencies": {
    "@types/jasmine": "2.5.44",
    "@types/node": "6.0.65",
    "typescript": "2.2.1",
    "jasmine-core": "2.5.2",
    "karma": "1.5.0",
    "karma-chrome-launcher": "2.0.0",
    "karma-jasmine": "1.1.0",
    "karma-typescript": "3.0.0-beta.1",
    "karma-typescript-angular2-transform": "1.0.0-beta.5",
    "karma-phantomjs-launcher": "1.0.4"
  }

当我在没有examples文件夹的情况下运行测试时,一切正常,但如果我尝试使用里面的示例运行测试并忽略它,它就不起作用。

我收到了下一个错误:

  

14 03 2017 11:15:07.881:ERROR [karma]:TypeError:无法读取属性   '名称'未定义的       在mergeSymbol(/workspace/node_modules/typescript/lib/typescript.js:25122:46)       at /workspace/node_modules/typescript/lib/typescript.js:25146:21       在Map.forEach(原生)

1 个答案:

答案 0 :(得分:0)

我发现了你的错误。

我必须排除预处理器配置中的文件夹:

karmaTypescriptConfig: { bundlerOptions: { entrypoints: /\.spec\.ts$/, transforms: [ require("karma-typescript-angular2-transform") ] }, coverageOptions: { instrumentation: true }, exclude: ['examples'] },