将Jasmine规范文件传输到输出目录

时间:2016-08-02 22:34:57

标签: typescript jasmine systemjs

我已经完成了https://angular.io/docs/ts/latest/guide/testing.html的优秀教程,包括英雄之旅应用程序。

完成后,我想将编译器生成的JS移动到新的构建文件夹。我是通过将"outDir": "build"添加到文件tsconfig.json来完成此操作的。达到了预期的效果,我的英雄之旅应用程序仍在运行。

测试是一个问题,因为当我的NPM转换Jasmine spec文件时,会显示以下错误:

[1] 16.08.02 22:58:53 404 GET /app/person.spec.js
[1] 16.08.02 22:58:53 404 GET /app/my-uppercase.pipe.spec.js

这是因为我的编译器生成的spec.js和地图文件现在位于构建目录中,但没有被选中(运行应用程序时其他应用程序文件被选中,它只是缺少的测试文件)。我不确定如何修复甚至在哪里进行更改。

最有可能是我在unit-tests.html

中加载了承诺
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <title>Ng App Unit Tests</title>
    <link rel="stylesheet" href="../node_modules/jasmine-core/lib/jasmine-core/jasmine.css">
    <script src="../node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script>
    <script src="../node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script>
    <script src="../node_modules/jasmine-core/lib/jasmine-core/boot.js"></script>
</head>
<body>
<!-- #1. add the system.js library -->
<!-- #1. add the system.js and angular libraries -->
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/reflect-metadata/Reflect.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="systemjs.config.js"></script>
<script>
    // #2. Import the spec files explicitly
    Promise.all([
        System.import('app/person.spec'),
        System.import('app/my-uppercase.pipe.spec')
    ])

    // #3. wait for all imports to load ...
    //     then re-execute `window.onload` which
    //     triggers the Jasmine test-runner start
    //     or explain what went wrong.
            .then(window.onload)
            .catch(console.error.bind(console));
</script>
</body>
</html>

systemjs.config.js加载程序文件

/**
 * System configuration for Angular 2 samples
 * Adjust as necessary for your application needs.
 */
(function(global) {
    // map tells the System loader where to look for things
    var map = {
        'app':                        'app', // 'dist',
        '@angular':                   'node_modules/@angular',
        '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',
        'forms',
        '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] = { main: '/bundles/' + 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
    };
    System.config(config);
})(this);

或者以某种方式过滤掉规范文件,而不是通过tsconfig.json文件将它们放在构建文件夹中

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false,
    "outDir": "build"
  }
}

有关如何获取Jamsine编译的JS文件的任何建议?

提前致谢 X

0 个答案:

没有答案