加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Karma Testing Angular Seed Project System.JS路径错误

发布时间:2020-12-17 17:10:03 所属栏目:安全 来源:网络整理
导读:我刚刚使用 https://github.com/mgechev/angular-seed作为我的初始设置开始使用Angular. 我在使用Jasmine进行初始单元测试设置时遇到了一些问题.我的项目中使用的OAuth库似乎是个问题,但我不确定它是否可以被安全地抑制或者我需要对配置做出哪些更改. base /
我刚刚使用 https://github.com/mgechev/angular-seed作为我的初始设置开始使用Angular.

我在使用Jasmine进行初始单元测试设置时遇到了一些问题.我的项目中使用的OAuth库似乎是个问题,但我不确定它是否可以被安全地抑制或者我需要对配置做出哪些更改. base / node_modules路径当前不正确,但我不确定配置的哪一部分构建它.我已经尝试将路径添加到被忽略的部分,但错误仍然存??在.任何帮助赞赏.

// Karma configuration
// Generated on Wed Jul 15 2015 09:44:02 GMT+0200 (Romance Daylight Time)
'use strict';

var argv = require('yargs').argv;
var minimatch = require("minimatch");


module.exports = function (config) {
  config.set({

    // base path that will be used to resolve all patterns (eg. files,exclude)
    basePath: './',// frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['jasmine'],// list of files / patterns to load in the browser
    files: [
      // Polyfills.
      'node_modules/core-js/client/shim.min.js','node_modules/intl/dist/Intl.min.js','node_modules/traceur/bin/traceur.js',// System.js for module loading
      'node_modules/systemjs/dist/system.src.js',// Zone.js dependencies
      'node_modules/zone.js/dist/zone.js','node_modules/zone.js/dist/long-stack-trace-zone.js','node_modules/zone.js/dist/async-test.js','node_modules/zone.js/dist/fake-async-test.js','node_modules/zone.js/dist/sync-test.js','node_modules/zone.js/dist/proxy.js','node_modules/zone.js/dist/jasmine-patch.js',// RxJs.
      { pattern: 'node_modules/rxjs/**/*.js',included: false,watched: false },{ pattern: 'node_modules/rxjs/**/*.js.map',// paths loaded via module imports
      // Angular itself
      { pattern: 'node_modules/@angular/**/*.js',watched: true },{ pattern: 'node_modules/@angular/**/*.js.map',{ pattern: 'dist/dev/**/*.js',{ pattern: 'dist/dev/**/*.html',watched: true,served: true },{ pattern: 'dist/dev/**/*.css',{ pattern: 'node_modules/systemjs/dist/system-polyfills.js',// PhantomJS2 (and possibly others) might require it

      // suppress annoying 404 warnings for resources,images,etc.
      { pattern: 'dist/dev/assets/**/*',watched: false,'test-config.js','dist/dev/app/system-config.js','test-main.js'
    ],// must go along with above,suppress annoying 404 warnings.
    proxies: {
      '/assets/': '/base/dist/dev/assets/'
    },// list of files to exclude
    exclude: [
      'node_modules/**/*spec.js','node_modules/angular-oauth2-oidc/dist/index.js',],// preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor

    // test results reporter to use
    // possible values: 'dots','progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['mocha'],// web server port
    port: 9876,// enable / disable colors in the output (reporters and logs)
    colors: true,// level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_INFO,// enable / disable watching file and executing tests whenever any file changes
    autoWatch: true,// start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: [
      'Chrome'
    ],customLaunchers: {
      Chrome_travis_ci: {
        base: 'Chrome',flags: ['--no-sandbox']
      }
    },// Continuous Integration mode
    // if true,Karma captures browsers,runs the tests and exits
    singleRun: false,// Passing command line arguments to tests
    client: {
      files:  argv.files ? minimatch.makeRe(argv.files).source : null
    }
  });

  if (process.env.APPVEYOR) {
    config.browsers = ['IE'];
    config.singleRun = true;
    config.browserNoActivityTimeout = 90000; // Note: default value (10000) is not enough
  }

  if (process.env.TRAVIS || process.env.CIRCLECI) {
    config.browsers = ['Chrome_travis_ci'];
    config.singleRun = true;
    config.browserNoActivityTimeout = 90000;
  }
};

以下是错误消息:

06 07 2017 09:27:29.589:INFO [karma]: Karma v1.3.0 server started at http://loca
lhost:9876/
06 07 2017 09:27:29.590:INFO [launcher]: Launching browser Chrome with unlimited
 concurrency
06 07 2017 09:27:29.595:INFO [launcher]: Starting browser Chrome
06 07 2017 09:27:31.064:INFO [Chrome 59.0.3071 (Windows 8.1 0.0.0)]: Connected o
n socket /#4mhCO5mVkEwzD0EfAAAA with id 14947625
06 07 2017 09:27:32.242:WARN [web-server]: 404: /base/node_modules/angular-oauth
2-oidc/dist/index.js
Chrome 59.0.3071 (Windows 8.1 0.0.0) ERROR: '(SystemJS) XHR error (404 Not Found
) loading http://localhost:9876/base/node_modules/angular-oauth2-oidc/dist/index
.js
        Error: XHR error (404 Not Found) loading http://localhost:9876/base/node
_modules/angular-oauth2-oidc/dist/index.js
            at XMLHttpRequest.wrapFn [as __zone_symbol___onreadystatechange] (ht
tp://localhost:9876/base/node_modules/zone.js/dist/zone.js?082dc1d83c7a42ddda9b6
52319d281eef1d450d5:1056:39)
            at ZoneDelegate.invokeTask (http://localhost:9876/base/node_modules/
zone.js/dist/zone.js?082dc1d83c7a42ddda9b652319d281eef1d450d5:424:31)
            at Zone.runTask (http://localhost:9876/base/node_modules/zone.js/dis
t/zone.js?082dc1d83c7a42ddda9b652319d281eef1d450d5:191:47)
            at XMLHttpRequest.ZoneTask.invoke (http://localhost:9876/base/node_m
odules/zone.js/dist/zone.js?082dc1d83c7a42ddda9b652319d281eef1d450d5:486:38)
        Error loading http://localhost:9876/base/node_modules/angular-oauth2-oid
c/dist/index.js as "angular-oauth2-oidc" from http://localhost:9876/base/dist/de
v/app/shared/login/login-service.js'
Chrome 59.0.3071 (Windows 8.1 0.0.0) ERROR: '(SystemJS) XHR error (404 Not Found
) loading http://localhost:9876/base/node_modules/angular-oauth2-oidc/dist/index
.js
        Error: XHR error (404 Not Found) loading http://localhost:9876/base/node
_modules/angular-oauth2-oidc/dist/index.js
            at XMLHttpRequest.wrapFn [as __zone_symbol___onreadystatechange] (ht
tp://localhost:9876/base/node_modules/zone.js/dist/zone.js?082dc1d83c7a42ddda9b6
52319d281eef1d450d5:1056:39)
            at ZoneDelegate.invokeTask (http://localhost:9876/base/node_modules/
zone.js/dist/zone.js?082dc1d83c7a42ddda9b652319d281eef1d450d5:424:31)
            at Zone.runTask (http://localhost:9876/base/node_modules/zone.js/dis
t/zone.js?082dc1d83c7a42ddda9b652319d281eef1d450d5:191:47)
            at XMLHttpRequest.ZoneTask.invoke (http://localhost:9876/base/node_m
odules/zone.js/dist/zone.js?082dc1d83c7a42ddda9b652319d281eef1d450d5:486:38)
        Error loading http://localhost:9876/base/node_modules/angular-oauth2-oid
c/dist/index.js as "angular-oauth2-oidc" from http://localhost:9876/base/dist/de
v/app/shared/login/login-service.js'
06 07 2017 09:27:32.274:WARN [web-server]: 404: /base/node_modules/angular-oauth
2-oidc/dist/index.js

更新:

删除要排除的文件列表后:

enter image description here

解决方法

我认为你也需要代理node_module

proxies: {
            '/node_modules/': "/base/node_modules/",'/assets/': '/base/dist/dev/assets/'
        },

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读