Gulp-Jasmine 给出了 SystemJS 的错误

gulp-jasmine gives error with systemjs

本文关键字:错误 SystemJS Gulp-Jasmine      更新时间:2023-09-26

--- UPDATE ---

所以我更新了我的任务,现在我有以下内容,问题是当它进入规范时,第一行如下

import {Injector, provide} from "angular2/core";

不幸的是,这不是引用node_modules/angular2目录,而是引用项目根目录!!

var jasmine = require('gulp-jasmine');
var System = require('systemjs');
gulp.task('newtest', () => {
System.config({
    baseURL: "/",
    transpiler: 'typescript',
    defaultJSExtensions: true,
    path: {
        "node_modules*": "node_modules/*"           
    },
    packages: {
        "app": {
            "defaultExtension": "js"
        }
    },      
    maps:{
        "angular2": "/node_modules/angular2",
    },
});
Promise.all([
    System.import('app/assets/services/config.service.spec'),
]).then(function(){     
    gulp.src(['app/assets/services/config.service.spec'])
        .pipe(jasmine())
}).catch(console.error.bind(console));
});

---老---

所以我可能是这个东西的新手,但我正在尝试使用 gulp 来构建、lint 和测试我的演示解决方案。该应用程序正在使用Angular 2,Gulp,SystemJS,Gulp-tslint和Gulp-Jasmine,但是我无法让Gulp-Jasmine在不摔倒的情况下运行。它抱怨如下:

events.js:141
throw er; // Unhandled 'error' event
^
TypeError: Invalid System.register call. Anonymous System.register calls can only be made by modules loaded by SystemJS.import and not via script tags.
at SystemJSNodeLoader. (D:'ng2demo'node_modules'systemjs'dist'system.src.js:2981:17)
at SystemJSNodeLoader. (D:'ng2demo'node_modules'systemjs'dist'system.src.js:3655:29)
at SystemJSNodeLoader. (D:'ng2demo'node_modules'systemjs'dist'system.src.js:4142:33)
at SystemJSNodeLoader.reduceRegister_ (D:'ng2demo'node_modules'systemjs'dist
'system.src.js:4142:33)
at SystemJSNodeLoader.pushRegister_ (D:'ng2demo'node_modules'systemjs'dist'system.src.js:2699:14)
at SystemJSNodeLoader.SystemJSLoader.register (D:'ng2demo'node_modules'syste
mjs'dist'system.src.js:2937:10)
at Object. (D:'ng2demo'app'assets'services'config.service.spec.js
:4:8)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)

它尝试运行的JS文件是用TypeScript编写的规范,并使用gulp-typescript转译为JS。所以文件的第一行是:

System.register(['angular2/core', 'angular2/http', 'angular2/http/testing',
./config.service'], function(exports_1, context_1) {
//Do Stuff
});

就是这条线有问题,有什么想法吗?

似乎缺少此行中的'

./config.service'], function(exports_1, context_1) {

应该是:

System.register(['angular2/core', 'angular2/http', 'angular2/http/testing',
'./config.service'], function(exports_1, context_1) {
//Do Stuff
});