Карма не может разрешить переменные пространства имен в угловых, почему? - PullRequest
0 голосов
/ 25 апреля 2018

В моем приложении я настроил пространство имен для среды в tsconfig.ts приложение работает без ошибок, но проблема в том, что при запуске ng test команда карма не можетразрешить эти переменные.

Мой tsconfig выглядит следующим образом.

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ],
    "baseUrl": "src",
    "paths": {
      "@app/*": [
        "app/*"
      ],
      "@env/*": [
        "environments/*"
      ],
      "@service/*": [
        "services/*"
      ]
    }
  },
  "angularCompilerOptions": {
    "preserveWhitespaces": false
  }
}

В моем компоненте я обращаюсь к переменным окружения, подобным этому, для чтения templateUrl и styleUrls для домашнего компонента.

import { environment } from '@app/environments';

@Component({
  selector: 'app-home',
  templateUrl: environment.theme + '/home/home.component.html',
  styleUrls: [ environment.theme + '/home/home.component.scss']
})
export class HomeComponent {}

Это karma.conf.js

// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html

process.env.CHROME_BIN = require('puppeteer').executablePath();

module.exports = function(config) {
    config.set({
        basePath: '.',
        frameworks: ['jasmine', '@angular/cli', 'karma-typescript'],

        // file need to be loaded during testing.
        files: [
            // { pattern: 'src/environments/*', included: false, served: true, watched: true },
            // { pattern: 'src/services/*.{ts,js}', included: false, served: true, watched: true },
        ],


        karmaTypescriptConfig: {
            tsconfig: "./tsconfig.json",
            bundlerOptions: {
                transforms: [
                    require("karma-typescript-angular2-transform")
                ]
            }
        },
        preprocessors: {
            "**/*.ts": "karma-typescript"
        },

        plugins: [
            require('karma-jasmine'),
            require('karma-chrome-launcher'),
            require('karma-junit-reporter'),
            require('karma-coverage-istanbul-reporter'),
            require('@angular/cli/plugins/karma'),
            require('karma-typescript'),
        ],
        client: {
            clearContext: false, // leave Jasmine Spec Runner output visible in browser
            captureConsole: false
        },
        junitReporter: {
            outputDir: 'reports/junit/',
            outputFile: 'TESTS-xunit.xml',
            useBrowserName: false,
            suite: '' // Will become the package name attribute in xml testsuite element
        },
        coverageIstanbulReporter: {
            reports: ['html', 'lcovonly', 'text-summary'],
            dir: './reports/coverage',
            fixWebpackSourcePaths: false
        },
        angularCli: {
            environment: 'test'
        },
        reporters: ['progress', 'junit', 'karma-typescript'],
        port: 9876,
        colors: true,
        // Level of logging, can be: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
        logLevel: config.LOG_INFO,
        autoWatch: true,
        browsers: ['ChromeHeadless'],
        singleRun: false
    });
};

Я не могу понять, почему яя получаю эту ошибку, может кто-нибудь объяснить мне, почему это происходит?

Error details

Нужно ли что-то добавить в karma.conf.js, чтобы он знал о путях опция в tsconfig

...