You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(cli): ensure that argument order is correct for Jest
This ensures that CLI arguments are ordered correctly when we pass them
to Jest. In particular, we want to ensure that all flags of the type
`--maxWorkers=0` and the like are _before_ any flags which we don't know
about, like `my-spec-file.ts` (the latter being actually a match pattern
for which spec files to run).
In other words, if the user passes arguments like this:
```
--e2e foo.spec.ts
```
or
```
--e2e -- foo.spec.ts
```
We need to ensure we use something like
```
["--e2e", "foo.spec.ts"]
```
to generate the Jest config.
The wrinkle is that after we've parsed our known CLI arguments (in the
`cli` module) we do some addition modification of the arguments, based
on values set in the `Config`, in the `buildJestArgv` function. In
particular, we'll look to see if a `maxWorkers` flag is already passed
and, if not, we add one to the args before they're used to build the
Jest configuration.
Before this change that would result in an array like this being passed
to Jest:
```
["--e2e", "foo.spec.ts", "--maxWorkers=0"]
```
because we simply stuck the new `--maxWorkers` arg right on the end of
the already-combined array (combined because it's basically `knownArgs +
unknownArgs`). No good!
Why no good? Well, basically because Jest works best if the filename
matches are at the end. It's behavior if they're _not_ is,
unfortunately, inconsistent and it will work sometimes, but it (as far
as I have tested it!) _always_ works if the pattern is at the end.
So in order to provide a guarantee the pattern is at the end, we modify
a copy of `knownArgs` with flags like this and then produce a new,
combined array to pass to Jest when we're all done, so it looks like
this instead:
```
["--e2e", "--maxWorkers=0", "foo.spec.ts"]
```
Much better!
0 commit comments