Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli): ensure that argument order is correct for Jest (#3827)
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!
- Loading branch information
eb44060
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug
Details
Unable to run single e2e test after upgrading from v2.16.1 to v2.19.3
Command used:
npx stencil test --e2e dialog.e2e.ts
Work around
I am able to get the same functionality by adding
--
as an extra argCommand used:
npx stencil test --e2e -- dialog.e2e.ts
Screenshots
v2.16.1
v2.19.3
v2.19.3 with workaround