gpt4 book ai didi

Angular2 测试 : Error when trying to use: @angular/platform-browser/testing/browser_util (Karma configurations)

转载 作者:太空狗 更新时间:2023-10-29 17:36:02 28 4
gpt4 key购买 nike

我正在尝试在运行 angular2 测试时使用 @angular/platform-b​​rowser/testing/browser_util。Angular2核心版本是2.3.0。我收到以下 404 错误:

[1]   {
[1] "__zone_symbol__error": {
[1] "originalStack": "Error: (SystemJS) XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util as \"@angular/platform-browser/testing/browser_util\" from app/components/gamestart/gamestart.component.spec.js",
[1] "zoneAwareStack": "Error: (SystemJS) XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util as \"@angular/platform-browser/testing/browser_util\" from app/components/gamestart/gamestart.component.spec.js"
[1] },
[1] "stack": "(SystemJS) XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util as \"@angular/platform-browser/testing/browser_util\" from app/components/gamestart/gamestart.component.spec.js",
[1] "name": "Error",
[1] "message": "(SystemJS) XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util as \"@angular/platform-browser/testing/browser_util\" from app/components/gamestart/gamestart.component.spec.js",
[1] "originalStack": "Error: (SystemJS) XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util as \"@angular/platform-browser/testing/browser_util\" from app/components/gamestart/gamestart.component.spec.js",
[1] "zoneAwareStack": "Error: (SystemJS) XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util as \"@angular/platform-browser/testing/browser_util\" from app/components/gamestart/gamestart.component.spec.js",
[1] "__zone_symbol__stack": "(SystemJS) XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util as \"@angular/platform-browser/testing/browser_util\" from app/components/gamestart/gamestart.component.spec.js",
[1] "originalErr": {
[1] "__zone_symbol__error": {
[1] "originalStack": "Error: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util",
[1] "zoneAwareStack": "Error: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util"
[1] },
[1] "stack": "Error: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util",
[1] "name": "Error",
[1] "message": "XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util",
[1] "originalStack": "Error: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util",
[1] "zoneAwareStack": "Error: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util",
[1] "__zone_symbol__stack": "Error: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util",
[1] "__zone_symbol__message": "XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util",
[1] "__zone_symbol__name": "Error",
[1] "__zone_symbol__originalStack": "Error: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util",
[1] "__zone_symbol__zoneAwareStack": "Error: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util"
[1] },
[1] "__zone_symbol__name": "Error",
[1] "__zone_symbol__message": "(SystemJS) XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util as \"@angular/platform-browser/testing/browser_util\" from app/components/gamestart/gamestart.component.spec.js",
[1] "__zone_symbol__originalStack": "Error: (SystemJS) XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util as \"@angular/platform-browser/testing/browser_util\" from app/components/gamestart/gamestart.component.spec.js",
[1] "__zone_symbol__zoneAwareStack": "Error: (SystemJS) XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util as \"@angular/platform-browser/testing/browser_util\" from app/components/gamestart/gamestart.component.spec.js"
[1] }
[1]
[1] Chrome 55.0.2883 (Linux 0.0.0) ERROR
[1] {
[1] "__zone_symbol__error": {
[1] "originalStack": "Error: (SystemJS) XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util as \"@angular/platform-browser/testing/browser_util\" from app/components/gamestart/gamestart.component.spec.js",
[1] "zoneAwareStack": "Error: (SystemJS) XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util as \"@angular/platform-browser/testing/browser_util\" from app/components/gamestart/gamestart.component.spec.js"
[1] },
[1] "stack": "(SystemJS) XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util as \"@angular/platform-browser/testing/browser_util\" from app/components/gamestart/gamestart.component.spec.js",
[1] "name": "Error",
[1] "message": "(SystemJS) XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util as \"@angular/platform-browser/testing/browser_util\" from app/components/gamestart/gamestart.component.spec.js",
[1] "originalStack": "Error: (SystemJS) XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util as \"@angular/platform-browser/testing/browser_util\" from app/components/gamestart/gamestart.component.spec.js",
[1] "zoneAwareStack": "Error: (SystemJS) XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util as \"@angular/platform-browser/testing/browser_util\" from app/components/gamestart/gamestart.component.spec.js",
[1] "__zone_symbol__stack": "(SystemJS) XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util as \"@angular/platform-browser/testing/browser_util\" from app/components/gamestart/gamestart.component.spec.js",
[1] "originalErr": {
[1] "__zone_symbol__error": {
[1] "originalStack": "Error: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util",
[1] "zoneAwareStack": "Error: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util"
[1] },
[1] "stack": "Error: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util",
[1] "name": "Error",
[1] "message": "XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util",
[1] "originalStack": "Error: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util",
[1] "zoneAwareStack": "Error: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util",
[1] "__zone_symbol__stack": "Error: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util",
[1] "__zone_symbol__message": "XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util",
[1] "__zone_symbol__name": "Error",
[1] "__zone_symbol__originalStack": "Error: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util",
[1] "__zone_symbol__zoneAwareStack": "Error: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util"
[1] },
[1] "__zone_symbol__name": "Error",
[1] "__zone_symbol__message": "(SystemJS) XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util as \"@angular/platform-browser/testing/browser_util\" from app/components/gamestart/gamestart.component.spec.js",
[1] "__zone_symbol__originalStack": "Error: (SystemJS) XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util as \"@angular/platform-browser/testing/browser_util\" from app/components/gamestart/gamestart.component.spec.js",
[1] "__zone_symbol__zoneAwareStack": "Error: (SystemJS) XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util as \"@angular/platform-browser/testing/browser_util\" from app/components/gamestart/gamestart.component.spec.js"
[1] }
[1]
[1] 27 01 2017 17:21:08.936:WARN [web-server]: 404: /base/node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util
[1] Chrome 55.0.2883 (Linux 0.0.0) ERROR
[1] {
[1] "__zone_symbol__error": {
[1] "originalStack": "Error: (SystemJS) XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util as \"@angular/platform-browser/testing/browser_util\" from app/components/gamestart/gamestart.component.spec.js",
[1] "zoneAwareStack": "Error: (SystemJS) XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util as \"@angular/platform-browser/testing/browser_util\" from app/components/gamestart/gamestart.component.spec.js"
[1] },
[1] "stack": "(SystemJS) XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util as \"@angular/platform-browser/testing/browser_util\" from app/components/gamestart/gamestart.component.spec.js",
[1] "name": "Error",
[1] "message": "(SystemJS) XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util as \"@angular/platform-browser/testing/browser_util\" from app/components/gamestart/gamestart.component.spec.js",
[1] "originalStack": "Error: (SystemJS) XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util as \"@angular/platform-browser/testing/browser_util\" from app/components/gamestart/gamestart.component.spec.js",
[1] "zoneAwareStack": "Error: (SystemJS) XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util as \"@angular/platform-browser/testing/browser_util\" from app/components/gamestart/gamestart.component.spec.js",
[1] "__zone_symbol__stack": "(SystemJS) XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util as \"@angular/platform-browser/testing/browser_util\" from app/components/gamestart/gamestart.component.spec.js",
[1] "originalErr": {
[1] "__zone_symbol__error": {
[1] "originalStack": "Error: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util",
[1] "zoneAwareStack": "Error: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util"
[1] },
[1] "stack": "Error: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util",
[1] "name": "Error",
[1] "message": "XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util",
[1] "originalStack": "Error: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util",
[1] "zoneAwareStack": "Error: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util",
[1] "__zone_symbol__stack": "Error: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util",
[1] "__zone_symbol__message": "XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util",
[1] "__zone_symbol__name": "Error",
[1] "__zone_symbol__originalStack": "Error: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util",
[1] "__zone_symbol__zoneAwareStack": "Error: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util"
[1] },
[1] "__zone_symbol__name": "Error",
[1] "__zone_symbol__message": "(SystemJS) XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util as \"@angular/platform-browser/testing/browser_util\" from app/components/gamestart/gamestart.component.spec.js",
[1] "__zone_symbol__originalStack": "Error: (SystemJS) XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError: XHR error (404 Not Found) loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util\n\tError loading node_modules/@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util as \"@angular/platform-browser/testing/browser_util\" from app/components/gamestart/gamestart.component.spec.js"

我在这里错过了什么?

更新这是 Karma 配置:

module.exports = function(config) {

var appBase = 'app/'; // transpiled app JS and map files
var appSrcBase = 'app/'; // app source TS files
var appAssets = 'base/app/'; // component assets fetched by Angular's compiler

// Testing helpers (optional) are conventionally in a folder called `testing`
var testingBase = 'testing/'; // transpiled test JS and map files
var testingSrcBase = 'testing/'; // test source TS files

config.set({
basePath: '',
frameworks: ['jasmine'],

plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter')
],

client: {
builtPaths: [appBase, testingBase], // add more spec base paths as needed
clearContext: false // leave Jasmine Spec Runner output visible in browser
},

customLaunchers: {
// From the CLI. Not used here but interesting
// chrome setup for travis CI using chromium
Chrome_travis_ci: {
base: 'Chrome',
flags: ['--no-sandbox']
}
},

files: [
// System.js for module loading
'node_modules/systemjs/dist/system.src.js',

// Polyfills
'node_modules/core-js/client/shim.js',
'node_modules/reflect-metadata/Reflect.js',

// zone.js
'node_modules/zone.js/dist/zone.js',
'node_modules/zone.js/dist/long-stack-trace-zone.js',
'node_modules/zone.js/dist/proxy.js',
'node_modules/zone.js/dist/sync-test.js',
'node_modules/zone.js/dist/jasmine-patch.js',
'node_modules/zone.js/dist/async-test.js',
'node_modules/zone.js/dist/fake-async-test.js',

// RxJs
{ pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
{ pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false },

// Paths loaded via module imports:
// Angular itself
{ pattern: 'node_modules/@angular/**/*.js', included: false, watched: false },
{ pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: false },

{ pattern: 'systemjs.config.js', included: false, watched: false },
{ pattern: 'systemjs.config.extras.js', included: false, watched: false },
'karma-test-shim.js', // optionally extend SystemJS mapping e.g., with barrels

// transpiled application & spec code paths loaded via module imports
{ pattern: appBase + '**/*.js', included: false, watched: true },
{ pattern: testingBase + '**/*.js', included: false, watched: true },


// Asset (HTML & CSS) paths loaded via Angular's component compiler
// (these paths need to be rewritten, see proxies section)
{ pattern: appBase + '**/*.html', included: false, watched: true },
{ pattern: appBase + '**/*.css', included: false, watched: true },

// Paths for debugging with source maps in dev tools
{ pattern: appSrcBase + '**/*.ts', included: false, watched: false },
{ pattern: appBase + '**/*.js.map', included: false, watched: false },
{ pattern: testingSrcBase + '**/*.ts', included: false, watched: false },
{ pattern: testingBase + '**/*.js.map', included: false, watched: false}
],

// Proxied base paths for loading assets
proxies: {
// required for component assets fetched by Angular's compiler
"/app/": appAssets
},

exclude: [],
preprocessors: {},
reporters: ['progress', 'kjhtml'],

port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
})
}

Jasmine 包.json:

{
"name": "@types/jasmine",
"version": "2.5.38",
"description": "TypeScript definitions for Jasmine 2.5",
"license": "MIT",
"author": "Boris Yankov <https://github.com/borisyankov/>, Theodore Brown <https://github.com/theodorejb>, David Pärsson <https://github.com/davidparsson/>",
"main": "",
"repository": {
"type": "git",
"url": "https://www.github.com/DefinitelyTyped/DefinitelyTyped.git"
},
"scripts": {},
"dependencies": {},
"peerDependencies": {},
"typings": "index.d.ts",
"typesPublisherContentHash": "deae5b77cefabcb3a692eff958b0cfe55516a87b535b4247349dbe4fc5f835f6",
"_id": "@types/jasmine@2.5.38",
"dist": {
"shasum": "a4379124c4921d4e21de54ec74669c9e9b356717",
"tarball": "https://registry.npmjs.org/@types/jasmine/-/jasmine-2.5.38.tgz"
},
"maintainers": [
{
"name": "types",
"email": "ryan.cavanaugh@microsoft.com"
}
],
"_npmUser": {
"name": "types",
"email": "ts-npm-types@microsoft.com"
},
"_npmOperationalInternal": {
"host": "packages-18-east.internal.npmjs.com",
"tmp": "tmp/jasmine-2.5.38.tgz_1479152172228_0.4748733174055815"
},
"directories": {},
"_shasum": "a4379124c4921d4e21de54ec74669c9e9b356717",
"_resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-2.5.38.tgz",
"_from": "@types/jasmine@>=2.5.36 <3.0.0"
}

系统.config.js:

/**
* System configuration for Angular samples
* Adjust as necessary for your application needs.
*/
(function (global) {
System.config({
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
app: 'app',

// angular bundles
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',

// other libraries
'rxjs': 'npm:rxjs',
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
main: './main.js',
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
}
}
});
})(this);

