monounity / karma-typescript

Simplifying running unit tests with coverage for Typescript projects.
313 stars 109 forks source link

Exclude does not work #32

Closed pearljamik closed 7 years ago

pearljamik commented 7 years ago

Config is like:

 `   preprocessors: {
        "src/**/*.ts": ["karma-typescript"]
    },

    karmaTypescriptConfig: {
        compilerOptions: {
            emitDecoratorMetadata: true,
            experimentalDecorators: true,
            module: "commonjs",
            sourceMap: true,
            target: "ES5"
        },
        include: ["src/app/**/*.ts"],
        exclude: ["node_modules"],
        reports:
            {
                "html": "coverage",
                "text-summary": ""
            }
    },`

When running:

`npm run test

node --max-old-space-size=4096 node_modules/karma/bin/karma start

18 11 2016 18:05:08.214:INFO [compiler.karma-typescript]: Compiling project using Typescript 2.0.7 18 11 2016 18:05:10.196:ERROR [compiler.karma-typescript]: No source found for c:/Users/gwk736/Gitlab/pro/node_modules/rxjs/add/observable/if.d.ts 18 11 2016 18:05:10.250:ERROR [compiler.karma-typescript]: No source found for c:/Users/gwk736/Gitlab/pro/node_modules/rxjs/add/observable/throw.d.ts 18 11 2016 18:05:10.904:ERROR [compiler.karma-typescript]: No source found for c:/Users/gwk736/Gitlab/pro/node_modules/common-map/node_modules/rxjs/add/observable/throw.d.ts 18 11 2016 18:05:14.102:ERROR [compiler.karma-typescript]: No source found for c:/Users/gwk736/Gitlab/pro/src/app/index.ts 18 11 2016 18:05:18.220:INFO [compiler.karma-typescript]: Compiled 252 files in 9329 ms. 18 11 2016 18:05:33.589:ERROR [karma]: RangeError: Maximum call stack size exceeded

monounity commented 7 years ago

Hey @pearljamik, the exclude property only affects which files the Typescript compiler picks up, it doesn't affect which files Karma picks up for the test run. What does the file section in your Karma conf look like, which patterns have you specified? It seems Karma has picked a lot of files that the compiler hasn't picked up, that's why you get these error messages. This should probably be clarified in the documentation...

pearljamik commented 7 years ago

Files section:

> files: [
            { pattern: "node_modules/reflect-metadata/Reflect.js" },
            { pattern: "node_modules/zone.js/dist/zone.js" },
            { pattern: "node_modules/zone.js/dist/long-stack-trace-zone.js" },
            { pattern: "node_modules/zone.js/dist/proxy.js" },
            { pattern: "node_modules/zone.js/dist/sync-test.js" },
            { pattern: "node_modules/zone.js/dist/jasmine-patch.js" },
            { pattern: "node_modules/zone.js/dist/async-test.js" },
            { pattern: "node_modules/zone.js/dist/fake-async-test.js" },

            { pattern: "src/app/**/*.ts" }
        ],
monounity commented 7 years ago

@pearljamik, it looks like you've found a nasty little bug, so I've added more debug logging because I need more input to fix it...

pearljamik commented 7 years ago

23 11 2016 17:18:59.188:ERROR [compiler.karma-typescript]: No source found for C:/Users/gwk736/Gitlab/Inform/node_modules/rxjs/add/observable/if.d.ts 23 11 2016 17:18:59.248:ERROR [compiler.karma-typescript]: No source found for C:/Users/gwk736/Gitlab/Inform/node_modules/rxjs/add/observable/throw.d.ts 23 11 2016 17:18:59.952:ERROR [compiler.karma-typescript]: No source found for C:/Users/gwk736/Gitlab/Inform/node_modules/common-map/node_modules/rxjs/add/observable/throw.d.ts

monounity commented 7 years ago

Does everything work if you install the latest from main again?

ehartford commented 6 years ago

It is happening to me too

maxime1992 commented 6 years ago

Any news? I do have the same problem.

My repo has the following structure:

| backend/
|--karma.conf.js
|--src/
|----app.spec.ts
| frontend/
| package.json

Here's my backend/karma.conf.json:

module.exports = function(config) {
  config.set({
    basePath: '..',
    frameworks: ['jasmine', 'karma-typescript'],
    files: ['./backend/src/**/*spec.ts'],
    preprocessors: {
      './backend/src/**/*spec.ts': 'karma-typescript',
    },
    reporters: ['progress', 'karma-typescript'],
    browsers: ['Chromium'],
    karmaTypescriptConfig: {
      compilerOptions: {
        include: ['./backend/src/**/*spec.ts'],
        exclude: ['../node_modules'],
      },
    },
    karmaTypescriptConfig: { exclude: ['../node_modules'] },
  });
};

Within package.json I have the following script: "back:test": "karma start backend/karma.conf.js --auto-watch",

My test is a dumb one just to make sure it's working:

describe('Test', () => {
  it('should be true', () => {
    expect(true).toBe(true);
  });
});

The test run and succeed :tada: BUT...

I still have some Typescript errors:

$ karma start backend/karma.conf.js --auto-watch 02 03 2018 23:55:35.378:INFO [compiler.karma-typescript]: Compiling project using Typescript 2.7.2 02 03 2018 23:55:45.761:ERROR [compiler.karma-typescript]: error TS2468: Cannot find global value 'Promise'. 02 03 2018 23:55:45.762:ERROR [compiler.karma-typescript]: backend/src/main.ts(5,16): error TS2705: An async function or method in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your `--lib` option. 02 03 2018 23:55:45.762:ERROR [compiler.karma-typescript]: cypress/integration/basic.e2e-spec.ts(5,5): error TS2304: Cannot find name 'cy'. 02 03 2018 23:55:45.762:ERROR [compiler.karma-typescript]: cypress/integration/basic.e2e-spec.ts(9,5): error TS2304: Cannot find name 'cy'. 02 03 2018 23:55:45.762:ERROR [compiler.karma-typescript]: cypress/integration/basic.e2e-spec.ts(10,5): error TS2304: Cannot find name 'cy'. 02 03 2018 23:55:45.763:ERROR [compiler.karma-typescript]: cypress/integration/basic.e2e-spec.ts(11,5): error TS2304: Cannot find name 'cy'. 02 03 2018 23:55:45.763:ERROR [compiler.karma-typescript]: cypress/integration/basic.e2e-spec.ts(13,5): error TS2304: Cannot find name 'cy'. 02 03 2018 23:55:45.763:ERROR [compiler.karma-typescript]: cypress/integration/basic.e2e-spec.ts(14,5): error TS2304: Cannot find name 'cy'. 02 03 2018 23:55:45.763:ERROR [compiler.karma-typescript]: frontend/src/app/app-routing.module.ts(9,43): error TS2307: Cannot find module 'app/core/runtime-environment.service'. 02 03 2018 23:55:45.763:ERROR [compiler.karma-typescript]: frontend/src/app/app-routing.module.ts(10,29): error TS2307: Cannot find module 'environments/environment'. 02 03 2018 23:55:45.763:ERROR [compiler.karma-typescript]: frontend/src/app/app.component.spec.ts(12,27): error TS2307: Cannot find module 'app/core/injection-tokens'. 02 03 2018 23:55:45.764:ERROR [compiler.karma-typescript]: frontend/src/app/app.component.spec.ts(13,28): error TS2307: Cannot find module 'app/shared/states/ui/ui.actions'. 02 03 2018 23:55:45.764:ERROR [compiler.karma-typescript]: frontend/src/app/app.component.spec.ts(15,40): error TS2307: Cannot find module 'app/shared/states/root.reducer'. 02 03 2018 23:55:45.764:ERROR [compiler.karma-typescript]: frontend/src/app/app.component.spec.ts(16,24): error TS2307: Cannot find module 'app/shared/interfaces/store.interface'. 02 03 2018 23:55:45.764:ERROR [compiler.karma-typescript]: frontend/src/app/app.component.ts(7,27): error TS2307: Cannot find module 'app/core/injection-tokens'. 02 03 2018 23:55:45.764:ERROR [compiler.karma-typescript]: frontend/src/app/app.component.ts(8,24): error TS2307: Cannot find module 'app/shared/interfaces/store.interface'. 02 03 2018 23:55:45.764:ERROR [compiler.karma-typescript]: frontend/src/app/app.component.ts(9,28): error TS2307: Cannot find module 'app/shared/states/ui/ui.actions'. 02 03 2018 23:55:45.764:ERROR [compiler.karma-typescript]: frontend/src/app/app.component.ts(10,29): error TS2307: Cannot find module 'app/shared/states/ui/ui.selectors'. 02 03 2018 23:55:45.765:ERROR [compiler.karma-typescript]: frontend/src/app/app.component.ts(11,29): error TS2307: Cannot find module 'environments/environment'. 02 03 2018 23:55:45.765:ERROR [compiler.karma-typescript]: frontend/src/app/app.component.ts(52,44): error TS2345: Argument of type '{}' is not assignable to parameter of type 'string'. 02 03 2018 23:55:45.765:ERROR [compiler.karma-typescript]: frontend/src/app/app.module.ts(9,34): error TS2307: Cannot find module 'app/app-routing.module'. 02 03 2018 23:55:45.766:ERROR [compiler.karma-typescript]: frontend/src/app/app.module.ts(10,30): error TS2307: Cannot find module 'app/app.component'. 02 03 2018 23:55:45.766:ERROR [compiler.karma-typescript]: frontend/src/app/app.module.ts(11,28): error TS2307: Cannot find module 'app/core/core.module'. 02 03 2018 23:55:45.767:ERROR [compiler.karma-typescript]: frontend/src/app/app.module.ts(12,30): error TS2307: Cannot find module 'app/shared/shared.module'. 02 03 2018 23:55:45.767:ERROR [compiler.karma-typescript]: frontend/src/app/app.module.ts(13,29): error TS2307: Cannot find module 'environments/environment'. 02 03 2018 23:55:45.767:ERROR [compiler.karma-typescript]: frontend/src/app/core/core.module.ts(13,27): error TS2307: Cannot find module 'app/core/injection-tokens'. 02 03 2018 23:55:45.767:ERROR [compiler.karma-typescript]: frontend/src/app/core/core.module.ts(14,43): error TS2307: Cannot find module 'app/core/runtime-environment.service'. 02 03 2018 23:55:45.767:ERROR [compiler.karma-typescript]: frontend/src/app/core/core.module.ts(15,35): error TS2307: Cannot find module 'app/shared/helpers/aot.helper'. 02 03 2018 23:55:45.767:ERROR [compiler.karma-typescript]: frontend/src/app/core/core.module.ts(16,40): error TS2307: Cannot find module 'app/shared/states/root.reducer'. 02 03 2018 23:55:45.768:ERROR [compiler.karma-typescript]: frontend/src/app/core/core.module.ts(17,29): error TS2307: Cannot find module 'environments/environment'. 02 03 2018 23:55:45.768:ERROR [compiler.karma-typescript]: frontend/src/app/core/runtime-environment.service.ts(8,29): error TS2307: Cannot find module 'environments/environment'. 02 03 2018 23:55:45.768:ERROR [compiler.karma-typescript]: frontend/src/app/features/features-routing.module.ts(4,35): error TS2307: Cannot find module 'app/features/features.component'. 02 03 2018 23:55:45.768:ERROR [compiler.karma-typescript]: frontend/src/app/features/features.component.ts(8,27): error TS2307: Cannot find module 'app/core/injection-tokens'. 02 03 2018 23:55:45.769:ERROR [compiler.karma-typescript]: frontend/src/app/features/features.component.ts(9,24): error TS2307: Cannot find module 'app/shared/interfaces/store.interface'. 02 03 2018 23:55:45.769:ERROR [compiler.karma-typescript]: frontend/src/app/features/features.component.ts(10,28): error TS2307: Cannot find module 'app/shared/states/ui/ui.actions'. 02 03 2018 23:55:45.769:ERROR [compiler.karma-typescript]: frontend/src/app/features/features.component.ts(11,21): error TS2307: Cannot find module 'app/shared/states/ui/ui.interface'. 02 03 2018 23:55:45.769:ERROR [compiler.karma-typescript]: frontend/src/app/features/features.module.ts(3,39): error TS2307: Cannot find module 'app/features/features-routing.module'. 02 03 2018 23:55:45.769:ERROR [compiler.karma-typescript]: frontend/src/app/features/features.module.ts(4,35): error TS2307: Cannot find module 'app/features/features.component'. 02 03 2018 23:55:45.769:ERROR [compiler.karma-typescript]: frontend/src/app/features/features.module.ts(5,30): error TS2307: Cannot find module 'app/shared/shared.module'. 02 03 2018 23:55:45.769:ERROR [compiler.karma-typescript]: frontend/src/app/shared/helpers/mock.helper.ts(7,29): error TS2307: Cannot find module 'environments/environment'. 02 03 2018 23:55:45.770:ERROR [compiler.karma-typescript]: frontend/src/app/shared/interfaces/store.interface.ts(1,21): error TS2307: Cannot find module 'app/shared/states/ui/ui.interface'. 02 03 2018 23:55:45.770:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.actions.ts(3,49): error TS2307: Cannot find module 'app/shared/states/pizzas/pizzas.interfaces'. 02 03 2018 23:55:45.770:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.effects.ts(8,32): error TS2307: Cannot find module 'app/shared/states/pizzas/pizzas.actions'. 02 03 2018 23:55:45.770:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.effects.ts(9,31): error TS2307: Cannot find module 'app/shared/states/pizzas/pizzas.service'. 02 03 2018 23:55:45.771:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.effects.ts(10,29): error TS2307: Cannot find module 'environments/environment'. 02 03 2018 23:55:45.771:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.initial-state.ts(5,8): error TS2307: Cannot find module 'app/shared/states/pizzas/pizzas.interfaces'. 02 03 2018 23:55:45.771:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.initial-state.ts(6,31): error TS2307: Cannot find module 'app/shared/states/pizzas/pizzas.reducer'. 02 03 2018 23:55:45.771:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.reducer.ts(4,32): error TS2307: Cannot find module 'app/shared/states/pizzas/pizzas.actions'. 02 03 2018 23:55:45.771:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.reducer.ts(5,36): error TS2307: Cannot find module 'app/shared/states/pizzas/pizzas.initial-state'. 02 03 2018 23:55:45.771:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.reducer.ts(9,8): error TS2307: Cannot find module 'app/shared/states/pizzas/pizzas.interfaces'. 02 03 2018 23:55:45.771:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.selectors.ts(6,8): error TS2307: Cannot find module 'app/shared/states/pizzas/pizzas.reducer'. 02 03 2018 23:55:45.771:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.selectors.ts(38,28): error TS2339: Property 'selected' does not exist on type '{}'. 02 03 2018 23:55:45.771:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.service.mock.ts(4,35): error TS2307: Cannot find module 'app/shared/states/pizzas/pizzas.initial-state'. 02 03 2018 23:55:45.772:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.service.mock.ts(8,8): error TS2307: Cannot find module 'app/shared/states/pizzas/pizzas.interfaces'. 02 03 2018 23:55:45.772:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.service.mock.ts(9,31): error TS2307: Cannot find module 'app/shared/states/pizzas/pizzas.service'. 02 03 2018 23:55:45.772:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.service.ts(5,35): error TS2307: Cannot find module 'app/shared/states/pizzas/pizzas.initial-state'. 02 03 2018 23:55:45.772:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.service.ts(9,8): error TS2307: Cannot find module 'app/shared/states/pizzas/pizzas.interfaces'. 02 03 2018 23:55:45.772:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.service.ts(10,29): error TS2307: Cannot find module 'environments/environment'. 02 03 2018 23:55:45.773:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/root.reducer.ts(5,24): error TS2307: Cannot find module 'app/shared/interfaces/store.interface'. 02 03 2018 23:55:45.773:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/root.reducer.ts(6,27): error TS2307: Cannot find module 'app/shared/states/ui/ui.reducer'. 02 03 2018 23:55:45.773:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/root.reducer.ts(7,29): error TS2307: Cannot find module 'environments/environment'. 02 03 2018 23:55:45.773:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/ui/ui.initial-state.ts(1,21): error TS2307: Cannot find module 'app/shared/states/ui/ui.interface'. 02 03 2018 23:55:45.773:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/ui/ui.reducer.ts(3,28): error TS2307: Cannot find module 'app/shared/states/ui/ui.actions'. 02 03 2018 23:55:45.773:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/ui/ui.reducer.ts(4,32): error TS2307: Cannot find module 'app/shared/states/ui/ui.initial-state'. 02 03 2018 23:55:45.773:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/ui/ui.reducer.ts(5,21): error TS2307: Cannot find module 'app/shared/states/ui/ui.interface'. 02 03 2018 23:55:45.773:ERROR [compiler.karma-typescript]: node_modules/@nestjs/core/injector/modules-container.d.ts(2,47): error TS2689: Cannot extend an interface 'Map'. Did you mean 'implements'? 02 03 2018 23:55:45.774:ERROR [compiler.karma-typescript]: node_modules/@types/jasmine/index.d.ts(14,18): error TS2300: Duplicate identifier 'describe'. 02 03 2018 23:55:45.775:ERROR [compiler.karma-typescript]: node_modules/@types/jasmine/index.d.ts(16,18): error TS2300: Duplicate identifier 'xdescribe'. 02 03 2018 23:55:45.775:ERROR [compiler.karma-typescript]: node_modules/@types/jasmine/index.d.ts(25,18): error TS2300: Duplicate identifier 'it'. 02 03 2018 23:55:45.775:ERROR [compiler.karma-typescript]: node_modules/@types/jasmine/index.d.ts(35,18): error TS2300: Duplicate identifier 'xit'. 02 03 2018 23:55:45.776:ERROR [compiler.karma-typescript]: node_modules/@types/jasminewd2/index.d.ts(9,18): error TS2300: Duplicate identifier 'it'. 02 03 2018 23:55:45.776:ERROR [compiler.karma-typescript]: node_modules/@types/jasminewd2/index.d.ts(11,18): error TS2300: Duplicate identifier 'xit'. 02 03 2018 23:55:45.776:ERROR [compiler.karma-typescript]: node_modules/@types/mocha/index.d.ts(36,13): error TS2300: Duplicate identifier 'describe'. 02 03 2018 23:55:45.776:ERROR [compiler.karma-typescript]: node_modules/@types/mocha/index.d.ts(37,13): error TS2300: Duplicate identifier 'xdescribe'. 02 03 2018 23:55:45.776:ERROR [compiler.karma-typescript]: node_modules/@types/mocha/index.d.ts(42,13): error TS2300: Duplicate identifier 'it'. 02 03 2018 23:55:45.777:ERROR [compiler.karma-typescript]: node_modules/@types/mocha/index.d.ts(43,13): error TS2300: Duplicate identifier 'xit'. 02 03 2018 23:55:45.777:ERROR [compiler.karma-typescript]: node_modules/rxjs/Observable.d.ts(58,60): error TS2693: 'Promise' only refers to a type, but is being used as a value here. 02 03 2018 23:55:45.777:ERROR [compiler.karma-typescript]: node_modules/rxjs/Observable.d.ts(73,59): error TS2693: 'Promise' only refers to a type, but is being used as a value here. 02 03 2018 23:55:46.289:INFO [compiler.karma-typescript]: Compiled 45 files in 10870 ms. 02 03 2018 23:55:47.011:WARN [karma]: No captured browser, open http://localhost:9876/ 02 03 2018 23:55:47.028:INFO [karma]: Karma v2.0.0 server started at http://0.0.0.0:9876/ 02 03 2018 23:55:47.029:INFO [launcher]: Launching browser Chromium with unlimited concurrency 02 03 2018 23:55:47.037:INFO [launcher]: Starting browser Chromium 02 03 2018 23:55:49.477:INFO [Chromium 64.0.3282 (Ubuntu 0.0.0)]: Connected on socket yxxy5QAzRxgT1uMwAAAA with id 1913170 Chromium 64.0.3282 (Ubuntu 0.0.0): Executed 1 of 1 SUCCESS (0.009 secs / 0 secs)

1) Why do I have errors from node_modules? 2) Why do I have errors from the frontend?

I'm not including them, only backend/...

Thanks for the good work btw :)

erikbarke commented 6 years ago

@maxime1992, you need to include all .ts files you want to compile and test in the files and preprocessors section of the Karma config: ./backend/src/**/*.ts.

Also, you need to fix this in your tsconfig: error TS2705: An async function or method in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your --lib option

maxime1992 commented 6 years ago

@erikbarke thanks :)

So I did try to include all the TS files (files + tests) and target to ES6 but still no luck, I think it's even worse as now:


Stacktrace from node_modules:

$ karma start backend/karma.conf.js --auto-watch 03 03 2018 10:15:25.557:INFO [compiler.karma-typescript]: Compiling project using Typescript 2.7.2 03 03 2018 10:15:35.607:ERROR [compiler.karma-typescript]: error TS2468: Cannot find global value 'Promise'. 03 03 2018 10:15:35.608:ERROR [compiler.karma-typescript]: backend/src/main.ts(5,16): error TS2705: An async function or method in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your `--lib` option. 03 03 2018 10:15:35.609:ERROR [compiler.karma-typescript]: cypress/integration/basic.e2e-spec.ts(5,5): error TS2304: Cannot find name 'cy'. 03 03 2018 10:15:35.609:ERROR [compiler.karma-typescript]: cypress/integration/basic.e2e-spec.ts(9,5): error TS2304: Cannot find name 'cy'. 03 03 2018 10:15:35.609:ERROR [compiler.karma-typescript]: cypress/integration/basic.e2e-spec.ts(10,5): error TS2304: Cannot find name 'cy'. 03 03 2018 10:15:35.609:ERROR [compiler.karma-typescript]: cypress/integration/basic.e2e-spec.ts(11,5): error TS2304: Cannot find name 'cy'. 03 03 2018 10:15:35.609:ERROR [compiler.karma-typescript]: cypress/integration/basic.e2e-spec.ts(13,5): error TS2304: Cannot find name 'cy'. 03 03 2018 10:15:35.609:ERROR [compiler.karma-typescript]: cypress/integration/basic.e2e-spec.ts(14,5): error TS2304: Cannot find name 'cy'. 03 03 2018 10:15:35.610:ERROR [compiler.karma-typescript]: frontend/src/app/app-routing.module.ts(9,43): error TS2307: Cannot find module 'app/core/runtime-environment.service'. 03 03 2018 10:15:35.610:ERROR [compiler.karma-typescript]: frontend/src/app/app-routing.module.ts(10,29): error TS2307: Cannot find module 'environments/environment'. 03 03 2018 10:15:35.610:ERROR [compiler.karma-typescript]: frontend/src/app/app.component.spec.ts(12,27): error TS2307: Cannot find module 'app/core/injection-tokens'. 03 03 2018 10:15:35.610:ERROR [compiler.karma-typescript]: frontend/src/app/app.component.spec.ts(13,28): error TS2307: Cannot find module 'app/shared/states/ui/ui.actions'. 03 03 2018 10:15:35.610:ERROR [compiler.karma-typescript]: frontend/src/app/app.component.spec.ts(15,40): error TS2307: Cannot find module 'app/shared/states/root.reducer'. 03 03 2018 10:15:35.610:ERROR [compiler.karma-typescript]: frontend/src/app/app.component.spec.ts(16,24): error TS2307: Cannot find module 'app/shared/interfaces/store.interface'. 03 03 2018 10:15:35.610:ERROR [compiler.karma-typescript]: frontend/src/app/app.component.ts(7,27): error TS2307: Cannot find module 'app/core/injection-tokens'. 03 03 2018 10:15:35.610:ERROR [compiler.karma-typescript]: frontend/src/app/app.component.ts(8,24): error TS2307: Cannot find module 'app/shared/interfaces/store.interface'. 03 03 2018 10:15:35.610:ERROR [compiler.karma-typescript]: frontend/src/app/app.component.ts(9,28): error TS2307: Cannot find module 'app/shared/states/ui/ui.actions'. 03 03 2018 10:15:35.611:ERROR [compiler.karma-typescript]: frontend/src/app/app.component.ts(10,29): error TS2307: Cannot find module 'app/shared/states/ui/ui.selectors'. 03 03 2018 10:15:35.611:ERROR [compiler.karma-typescript]: frontend/src/app/app.component.ts(11,29): error TS2307: Cannot find module 'environments/environment'. 03 03 2018 10:15:35.611:ERROR [compiler.karma-typescript]: frontend/src/app/app.component.ts(52,44): error TS2345: Argument of type '{}' is not assignable to parameter of type 'string'. 03 03 2018 10:15:35.611:ERROR [compiler.karma-typescript]: frontend/src/app/app.module.ts(9,34): error TS2307: Cannot find module 'app/app-routing.module'. 03 03 2018 10:15:35.612:ERROR [compiler.karma-typescript]: frontend/src/app/app.module.ts(10,30): error TS2307: Cannot find module 'app/app.component'. 03 03 2018 10:15:35.612:ERROR [compiler.karma-typescript]: frontend/src/app/app.module.ts(11,28): error TS2307: Cannot find module 'app/core/core.module'. 03 03 2018 10:15:35.612:ERROR [compiler.karma-typescript]: frontend/src/app/app.module.ts(12,30): error TS2307: Cannot find module 'app/shared/shared.module'. 03 03 2018 10:15:35.612:ERROR [compiler.karma-typescript]: frontend/src/app/app.module.ts(13,29): error TS2307: Cannot find module 'environments/environment'. 03 03 2018 10:15:35.613:ERROR [compiler.karma-typescript]: frontend/src/app/core/core.module.ts(13,27): error TS2307: Cannot find module 'app/core/injection-tokens'. 03 03 2018 10:15:35.613:ERROR [compiler.karma-typescript]: frontend/src/app/core/core.module.ts(14,43): error TS2307: Cannot find module 'app/core/runtime-environment.service'. 03 03 2018 10:15:35.613:ERROR [compiler.karma-typescript]: frontend/src/app/core/core.module.ts(15,35): error TS2307: Cannot find module 'app/shared/helpers/aot.helper'. 03 03 2018 10:15:35.613:ERROR [compiler.karma-typescript]: frontend/src/app/core/core.module.ts(16,40): error TS2307: Cannot find module 'app/shared/states/root.reducer'. 03 03 2018 10:15:35.614:ERROR [compiler.karma-typescript]: frontend/src/app/core/core.module.ts(17,29): error TS2307: Cannot find module 'environments/environment'. 03 03 2018 10:15:35.614:ERROR [compiler.karma-typescript]: frontend/src/app/core/runtime-environment.service.ts(8,29): error TS2307: Cannot find module 'environments/environment'. 03 03 2018 10:15:35.614:ERROR [compiler.karma-typescript]: frontend/src/app/features/features-routing.module.ts(4,35): error TS2307: Cannot find module 'app/features/features.component'. 03 03 2018 10:15:35.614:ERROR [compiler.karma-typescript]: frontend/src/app/features/features.component.ts(8,27): error TS2307: Cannot find module 'app/core/injection-tokens'. 03 03 2018 10:15:35.615:ERROR [compiler.karma-typescript]: frontend/src/app/features/features.component.ts(9,24): error TS2307: Cannot find module 'app/shared/interfaces/store.interface'. 03 03 2018 10:15:35.615:ERROR [compiler.karma-typescript]: frontend/src/app/features/features.component.ts(10,28): error TS2307: Cannot find module 'app/shared/states/ui/ui.actions'. 03 03 2018 10:15:35.615:ERROR [compiler.karma-typescript]: frontend/src/app/features/features.component.ts(11,21): error TS2307: Cannot find module 'app/shared/states/ui/ui.interface'. 03 03 2018 10:15:35.615:ERROR [compiler.karma-typescript]: frontend/src/app/features/features.module.ts(3,39): error TS2307: Cannot find module 'app/features/features-routing.module'. 03 03 2018 10:15:35.615:ERROR [compiler.karma-typescript]: frontend/src/app/features/features.module.ts(4,35): error TS2307: Cannot find module 'app/features/features.component'. 03 03 2018 10:15:35.615:ERROR [compiler.karma-typescript]: frontend/src/app/features/features.module.ts(5,30): error TS2307: Cannot find module 'app/shared/shared.module'. 03 03 2018 10:15:35.615:ERROR [compiler.karma-typescript]: frontend/src/app/shared/helpers/mock.helper.ts(7,29): error TS2307: Cannot find module 'environments/environment'. 03 03 2018 10:15:35.616:ERROR [compiler.karma-typescript]: frontend/src/app/shared/interfaces/store.interface.ts(1,21): error TS2307: Cannot find module 'app/shared/states/ui/ui.interface'. 03 03 2018 10:15:35.616:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.actions.ts(3,49): error TS2307: Cannot find module 'app/shared/states/pizzas/pizzas.interfaces'. 03 03 2018 10:15:35.616:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.effects.ts(8,32): error TS2307: Cannot find module 'app/shared/states/pizzas/pizzas.actions'. 03 03 2018 10:15:35.616:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.effects.ts(9,31): error TS2307: Cannot find module 'app/shared/states/pizzas/pizzas.service'. 03 03 2018 10:15:35.616:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.effects.ts(10,29): error TS2307: Cannot find module 'environments/environment'. 03 03 2018 10:15:35.616:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.initial-state.ts(5,8): error TS2307: Cannot find module 'app/shared/states/pizzas/pizzas.interfaces'. 03 03 2018 10:15:35.616:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.initial-state.ts(6,31): error TS2307: Cannot find module 'app/shared/states/pizzas/pizzas.reducer'. 03 03 2018 10:15:35.617:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.reducer.ts(4,32): error TS2307: Cannot find module 'app/shared/states/pizzas/pizzas.actions'. 03 03 2018 10:15:35.617:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.reducer.ts(5,36): error TS2307: Cannot find module 'app/shared/states/pizzas/pizzas.initial-state'. 03 03 2018 10:15:35.617:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.reducer.ts(9,8): error TS2307: Cannot find module 'app/shared/states/pizzas/pizzas.interfaces'. 03 03 2018 10:15:35.617:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.selectors.ts(6,8): error TS2307: Cannot find module 'app/shared/states/pizzas/pizzas.reducer'. 03 03 2018 10:15:35.617:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.selectors.ts(38,28): error TS2339: Property 'selected' does not exist on type '{}'. 03 03 2018 10:15:35.617:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.service.mock.ts(4,35): error TS2307: Cannot find module 'app/shared/states/pizzas/pizzas.initial-state'. 03 03 2018 10:15:35.617:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.service.mock.ts(8,8): error TS2307: Cannot find module 'app/shared/states/pizzas/pizzas.interfaces'. 03 03 2018 10:15:35.617:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.service.mock.ts(9,31): error TS2307: Cannot find module 'app/shared/states/pizzas/pizzas.service'. 03 03 2018 10:15:35.617:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.service.ts(5,35): error TS2307: Cannot find module 'app/shared/states/pizzas/pizzas.initial-state'. 03 03 2018 10:15:35.618:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.service.ts(9,8): error TS2307: Cannot find module 'app/shared/states/pizzas/pizzas.interfaces'. 03 03 2018 10:15:35.618:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/pizzas/pizzas.service.ts(10,29): error TS2307: Cannot find module 'environments/environment'. 03 03 2018 10:15:35.618:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/root.reducer.ts(5,24): error TS2307: Cannot find module 'app/shared/interfaces/store.interface'. 03 03 2018 10:15:35.618:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/root.reducer.ts(6,27): error TS2307: Cannot find module 'app/shared/states/ui/ui.reducer'. 03 03 2018 10:15:35.618:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/root.reducer.ts(7,29): error TS2307: Cannot find module 'environments/environment'. 03 03 2018 10:15:35.618:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/ui/ui.initial-state.ts(1,21): error TS2307: Cannot find module 'app/shared/states/ui/ui.interface'. 03 03 2018 10:15:35.618:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/ui/ui.reducer.ts(3,28): error TS2307: Cannot find module 'app/shared/states/ui/ui.actions'. 03 03 2018 10:15:35.619:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/ui/ui.reducer.ts(4,32): error TS2307: Cannot find module 'app/shared/states/ui/ui.initial-state'. 03 03 2018 10:15:35.619:ERROR [compiler.karma-typescript]: frontend/src/app/shared/states/ui/ui.reducer.ts(5,21): error TS2307: Cannot find module 'app/shared/states/ui/ui.interface'. 03 03 2018 10:15:35.619:ERROR [compiler.karma-typescript]: node_modules/@nestjs/core/injector/modules-container.d.ts(2,47): error TS2689: Cannot extend an interface 'Map'. Did you mean 'implements'? 03 03 2018 10:15:35.620:ERROR [compiler.karma-typescript]: node_modules/@types/jasmine/index.d.ts(14,18): error TS2300: Duplicate identifier 'describe'. 03 03 2018 10:15:35.620:ERROR [compiler.karma-typescript]: node_modules/@types/jasmine/index.d.ts(16,18): error TS2300: Duplicate identifier 'xdescribe'. 03 03 2018 10:15:35.620:ERROR [compiler.karma-typescript]: node_modules/@types/jasmine/index.d.ts(25,18): error TS2300: Duplicate identifier 'it'. 03 03 2018 10:15:35.621:ERROR [compiler.karma-typescript]: node_modules/@types/jasmine/index.d.ts(35,18): error TS2300: Duplicate identifier 'xit'. 03 03 2018 10:15:35.621:ERROR [compiler.karma-typescript]: node_modules/@types/jasminewd2/index.d.ts(9,18): error TS2300: Duplicate identifier 'it'. 03 03 2018 10:15:35.621:ERROR [compiler.karma-typescript]: node_modules/@types/jasminewd2/index.d.ts(11,18): error TS2300: Duplicate identifier 'xit'. 03 03 2018 10:15:35.621:ERROR [compiler.karma-typescript]: node_modules/@types/mocha/index.d.ts(36,13): error TS2300: Duplicate identifier 'describe'. 03 03 2018 10:15:35.621:ERROR [compiler.karma-typescript]: node_modules/@types/mocha/index.d.ts(37,13): error TS2300: Duplicate identifier 'xdescribe'. 03 03 2018 10:15:35.621:ERROR [compiler.karma-typescript]: node_modules/@types/mocha/index.d.ts(42,13): error TS2300: Duplicate identifier 'it'. 03 03 2018 10:15:35.622:ERROR [compiler.karma-typescript]: node_modules/@types/mocha/index.d.ts(43,13): error TS2300: Duplicate identifier 'xit'. 03 03 2018 10:15:35.622:ERROR [compiler.karma-typescript]: node_modules/rxjs/Observable.d.ts(58,60): error TS2693: 'Promise' only refers to a type, but is being used as a value here. 03 03 2018 10:15:35.622:ERROR [compiler.karma-typescript]: node_modules/rxjs/Observable.d.ts(73,59): error TS2693: 'Promise' only refers to a type, but is being used as a value here.

Stacktrace after node_modules:

03 03 2018 10:15:36.113:INFO [compiler.karma-typescript]: Compiled 45 files in 10525 ms. 03 03 2018 10:15:36.158:INFO [karma]: Karma v2.0.0 server started at http://0.0.0.0:9876/ 03 03 2018 10:15:36.161:INFO [launcher]: Launching browser Chromium with unlimited concurrency 03 03 2018 10:15:36.180:INFO [launcher]: Starting browser Chromium 03 03 2018 10:15:39.834:INFO [Chromium 64.0.3282 (Ubuntu 0.0.0)]: Connected on socket c-FZCqaP5s85FCw9AAAA with id 42811877 Chromium 64.0.3282 (Ubuntu 0.0.0) ERROR { "message": "You need to include some adapter that implements __karma__.start method!", "str": "You need to include some adapter that implements __karma__.start method!" } Unhandled rejection Error: COMPILATION ERROR at maybeWrapAsError (/home/maxime/Documents/nest-angular-starter/node_modules/bluebird/js/release/util.js:61:12) at /home/maxime/Documents/nest-angular-starter/node_modules/bluebird/js/release/nodeback.js:38:50 at nextPreprocessor (/home/maxime/Documents/nest-angular-starter/node_modules/karma/lib/preprocessor.js:26:14) at Object.callback (/home/maxime/Documents/nest-angular-starter/node_modules/karma-typescript/src/karma/preprocessor.ts:32:36) at /home/maxime/Documents/nest-angular-starter/node_modules/karma-typescript/src/compiler/compiler.ts:96:20 at Array.forEach (native) at Compiler.onProgramCompiled (/home/maxime/Documents/nest-angular-starter/node_modules/karma-typescript/src/compiler/compiler.ts:85:24) at Compiler.compileProject (/home/maxime/Documents/nest-angular-starter/node_modules/karma-typescript/src/compiler/compiler.ts:70:14) at Compiler. (/home/maxime/Documents/nest-angular-starter/node_modules/karma-typescript/src/compiler/compiler.ts:36:22) at invokeFunc (/home/maxime/Documents/nest-angular-starter/node_modules/lodash/lodash.js:10325:23) at trailingEdge (/home/maxime/Documents/nest-angular-starter/node_modules/lodash/lodash.js:10374:18) at Timeout.timerExpired [as _onTimeout] (/home/maxime/Documents/nest-angular-starter/node_modules/lodash/lodash.js:10362:18) at ontimeout (timers.js:469:11) at tryOnTimeout (timers.js:304:5) at Timer.listOnTimeout (timers.js:264:5) 03 03 2018 10:15:40.845:INFO [bundler.karma-typescript]: Bundled imports for 4 file(s) in 4198 ms. Unhandled rejection Error: COMPILATION ERROR at maybeWrapAsError (/home/maxime/Documents/nest-angular-starter/node_modules/bluebird/js/release/util.js:61:12) at /home/maxime/Documents/nest-angular-starter/node_modules/bluebird/js/release/nodeback.js:38:50 at nextPreprocessor (/home/maxime/Documents/nest-angular-starter/node_modules/karma/lib/preprocessor.js:26:14) at Object.callback (/home/maxime/Documents/nest-angular-starter/node_modules/karma-typescript/src/karma/preprocessor.ts:32:36) at /home/maxime/Documents/nest-angular-starter/node_modules/karma-typescript/src/compiler/compiler.ts:96:20 at Array.forEach (native) at Compiler.onProgramCompiled (/home/maxime/Documents/nest-angular-starter/node_modules/karma-typescript/src/compiler/compiler.ts:85:24) at Compiler.compileProject (/home/maxime/Documents/nest-angular-starter/node_modules/karma-typescript/src/compiler/compiler.ts:70:14) at Compiler. (/home/maxime/Documents/nest-angular-starter/node_modules/karma-typescript/src/compiler/compiler.ts:36:22) at invokeFunc (/home/maxime/Documents/nest-angular-starter/node_modules/lodash/lodash.js:10325:23) at trailingEdge (/home/maxime/Documents/nest-angular-starter/node_modules/lodash/lodash.js:10374:18) at Timeout.timerExpired [as _onTimeout] (/home/maxime/Documents/nest-angular-starter/node_modules/lodash/lodash.js:10362:18) at ontimeout (timers.js:469:11) at tryOnTimeout (timers.js:304:5) at Timer.listOnTimeout (timers.js:264:5)

In case it helps, I've pushed my current work as WIP so you can give a try on your own if you want.

The commit can be seen here: https://github.com/maxime1992/nest-angular-starter/commit/1c4f82b444a724dc716bdecbb1ae48d6ac9b00bc

If you want to try it locally:

git clone https://github.com/maxime1992/nest-angular-starter.git
git checkout feat/init-repo
yarn
yarn run back:test

(or same with npm if you prefer :+1:)

erikbarke commented 6 years ago

This is how far I got:

module.exports = function(config) {
  config.set({
    basePath: '.',
    frameworks: ['jasmine', 'karma-typescript'],
    files: ['./src/**/*.ts'],
    preprocessors: {
      './src/**/*.ts': 'karma-typescript',
    },
    reporters: ['progress', 'karma-typescript'],
    browsers: ['Chrome'],
    karmaTypescriptConfig: {
      bundlerOptions: {
        resolve: {
          alias: {
            'util': 'node_modules/util/util.js'
          }
        }
      },
      compilerOptions: {
        lib: ['ES2015', 'DOM'],
        types : ['jasmine']
      }
    }
  });
};

This compiles without errors, but when running the tests the package express crashes when trying to do Object.create(http.IncomingMessage.prototype) because the prototype is undefined on http.IncomingMessage.

Since the tests are running in a browser (not in Node.js) the karma-typescript bundler loads a browser shim for the module http called stream-http and it seems that shim isn't fully compatible with it's Node.js counterpart yet 🤔

This breaks in browserify bundles too, this isn't a karma-typescript bug 😞

maxime1992 commented 6 years ago

Thanks a lot for your investigation :pray:

So I'm kinda stuck here, I guess I'll have to open few issues around :sweat_smile: If you found anything at some point just let me know

Anyway thanks a lot for your help on that already, cheers

maxime1992 commented 6 years ago

Since the tests are running in a browser (not in Node.js) the karma-typescript bundler loads a browser shim for the module http called stream-http and it seems that shim isn't fully compatible with it's Node.js counterpart yet thinking

I figured out yesterday that I'm absolutely not supposed to use karma for E2E testing... :sweat_smile: how embarrassing uhm uhm... :yum:

Anyway you helped me a lot to figure things out @erikbarke, thanks