fix(testing): don't run tests against non-test files #3237
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull request checklist
Please check if your PR fulfills the following requirements:
npm run build
) was run locally and any changes were pushednpm test
) were run locally and passednpm run test.karma.prod
) were run locally and passednpm run prettier
) was run locally and passedPull request type
Please check the type of change your PR introduces:
What is the current behavior?
There are two issues that this PR solves (in 2 commits):
(test|spec|e2e).(js|ts|jsx|tsx)
(without a period preceding any combination of that string) are picked up by the test runner - e.g.my-test.tsx
will be picked up by the test runn.j
or.t
will be picked up by the test runnerGitHub Issue Number: #3221
What is the new behavior?
I split the two issues solved here into two commits, and will likely 'rebase and merge' them. Each commit has a fix:
Commit 1: this commit adds test infrastructure for files picked up by jest for
testing purposes. because there is no efficient way to get the
interaction with stencil+jest (or any libary+jest for that matter) under test, we
instead extract the testRegex field out of the stencil
TestConfig
andperform
RegExp.test()
-based assertions.remove a single '?' from the
testRegex
field used that was making theperiod preceding (test|spec|e2e) optional
Commit 2: update stencil's default
testRegex
to not capture.j
and.t
filesDoes this introduce a breaking change?
Testing
First and foremost, unit tests were added and passed.
Next, I built Stencil on this branch (
npm ci && npm run clean && npm run build
). I then ran each of our test suites to verify we didn't regress in the number of tests we run on this branch vsmain
npm t
npm run test.karma.prod
npm run test.end-to-end
Finally, I
npm pack
ed the built artifact to test this on a Stencil project:npm init stencil component my-cmp
to generate a new Stencil projectcd my-cmp && npm i
to get dependencies installednpm t
to get a baseline & verify that everything passednpm run generate
to generate a new component,my-test
, accept default test files when promptednpm run generate
to generate a new component,my-e2e
, accept default test files when promptednpm run generate
to generate a new component,my-spec
, accept default test files when promptednpm t
to see that there are now failing tests for each of the new files
npm i PATH_TO_TARBALL
npm t
to see all tests pass and the created component files aren't pick up anymore