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

Docs: Correct JavaScript React Component File Extension to .jsx in '01-vitest.mdx' #61087

Merged
merged 2 commits into from
Jan 25, 2024

Conversation

sogoagain
Copy link
Contributor

@sogoagain sogoagain commented Jan 24, 2024

Hello,

This PR resolves a file extension inconsistency in the 'Setting up Vitest with Next.js' section of the Next.js documentation (01-vitest.mdx).

When using next.js with JavaScript, following the documentation(01-vitest.mdx) leads to issues during testing because of the jsx extension.

This PR corrects an example code that wrongly uses a '.js' extension for a React component, which is against Vitest's requirement for '.jsx' extensions.

Thank you.

@sogoagain sogoagain requested review from a team as code owners January 24, 2024 14:18
@sogoagain sogoagain requested review from jh3y and lydiahallie and removed request for a team January 24, 2024 14:18
@sogoagain sogoagain changed the title Docs: Update JavaScript React Component File Extension to .jsx in '01-vitest.mdx' Docs: Correct JavaScript React Component File Extension to .jsx in '01-vitest.mdx' Jan 24, 2024
@samcx
Copy link
Member

samcx commented Jan 24, 2024

@sogoagain The config file isn't a React component → https://vitest.dev/config/#configuration (all the examples are using .ts, not .tsx).

@sogoagain
Copy link
Contributor Author

@samcx Oops, sorry. I should have edited the app/page.js file, but I mistakenly altered the wrong one. I've corrected the PR now. My apologies for the confusion. Please review again.
Thank you.

@samcx
Copy link
Member

samcx commented Jan 24, 2024

@sogoagain Thank you for the update!

Although I would agree using .jsx is more semantic, I believe all our JavaScript examples are simply using .js for the React components, which is fine for now!

@sogoagain
Copy link
Contributor Author

sogoagain commented Jan 24, 2024

@samcx Yes, I agree it's fine to use the .js extension for React components.

But the problem is, when I try to configure the vitest environment using next.js in Javascript, if I follow the documentation, I get an error when running the test due to the .js extension. This is a fix for that.

In fact, in the Typescript example code, it is written as app.page.tsx.

@samcx
Copy link
Member

samcx commented Jan 24, 2024

@sogoagain Can you share the error as well and your Vite versions? This may be solely a Vite thing, which if true, it may be best to just switch this to .jsx.

@sogoagain
Copy link
Contributor Author

@samcx

Sure. The error details are as follows.

 FAIL  __tests__/page.test.jsx [ __tests__/page.test.jsx ]
Error: Failed to parse source for import analysis because the content contains invalid JS syntax. If you are using JSX, make sure to name the file with the .jsx or .tsx extension.
 ❯ formatError node_modules/vite/dist/node/chunks/dep-9A4-l-43.js:63768:46
 ❯ TransformContext.error node_modules/vite/dist/node/chunks/dep-9A4-l-43.js:63762:19
 ❯ TransformContext.transform node_modules/vite/dist/node/chunks/dep-9A4-l-43.js:61979:22
 ❯ Object.transform node_modules/vite/dist/node/chunks/dep-9A4-l-43.js:64063:30
 ❯ loadAndTransform node_modules/vite/dist/node/chunks/dep-9A4-l-43.js:49741:29

The version of vitest is '1.2.1'.

Thank you.

@ijjk
Copy link
Member

ijjk commented Jan 25, 2024

Allow CI Workflow Run

  • approve CI run for commit: 02f1d24

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

Copy link
Member

@samcx samcx left a comment

Choose a reason for hiding this comment

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

:lgtm:

@samcx samcx merged commit 0cdc927 into vercel:canary Jan 25, 2024
29 checks passed
@github-actions github-actions bot added the locked label Feb 8, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants