Skip to content

ng test --environment works only once, but not on watch auto re-run #7305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lukemadera opened this issue Aug 8, 2017 · 9 comments
Closed
Assignees
Labels
P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful severity5: regression state: blocked type: bug/fix

Comments

@lukemadera
Copy link

lukemadera commented Aug 8, 2017

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Versions.

node --version
v6.10.1
npm --version
3.10.10
macOS (Sierra)

Repro steps.

  1. npm run test (which runs ng test --environment=local)
    This works fine (tests run successfully, using the specified environment).
  2. change a .spec test file
    This fails - it tries to re-run tests due to the change, but this time the environment is NOT used, instead the defaults environment.ts is used (which in our case leads to an error because it does not exist. Even if it did exist, it still is a bug as the proper environment is not being used).

The log given by the failure.

npm test

> [email protected] test /Users/lukemadera/Documents/code/presencelearning/pl-components-ng2
> ng test --environment=local

 10% building modules 1/1 modules 0 active08 08 2017 11:06:31.697:WARN [karma]: No captured browser, open http://localhost:9876/
08 08 2017 11:06:35.008:INFO [karma]: Karma v1.7.0 server started at http://0.0.0.0:9876/
08 08 2017 11:06:35.010:INFO [launcher]: Launching browser Chrome with unlimited concurrency
08 08 2017 11:06:35.015:INFO [launcher]: Starting browser Chrome
[../../../../../src recursive \.spec\.ts$] ./src \.spec\.ts$ 1.32 kB {main} [built]      
[../../../../../src/lib/pipes/commify.pipe.spec.ts] ./src/lib/pipes/commify.pipe.spec.ts 1.2 kB {main} [optional] [built]
[../../../../../src/lib/pl-button/index.spec.ts] ./src/lib/pl-button/index.spec.ts 135 bytes {main} [optional] [built]
[../../../../../src/lib/utilities/object.spec.ts] ./src/lib/utilities/object.spec.ts 1.74 kB {main} [optional] [built]
[../../../../../src/polyfills.ts] ./src/polyfills.ts 2.53 kB {polyfills} [built]
[../../../../../src/test.ts] ./src/test.ts 1.02 kB {main} [built]
[../../../../zone.js/dist/async-test.js] ./node_modules/zone.js/dist/async-test.js 3.23 kB {vendor} [built]
[../../../../zone.js/dist/fake-async-test.js] ./node_modules/zone.js/dist/fake-async-test.js 16.3 kB {vendor} [built]
[../../../../zone.js/dist/jasmine-patch.js] ./node_modules/zone.js/dist/jasmine-patch.js 6.36 kB {vendor} [built]
[../../../../zone.js/dist/long-stack-trace-zone.js] ./node_modules/zone.js/dist/long-stack-trace-zone.js 6.22 kB {vendor} [built]
   [0] multi ./src/polyfills.ts 28 bytes {polyfills} [built]
[../../../../zone.js/dist/proxy.js] ./node_modules/zone.js/dist/proxy.js 5.6 kB {vendor} [built]
[../../../../zone.js/dist/sync-test.js] ./node_modules/zone.js/dist/sync-test.js 1.41 kB {vendor} [built]
[../../../core/@angular/core/testing.es5.js] ./node_modules/@angular/core/@angular/core/testing.es5.js 39.7 kB {vendor} [built]
[../../../platform-browser-dynamic/@angular/platform-browser-dynamic/testing.es5.js] ./node_modules/@angular/platform-browser-dynamic/@angular/platform-browser-dynamic/testing.es5.js 3.61 kB {vendor} [built]
    + 930 hidden modules

WARNING in ./node_modules/jasmine/lib/jasmine.js
93:4-17 Critical dependency: the request of a dependency is an expression

WARNING in ./node_modules/jasmine/lib/jasmine.js
99:4-17 Critical dependency: the request of a dependency is an expression

WARNING in ./node_modules/jasmine/lib/jasmine.js
106:17-48 Critical dependency: the request of a dependency is an expression
08 08 2017 11:06:50.457:WARN [karma]: No captured browser, open http://localhost:9876/
08 08 2017 11:06:50.709:INFO [Chrome 56.0.2924 (Mac OS X 10.12.3)]: Connected on socket GYNA0Z9MVmEi5n5VAAAA with id 44599402
Chrome 56.0.2924 (Mac OS X 10.12.3): Executed 27 of 27 SUCCESS (0.495 secs / 0.461 secs)
[../../../../../src recursive \.spec\.ts$] ./src \.spec\.ts$ 1.32 kB {main} [built]
[../../../../../src/lib/pipes/commify.pipe.spec.ts] ./src/lib/pipes/commify.pipe.spec.ts 1.2 kB {main} [optional]
[../../../../../src/lib/pl-button/index.spec.ts] ./src/lib/pl-button/index.spec.ts 135 bytes {main} [optional]
[../../../../../src/lib/utilities/object.spec.ts] ./src/lib/utilities/object.spec.ts 1.74 kB {main} [optional]
[../../../../../src/polyfills.ts] ./src/polyfills.ts 2.53 kB {polyfills}
[../../../../../src/test.ts] ./src/test.ts 1.02 kB {main}
[../../../../zone.js/dist/async-test.js] ./node_modules/zone.js/dist/async-test.js 3.23 kB {vendor}
[../../../../zone.js/dist/fake-async-test.js] ./node_modules/zone.js/dist/fake-async-test.js 16.3 kB {vendor}
[../../../../zone.js/dist/jasmine-patch.js] ./node_modules/zone.js/dist/jasmine-patch.js 6.36 kB {vendor}
[../../../../zone.js/dist/long-stack-trace-zone.js] ./node_modules/zone.js/dist/long-stack-trace-zone.js 6.22 kB {vendor}
   [0] multi ./src/polyfills.ts 28 bytes {polyfills}
