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

fix(testing): don't run tests against non-test files #3237

Merged
merged 4 commits into from
Feb 15, 2022

Conversation

rwaskiewicz
Copy link
Member

@rwaskiewicz rwaskiewicz commented Feb 10, 2022

Pull request checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
  • Build (npm run build) was run locally and any changes were pushed
  • Unit tests (npm test) were run locally and passed
  • E2E Tests (npm run test.karma.prod) were run locally and passed
  • Prettier (npm run prettier) was run locally and passed

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

There are two issues that this PR solves (in 2 commits):

  1. files that end with (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
  2. files that end in .j or .t will be picked up by the test runner

GitHub 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 and
perform RegExp.test()-based assertions.

remove a single '?' from the testRegex field used that was making the
period preceding (test|spec|e2e) optional

Commit 2: update stencil's default testRegex to not capture .j and .t files

Does this introduce a breaking change?

  • Yes
  • No

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 vs main

  • npm t
  • npm run test.karma.prod
  • npm run test.end-to-end

Finally, I npm packed the built artifact to test this on a Stencil project:

  1. npm init stencil component my-cmp to generate a new Stencil project
  2. cd my-cmp && npm i to get dependencies installed
  3. npm t to get a baseline & verify that everything passed
  4. npm run generate to generate a new component, my-test, accept default test files when prompted
  5. npm run generate to generate a new component, my-e2e, accept default test files when prompted
  6. npm run generate to generate a new component, my-spec, accept default test files when prompted
  7. npm t to see that there are now failing tests for each of the new file
    Screen Shot 2022-02-10 at 11 39 50 AM
    s
  8. npm i PATH_TO_TARBALL
  9. npm t to see all tests pass and the created component files aren't pick up anymore

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), we
instead extract the testRegex field out of the stencil `TestConfig` and
perform `RegExp.test()`-based assertions.

remove a single '?' from the `testRegex` field used that was making the
period preceding (test|spec|e2e) optional
update stencil's default `testRegex` to not capture `.j` and `.t` files
@rwaskiewicz rwaskiewicz marked this pull request as ready for review February 10, 2022 17:41
@rwaskiewicz rwaskiewicz requested a review from a team February 10, 2022 17:41
@rwaskiewicz rwaskiewicz merged commit c6fda39 into main Feb 15, 2022
@rwaskiewicz rwaskiewicz deleted the stencil362/test-non-test-files branch February 15, 2022 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants