2

Is there anyway to run ng test with a different test entry-point to the one specified in .angular-cli.json?

https://github.com/angular/angular-cli/issues/8579#issuecomment-346313383 provides a solution for increasing rebuild times by using lazy loaded chunks. But I fear that breaking up the tests into chunks might cause some tests to be missed.

Ideally i would have two files: test.ts, test.tmp.ts with test.ts containing:

const context = require.context('./', true, /\.spec\.ts$/);

while test.tmp.ts has:

const context = require.context('./app/some_module/', true, /\.spec\.ts$/);

This way, while developing, I can run something like ng test --entry-point=test.tmp.ts. Ideally test.tmp.ts will be git.ignored.

At the moment, its possible to call ng test --config=different_karma.conf.js to specify a different karma.conf.js, and within karma.conf.js you can change the reference to test.ts within that. However, this doesn't successfully run the tests, unless I change the apps.0.test entry point in angular-cli.json to test.tmp.ts.

The error I get is:

Uncaught SyntaxError: Unexpected string at src/test.tmp.ts:3

One solution is to create another app within .angular-cli.json which is a copy of the first with a different entry point, and call ng test -app but then you have to maintain two different app configs.

I can change test.ts directly each time, but its possible that might get committed.

Edit: https://stackoverflow.com/a/43669082/5464931 makes it seem like changing angular-cli.json was not neccessary, but I can't seem to get that to work.

Dulitha Ranatunga
  • 361
  • 1
  • 3
  • 6
  • Can you post your new test.tmp.ts content? – Mate Zabo Jan 02 '18 at 12:17
  • test.tmp.ts content is exactly the same as test.ts but with `const context = require.context('./', true, /\.spec\.ts$/);` changed to `const context = require.context('./app/some_module/', true, /\.spec\.ts$/);` But copied here anyway: [link](https://gist.github.com/DulithaRanatunga/35abda00536d7ad6b22c6579e3f34fe2) – Dulitha Ranatunga Jan 02 '18 at 22:20
  • Perhaps you might take a look at the ng test --main option. – user2367418 Nov 12 '18 at 19:00

1 Answers1

0

Try this:

Delete node_modules folder and run npm install

shrikant joshi
  • 494
  • 4
  • 12