[../../../../zone.js/dist/proxy.js] ./node_modules/zone.js/dist/proxy.js 5.6 kB {vendor}
[../../../../zone.js/dist/sync-test.js] ./node_modules/zone.js/dist/sync-test.js 1.41 kB {vendor}
[../../../core/@angular/core/testing.es5.js] ./node_modules/@angular/core/@angular/core/testing.es5.js 39.7 kB {vendor}
[../../../platform-browser-dynamic/@angular/platform-browser-dynamic/testing.es5.js] ./node_modules/@angular/platform-browser-dynamic/@angular/platform-browser-dynamic/testing.es5.js 3.61 kB {vendor}
    + 930 hidden modules

WARNING in ./node_modules/jasmine/lib/jasmine.js
93:4-17 Critical dependency: the request of a dependency is an expression

WARNING in ./node_modules/jasmine/lib/jasmine.js
99:4-17 Critical dependency: the request of a dependency is an expression

WARNING in ./node_modules/jasmine/lib/jasmine.js
106:17-48 Critical dependency: the request of a dependency is an expression

ERROR in ./src/environments/environment.ts
Module build failed: Error: ENOENT: no such file or directory, open '/Users/lukemadera/Documents/code/presencelearning/pl-components-ng2/src/environments/environment.ts'
    at Error (native)
 @ ./src/lib/pl-browser/pl-browser.service.ts 18:20-61
 @ ./src/lib/pl-browser/index.ts
 @ ./src/lib/pl-browser/index.spec.ts
 @ ./src \.spec\.ts$
 @ ./src/test.ts

Desired functionality.

The environment.local.ts specified by the --environment flag is used ALL the time, not just on the first run. Which thus leads to a successful test watcher that will auto re-run tests on changes without breaking, as it does now.

Mention any other details that might be useful.

@Brocco Brocco added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent severity2: inconvenient labels Aug 18, 2017
@filipesilva filipesilva added P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful severity5: regression and removed P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent labels Aug 21, 2017
@vonboth
Copy link

vonboth commented Sep 14, 2017

+1
This also affects the 'serve' command:
ng serve --env=local works for the first time but on any file change 'watch' re-builds using the default environment.ts

@filipesilva
Copy link
Contributor

I'm sorry, but I cannot reproduce this problem. Can you upload a simple reproduction that shows this happening? I've seen a couple reports of similar things but was never able to reproduce it, so a clear simple repro would be very important.

@filipesilva filipesilva added the needs: repro steps We cannot reproduce the issue with the information given label Sep 25, 2017
@vonboth
Copy link

vonboth commented Sep 25, 2017

Thank you for looking after this.
I wanted to create an example for you and couldn't reproduce it myself.
I start with the command yarn start:some whereas in my package.json I have a task: "start:some": "ng serve --dev --env=some"
Everything worked as expected.

Until I changed the environment files.
E.g. environment.ts and environment.some.ts. I simply added some values to both.
When the watcher now builds the app again it uses the environment.ts file and not the environment.some.ts

But if I change some other TS-file the watcher builds the app with environment.some.ts as expected.
Knowing this I can live with it as I will randomly change the environment-File.
However it might help you to find a fix (if there is one)
Thank you!

@lukemadera
Copy link
Author

Thanks @filipesilva for the follow up. I created a work around where I always create the default dev environment file and that's been working well enough for now. I don't have time to create a new project right now for reproducing (our projects are private repos) but if you and others still can't let me know I can try to find some time to do so.

@filipesilva
Copy link
Contributor

@vonboth thank you so much!!! I can repro that!!! If I run ng serve --env=prod, I can see that:

  • editing src/environments/environment.prod.ts does not reflect the changes.
  • editing src/environments/environment.ts will stop using the prod env file and start using the dev one.

Now I know what's going wrong. Thank you!!!

@lukemadera we do require the original file to exist so that's probably why it breaks in your scenario.

@chadbr
Copy link

chadbr commented Nov 30, 2017

I would just document this one...

@darron1217
Copy link

darron1217 commented Jun 24, 2018

This bug made my project to send unneeded error reports (e.g. Sentry)

export function provideErrorHandler() {
  if (environment.production) {
    return new RavenErrorHandler();
  } else {
    return new ErrorHandler();
  }
}

Error reporting must work only at production, but it keep sends report even on local dev env...
What a mess...

Weird thing is this bug sends error report with url webpack-internal:///, which should be application's domain on production

@hansl
Copy link
Contributor

hansl commented Sep 28, 2018

We changed file replacements in many PRs on the new 6.x workspace. I'm going to close this as fixed as we didn't have any new issues filed regarding environments and file replacements.

If this happens in the latest version, please file a new issue with an updated reproduction.

@hansl hansl closed this as completed Sep 28, 2018
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful severity5: regression state: blocked type: bug/fix
Projects
None yet
Development

No branches or pull requests

7 participants