Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/415.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Karma/PhantomJS无法运行用typescript编写的单元测试_Javascript_Typescript_Phantomjs_Karma Jasmine_Systemjs - Fatal编程技术网

Javascript Karma/PhantomJS无法运行用typescript编写的单元测试

Javascript Karma/PhantomJS无法运行用typescript编写的单元测试,javascript,typescript,phantomjs,karma-jasmine,systemjs,Javascript,Typescript,Phantomjs,Karma Jasmine,Systemjs,我正在尝试使用Karma&Jasmine在phantomJS中运行我的单元测试。unittests和源文件都是用Typescript编写的。 测试在Chrome、Safari和Firefox中运行良好,但在PhantomJS中失败。 错误: PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR Error: (SystemJS) eval@[native code] tryCatchReject@/poc/node_modules/systemjs/d

我正在尝试使用Karma&Jasmine在phantomJS中运行我的单元测试。unittests和源文件都是用Typescript编写的。 测试在Chrome、Safari和Firefox中运行良好,但在PhantomJS中失败。 错误:

PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
  Error: (SystemJS) eval@[native code]
        tryCatchReject@/poc/node_modules/systemjs/dist/system-polyfills.src.js:1188:34
        runContinuation1@/poc/node_modules/systemjs/dist/system-polyfills.src.js:1147:18
        when@/poc/node_modules/systemjs/dist/system-polyfills.src.js:935:20
        run@/poc/node_modules/systemjs/dist/system-polyfills.src.js:826:17
        _drain@/poc/node_modules/systemjs/dist/system-polyfills.src.js:102:22
        drain@/poc/node_modules/systemjs/dist/system-polyfills.src.js:67:15
        Evaluating /poc/src/components/button/button.js
        Error loading /poc/test/components/button/button.spec.ts
我试图连接phantomjs调试器,但它没有抛出任何错误,所以我有点困在这里

业力配置:

module.exports = function (config) {
  config.set({
    customLaunchers: {
      'PhantomJS_custom': {
        base: 'PhantomJS',
        options: {
          windowName: 'my-window',
          settings: {
            webSecurityEnabled: false
          }
        },
        flags: ['--load-images=true'],
        debug: true
      }
    },

    // 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: ['systemjs', 'jasmine'],

    plugins: [
      'karma-systemjs',
      'karma-jasmine',
      'karma-coverage',
      'karma-remap-istanbul',
      'karma-typescript-preprocessor',
      'karma-safari-launcher',
      'karma-chrome-launcher',
      'karma-firefox-launcher',
      'karma-phantomjs-launcher'
    ],

    preprocessors: {
      'src/**/*.ts': ['typescript', 'coverage']
    },

    // list of files / patterns to load in the browser
    files: [
      'node_modules/phantomjs-polyfill/bind-polyfill.js',
      'test/**/button.spec.ts',
      'testutils/**/*.ts'
    ],

    systemjs: {
      configFile: 'config/system.conf.js',
      config: {
        packages: {
          'src': {
            defaultExtension: 'js'
          },
          'test': {
            defaultExtension: 'ts'
          },
          'testutils': {
            defaultExtension: 'ts'
          }
        },

        transpiler: "typescript"
      },

      serveFiles: [
        'src/**/*.ts',
        'test/**/button.spec.ts',
        'testutils/**/*.ts'
      ]
    },

    // list of files to exclude
    exclude: [],

    coverageReporter: {
      reporters: [
        {
          type: 'json',
          dir: 'coverage',
          subdir: '.',
          file: 'report.json'
        }
      ]
    },

    remapIstanbulReporter: {
      src: 'coverage/report.json',
      reports: {
        lcovonly: 'coverage/lcov.info',
        html: 'coverage/html/report'
      }
    },

    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: [
      'progress',
      'coverage',
      'karma-remap-istanbul'
    ],
    typescriptPreprocessor: {
      // options passed to the typescript compiler
      options: {
        inlineSourceMap: true,
        inlineSources: true,
        "outDir": ".tmp/",
        sourceMap: false,
        noImplicitUseStrict: true,
        target: 'ES5', // (optional) Specify ECMAScript target version: 'ES3' (default), or 'ES5'
        module: 'commonjs', // (optional) Specify module code generation: 'commonjs' or 'amd'
        concatenateOutput: false // (optional) Concatenate and emit output to single file. By default true if module option is omitted, otherwise false.
      }
    },

    // 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_DEBUG,


    // 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: ['PhantomJS'],//, 'Safari', 'Chrome', 'Firefox'],


    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: false,

    // Concurrency level
    // how many browser should be started simultaneous
    concurrency: Infinity,

    captureTimeout: 60000,
    browserDisconnectTimeout: 20000000000,
    browserDisconnectTolerance: 0,
    browserNoActivityTimeout: 1000000000
  })
};

加载错误/poc/test/components/button/button.spec.ts
表明PhantomJS加载了错误的文件。TypeScript预处理器是否从
.ts
文件创建
.js
文件?是的,传输的文件已加载(至少,它们在Safari/Chrome中,我没有理由相信它们没有加载在PhantomJS中)。我记得PantomJS中的
eval
Date
存在一些问题。尝试运行最简单的示例