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

Refactor production tests #8073

Merged
merged 1 commit into from Apr 17, 2020
Merged

Conversation

fisker
Copy link
Sponsor Member

@fisker fisker commented Apr 17, 2020

  • Auto install production packge before running tests in jest.config.js(can't figure a better way).
  • Refactor STANDALONE tests to the same way as production-test

In this way, we can add more seperate tests on bundles.

To make this test runs on bundles:

Without this change, we have to modify scripts/test-dist.js add more if/else

Now, We only need

  • cross-env PRETTIER_FALLBACK_RESOLVE=1 jest tests_integration/__tests__/{config-resolution,config-invalid,plugin-resolution}.js to run tests on source
  • cross-env NODE_ENV=production PRETTIER_FALLBACK_RESOLVE=1 jest tests_integration/__tests__/{config-resolution,config-invalid,plugin-resolution}.js to run tests on bundles

Also easier to run production tests with pattern npx cross-env NODE_ENV=production jest tests/big-int


I’ve read the contributing guidelines.

Try the playground for this PR

@fisker fisker requested a review from thorn0 April 17, 2020 16:12

- name: Run Tests (Linux and Windows)
if: matrix.os != 'macos-latest'
run: yarn test:dist --maxWorkers=2

standalone:
Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try to merge production-test and standalone-test later.

const ENABLE_CODE_COVERAGE = !!process.env.ENABLE_CODE_COVERAGE;
if (process.env.NODE_ENV === "production") {
Copy link
Sponsor Member Author

@fisker fisker Apr 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think use NODE_ENV environment is a good idea, maybe change to another variable later

@thorn0
Copy link
Member

thorn0 commented Apr 17, 2020

To make this test runs on bundles:
Without this change, we have to modify scripts/test-dist.js add more if/else

I don't understand this part. Why do we have to modify that file to add that test? If anything, I thought we would modify tests_integration/runPrettier.js to mock process.env and restore it after the test. Adding try ... finally around the runPrettier call could work too. Aren't you overthinking this a bit?

Copy link
Member

@thorn0 thorn0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I'm good with this PR.

@fisker
Copy link
Sponsor Member Author

fisker commented Apr 17, 2020

To make this test runs on bundles:
Without this change, we have to modify scripts/test-dist.js add more if/else

I don't understand this part. Why do we have to modify that file to add that test? If anything, I thought we would modify tests_integration/runPrettier.js to mock process.env and restore it after the test. Adding try ... finally around the runPrettier call could work too. Aren't you overthinking this a bit?

How to run full config-resolution.js and plugin-resolution.js twice?

@fisker
Copy link
Sponsor Member Author

fisker commented Apr 17, 2020

Anyway, I think better in this way.

run production tests with pattern npx cross-env NODE_ENV=production jest tests/big-int

This is much easier.

@thorn0
Copy link
Member

thorn0 commented Apr 17, 2020

How to run full config-resolution.js and plugin-resolution.js twice?

By wrapping them in a loop. But I think just one test for that fallback would be enough.

@thorn0
Copy link
Member

thorn0 commented Apr 17, 2020

After a second thought, I think it's okay to test it in a separate step of the GitHub Actions workflow. It just feels unusual to me.

@fisker fisker merged commit 118b79f into prettier:master Apr 17, 2020
@fisker fisker deleted the production-tests-refactor branch April 17, 2020 17:33
thorn0 pushed a commit that referenced this pull request Apr 19, 2020
# Conflicts:
#	scripts/test-dist.js
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants