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

First class support for CRA #102

Merged
merged 26 commits into from May 23, 2022
Merged

First class support for CRA #102

merged 26 commits into from May 23, 2022

Conversation

nvh95
Copy link
Owner

@nvh95 nvh95 commented May 3, 2022

Features

  • First class support for CRA
    • Use node scripts/test.js instead of react-scripts test (example)
      • Use require('react-scripts/config/env'); instead of require('../config/env');
    • Use jest.config.js instead of jest object in package.json (example)
    • Add CLI to generate jest.config.js (jest-preview config-cra)
    • Add CLI to generate scripts/test.js (jest-preview config-cra)
    • Make jest-preview receives argument (use commander)

Chores

  • Update docs
  • Add blog post

@netlify
Copy link

netlify bot commented May 3, 2022

Deploy Preview for jest-preview-library ready!

Name Link
🔨 Latest commit 45ff575
🔍 Latest deploy log https://app.netlify.com/sites/jest-preview-library/deploys/628b2ca3906ee30008f2a2c0
😎 Deploy Preview https://deploy-preview-102--jest-preview-library.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@nvh95 nvh95 self-assigned this May 3, 2022
@nvh95 nvh95 linked an issue May 15, 2022 that may be closed by this pull request
@nvh95 nvh95 marked this pull request as ready for review May 18, 2022 16:14
cli/configCra.js Outdated Show resolved Hide resolved
@nvh95
Copy link
Owner Author

nvh95 commented May 21, 2022

@nvh95 nvh95 mentioned this pull request May 21, 2022
6 tasks
Copy link
Collaborator

@thanhsonng thanhsonng left a comment

Choose a reason for hiding this comment

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

@nvh95 I just want to make sure the CLI still works even if the app is already ejected

'^(?!.*\\.(js|jsx|mjs|cjs|ts|tsx|css|json)$)':
'jest-preview/transforms/fileCRA',
};
jestConfig.transformIgnorePatterns =
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we do a check first to ensure transformIgnorePatterns is an array and not nullish?

Copy link
Owner Author

Choose a reason for hiding this comment

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

No need since we are targeting un-ejected CRA apps. See other comments for more details

cli/configCra.js Outdated
(/** @type {string} */ pattern) =>
pattern !== '^.+\\.module\\.(css|sass|scss)$',
);
try {
Copy link
Collaborator

Choose a reason for hiding this comment

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

IMO a check (if statement) is better than a try-catch block

Copy link
Owner Author

Choose a reason for hiding this comment

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

I agree. However, actually, Since I explained that jest-preview config-cra target user with un-ejected app. So we don't even need to use try catch for the simplicity of source code.

We can check more strictly when developing jest-preview config

null,
true,
);
jestConfig.transform = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we add these keys to the existing transform instead of overwriting transform like this?

Copy link
Owner Author

Choose a reason for hiding this comment

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

No. This is intentional. We would like to remove '^.+\\.css$'. Without removing this, it causes some issues that makes Sass not work in #101

@nvh95
Copy link
Owner Author

nvh95 commented May 22, 2022

@thanhsonng

I just want to make sure the CLI still works even if the app is already ejected

The idea of jest-preview config-cra is to serve users without CRA being ejected. Once they ejected, they can follow the standard installation guide.

The reason is after ejected, they can customize everything they want, we cannot provide a CLI that work with both un-ejected and ejected CRA. For example:

  • We cannot create jest.config.js file from react-scripts/scripts/utils/createJestConfig.js (since react-scripts is uninstalled)
  • We couldn't replace require('../config/env'); by require('react-scripts/config/env'); (since react-scripts is uninstalled)

I think you want to support users who just ejected CRA without changing too much. But I don't think the common case, since after they ejected, they can do-whatever-they-want and we cannot anticipate that.

But I agree with you about a universal CLI, which tries to do its best to support users setup Jest Preview easier. it can be jest-preview config instead of jest-preview config-cra. I we can leave that work for the future.

For now jest-preview config-cra targets un-ejected CRA apps.

@nvh95
Copy link
Owner Author

nvh95 commented May 23, 2022

@thanhsonng I'm gonna merge this PR. Please let me know if I need to improve anything related to CRA support in the next PRs. Thanks

@nvh95 nvh95 merged commit 3b55071 into main May 23, 2022
@nvh95 nvh95 deleted the cra-support branch May 23, 2022 06:44
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.

Provide first-class support for CRA
3 participants