Skip to content
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

Jest: Neither --config nor --configuration works with v14 #1236

Closed
RTK opened this issue Jul 12, 2022 · 11 comments · Fixed by #1281
Closed

Jest: Neither --config nor --configuration works with v14 #1236

RTK opened this issue Jul 12, 2022 · 11 comments · Fixed by #1281
Labels

Comments

@RTK
Copy link

RTK commented Jul 12, 2022

Describe the Bug

After upgrading to version 14 I can no longer pass in the --configuration argument since it throws an error. The same goes for the --config option.

Also I have noticed, that when running ng test --help it prints for both --config and --configuration flag the abbreviation -c. Maybe this leads to this error.

Minimal Reproduction

Install latest version (v14), configure project and run ng test --configuration=test. It wil exit with an error (exit code 1) and print out the usage info Usage: ng [--config=<pathToConfigFile>] [TestPathPattern]. Also at the very end there is the error argv.config.match is not a function.

Expected Behavior

It should take either the angular configuration or the jest config and not throw an error.

Screenshots

$ ng test --configuration=test
Warning: 'no-cache' option has been declared with a 'no' prefix in the schema.Please file an issue with the author of this package.
Warning: 'noStackTrace' option has been declared with a 'no' prefix in the schema.Please file an issue with the author of this package.
Usage: ng [--config=<pathToConfigFile>] [TestPathPattern]

Options:
  -h, --help                        Show help                          [boolean]
      --version                     Show version number                [boolean]
      --all                         The opposite of `onlyChanged`. If
                                    `onlyChanged` is set by default, running
                                    jest with `--all` will force Jest to run all
                                    tests instead of running only tests related

[...]

                                    test re-run in watch mode. If the test path
                                    matches any of the patterns, it will be
                                    skipped.                             [array]
      --watchman                    Whether to use watchman for file crawling.
                                    Disable using --no-watchman.       [boolean]

Documentation: https://jestjs.io/

argv.config.match is not a function

Environment


Libs
- @angular/core version: 14.0.5
- @angular-devkit/build-angular version: 14.0.5
- @angular-builders/jest version: 14.0.0
- Jest: 28.1.2

For Tooling issues:
- Node version: v16.14.2
- Platform: Mac
@RTK
Copy link
Author

RTK commented Jul 12, 2022

I debugged a bit and found out, that the --config argument gets passed twice to jest:

index.ts in function runJest(options, context) -> buildArgv

[
  '--tsConfig=./src/tsconfig.spec.json',
  '--no-cache',
  '--config=test',
  '--globalMocks=getComputedStyle',
  '--globalMocks=doctype',
  '--globalMocks=styleTransform',
  '--globalMocks=matchMedia',
  '--notifyMode=failure-change',
  '--prettierPath=prettier',
  '--config',
  '{"preset":"jest-preset-angular",[...]}'

--configuration=test gets transformed into --config=test but the builder hardcodes a --config=[builder specific configurations] as well -> argv.push('--config', JSON.stringify(configuration));

Also I realized, that no options from my test Angular configuration gets added to the argv.

@just-jeb
Copy link
Owner

Do I get it right that with Angular v13 it works as expected and with Angular 14 not?

@just-jeb just-jeb added builders:jest bug Something isn't working labels Jul 12, 2022
@RTK
Copy link
Author

RTK commented Jul 13, 2022

Correct. I just tested it with @angular-builders/jest v13.0.3 and Angular 14.0.0 and it shows the same error, so it seems to be a side effect of Angular changes.

@just-jeb
Copy link
Owner

just-jeb commented Jul 14, 2022

Could you please provide a repo with minimal reproduction?

Also, a workaround to try in meanwhile - use ng run instead of ng test.
In your case it would be something like ng run your-project:test:test

@RTK
Copy link
Author

RTK commented Jul 18, 2022

https://github.com/RTK/angular-builders-jest-example

Setup via "npm install" and then run "ng test --configuration=test", then you should get the error I described. The workaround works for now, thanks!

@just-jeb
Copy link
Owner

Is -c alias working for v13?

@RTK
Copy link
Author

RTK commented Jul 18, 2022

Unfortunately no since both angular configuration AND jest configuration have the same -c alias

sinedied added a commit to ngx-rocket/generator-ngx-rocket that referenced this issue Aug 24, 2022
sinedied added a commit to ngx-rocket/generator-ngx-rocket that referenced this issue Aug 25, 2022
@HamsinD
Copy link

HamsinD commented Sep 22, 2022

I have same problem after upgrade to Angular 14,
when I run ng e2e -c xxx

`

Usage: ng.js [--config=<pathToConfigFile>] [TestPathPattern]                    
                                                                                
Options:                                                                        
  -h, --help                        Show help                          [boolean]
      --version                     Show version number                [boolean]
      --all                         The opposite of `onlyChanged`. If           
                                    `onlyChanged` is set by default, running    
                                    jest with `--all` will force Jest to run all
                                    tests instead of running only tests related 
                                    to changed files.                  [boolean]
      --automock                    Automock all files by default.     [boolean]
  -b, --bail                        Exit the test suite immediately after `n`
                                    number of failing tests.           [boolean]
      --cache                       Whether to use the transform cache. Disable
                                    the cache using --no-cache.        [boolean]
      --cacheDirectory              The directory where Jest should store its
                                    cached  dependency information.     [string]
      --changedFilesWithAncestor    Runs tests related to the current changes
                                    and the changes made in the last commit.
                                    Behaves similarly to `--onlyChanged`.
                                                                       [boolean]
      --changedSince                Runs tests related to the changes since the
                                    provided branch. If the current branch has
                                    diverged from the given branch, then only
                                    changes made locally will be tested. Behaves
                                    similarly to `--onlyChanged`.       [string]
      --ci                          Whether to run Jest in continuous
                                    integration (CI) mode. This option is on by
                                    default in most popular CI environments. It
                                    will prevent snapshots from being written
                                    unless explicitly requested.       [boolean]
      --clearCache                  Clears the configured Jest cache directory
                                    and then exits. Default directory can be
                                    found by calling jest --showConfig [boolean]
      --clearMocks                  Automatically clear mock calls, instances,
                                    contexts and results before every test.
                                    Equivalent to calling jest.clearAllMocks()
                                    before each test.                  [boolean]
      --collectCoverage             Alias for --coverage.              [boolean]
      --collectCoverageFrom         A glob pattern relative to <rootDir>
                                    matching the files that coverage info needs
                                    to be collected from.               [string]
      --collectCoverageOnlyFrom     Explicit list of paths coverage will be
                                    restricted to.                       [array]
      --color                       Forces test results output color
                                    highlighting (even if stdout is not a TTY).
                                    Set to false if you would like to have no
                                    colors.                            [boolean]
      --colors                      Alias for `--color`.               [boolean]
  -c, --config                      The path to a jest config file specifying
                                    how to find and execute tests. If no rootDir
                                    is set in the config, the directory
                                    containing the config file is assumed to be
                                    the rootDir for the project.This can also be
                                    a JSON encoded value which Jest will use as
                                    configuration.                      [string]
      --coverage                    Indicates that test coverage information
                                    should be collected and reported in the
                                    output.                            [boolean]
......
......
......
      --watchPathIgnorePatterns     An array of regexp pattern strings that are
                                    matched against all paths before trigger
                                    test re-run in watch mode. If the test path
                                    matches any of the patterns, it will be
                                    skipped.                             [array]
      --watchman                    Whether to use watchman for file crawling.
                                    Disable using --no-watchman.       [boolean]

Documentation: https://jestjs.io/

argv.config.match is not a function
`

and I run ng e2e --help, follow output is significantly different from angular 13.

image

run ng e2e --help in angular 13.

image

my angular.json configuration as follows.

image

@just-jeb
Copy link
Owner

Thanks for the report guys and sorry it took so long to deal with it.
The issue is with the way Angular CLI treats aliases - since c is already reserved for configuration it cannot be used by a builder, yet Jest Builder defines it as an alias for config and it fucks everything up.
I'm removing the alias, let's see if it works now.

@just-jeb
Copy link
Owner

Should be fixed in 14.0.2-beta.1, please confirm.

@RTK
Copy link
Author

RTK commented Oct 27, 2022

Now it works just fine! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants