Angular-cli: Run ng test in prod mode `ng test --prod`

Created on 20 Jul 2018  路  4Comments  路  Source: angular/angular-cli

Bug Report or Feature Request (mark with an x)

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

Command (mark with an x)

- [ ] new
- [ ] build
- [ ] serve
- [x] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Versions


node: 8.9.4
npm: 6.1.0
ng: 6.0.4

Repro steps


ng test --prod

The log given by the failure


After I realized that I had to add a configuration section in angular.json under test architect node (for which was does not appear to be documented anywhere obvious), here is my config:

          "configurations": {
            "production": {
              "sourceMap": false,
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ]
            }
          }

When I try to add "aot": true, I get the following error:

Schema validation failed with the following errors:
  Data path "" should NOT have additional properties(aot).

Which defeats the purpose of trying to run unit tests in prod mode...

Desired functionality


Runs unit tests with a production version of a build (including AOT) and works

Mention any other details that might be useful


Late at night, I dream of being on a beach with the pleasing sound of lapping waves as I run ng test --prod

Most helpful comment

Heya, we don't support using AOT in unit tests. There's an open feature request at https://github.com/angular/angular-cli/issues/6650 for it.

I can say that last week I was actually on a beach and ran ng test a couple of times, never with --prod though. It was pleasant but have to say the glare on my (glossy) laptop monitor was annoying.

All 4 comments

Heya, we don't support using AOT in unit tests. There's an open feature request at https://github.com/angular/angular-cli/issues/6650 for it.

I can say that last week I was actually on a beach and ran ng test a couple of times, never with --prod though. It was pleasant but have to say the glare on my (glossy) laptop monitor was annoying.

It is misleading though, as the wiki states it's possible:
https://github.com/angular/angular-cli/wiki/test

That flag (--prod) does exist, but using a configuration, such as production, does not mean the same options are available as the browser build.

For instance, you can have a production configuration for tests that includes code coverage, which isn't available on the browser build.

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._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gotschmarcel picture gotschmarcel  路  3Comments

delasteve picture delasteve  路  3Comments

IngvarKofoed picture IngvarKofoed  路  3Comments

donaldallen picture donaldallen  路  3Comments

JanStureNielsen picture JanStureNielsen  路  3Comments