最佳答案

您的问题是如何在 system.config.js 中配置测试包

这个:

@angular/platform-browser/bundles/platform-browser-testing.umd.js/browser_util

意味着它正在寻找“platform-b​​rowser-testing.umd.js”下的 browser_util,这是一个文件,而不是一个目录。

你的 system.config.js 应该为这个包配置:

@angular/platform-browser/bundles/platform-browser-testing.

更新 1:

这是您正确配置的 System.config.js。不同的是,当它不需要捆绑时,它使用单独的文件。特别是这些行:

// Individual files (~300 requests):
function packIndex(pkgName) {
packages['@angular/' + pkgName] = {main: 'index.js', defaultExtension: 'js'};
}

// Bundled (~40 requests):
function packUmd(pkgName) {
packages['@angular/' + pkgName + '/bundles/'] = {main: pkgName + '.umd.js', defaultExtension: 'js'};
};

// Most environments should use UMD; some (Karma) need the individual index files
var setPackageConfig = System.packageWithIndex ? packIndex : packUmd;

整个文件:

(function (global) {
// map tells the System loader where to look for things
var map = {
'app': 'app',
'@angular': 'node_modules/@angular',
'@angular/common': 'node_modules/@angular/common',
'@angular/compiler': 'node_modules/@angular/compiler',
'@angular/platform-browser': 'node_modules/@angular/platform-browser',
'@angular/platform-browser-dynamic': 'node_modules/@angular/platform-browser-dynamic',
'@angular/http': 'node_modules/@angular/http',
'@angular/router': 'node_modules/@angular/router',
'@angular/forms': 'node_modules/@angular/forms',
'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
'rxjs': 'node_modules/rxjs',
};

// packages tells the System loader how to load when no filename and/or no extension
var packages = {
'app': {main: 'main.js', defaultExtension: 'js'},
'rxjs': {defaultExtension: 'js'},
'angular2-in-memory-web-api': {main: 'index.js', defaultExtension: 'js'},
};

var ngPackageNames = [
'common',
'compiler',
'core',
'http',
'platform-browser',
'platform-browser-dynamic',
'router',
'router-deprecated',
'upgrade'
];

// Individual files (~300 requests):
function packIndex(pkgName) {
packages['@angular/' + pkgName] = {main: 'index.js', defaultExtension: 'js'};
}

// Bundled (~40 requests):
function packUmd(pkgName) {
packages['@angular/' + pkgName + '/bundles/'] = {main: pkgName + '.umd.js', defaultExtension: 'js'};
};

// Most environments should use UMD; some (Karma) need the individual index files
var setPackageConfig = System.packageWithIndex ? packIndex : packUmd;

// Add package entries for angular packages
ngPackageNames.forEach(setPackageConfig);

var config = {
map: map,
packages: packages,
meta: meta
};

System.config(config);
})
(this);

更新 2:

  1. “不同之处在于,当它不需要捆绑时,它使用单独的文件”……你能进一步解释一下吗?什么是 bundle ?

bundle 是从包中所有组合的 JavaScript 文件创建的 JavaScript。如果您查看“node_modules\@angular\platform-b​​rowser\bundles”目录,您仍然会看到以“.umd”结尾的文件,如“platform-b​​rowser.umd.js”。这些文件通常在您构建生产应用程序时使用。但是(出于我不知道的原因),Karma 无法使用捆绑文件,需要单独的文件,如“node_modules\@angular\platform-b​​rowser\testing\browser_util.js”中所示。

  1. System.packageWithIndex 如何更新?

我不知道。我看到每个人都在使用它,但是当我在控制台上输出它时,它是未定义的。找了之后,连SystemJS库的源码都找不到。我必须在这里发布一个问题,看看是否每个人都知道,或者它是否只是被复制/粘贴而没有人问为什么。

与此同时,我查看了官方 Angular 启动器的 Karma 配置,发现他们为 Karma 单独配置了 SystemJS,并单独导入了测试模块。我建议你看看那个并做同样的事情。 https://github.com/angular/quickstart/blob/master/karma-test-shim.js

  1. 我看到你正在更新包变量。你能举例说明在这个变量中设置的路径吗?

想法是将变量“setPackageConfig”设置为“packIndex”或“packUmd”函数,并将其用作从 bundle 或单个文件构建包的回调。

我将其留作引用,但请查看 https://github.com/angular/quickstart/blob/master/karma-test-shim.js 中的 karma 配置并忽略之前的 systemjs 配置。

关于Angular2 测试 : Error when trying to use: @angular/platform-browser/testing/browser_util (Karma configurations),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41897444/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com