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

Switch to ESM Jest config in docs #42144

Merged
merged 3 commits into from
Mar 28, 2023
Merged

Switch to ESM Jest config in docs #42144

merged 3 commits into from
Mar 28, 2023

Conversation

karlhorky
Copy link
Contributor

@karlhorky karlhorky commented Oct 29, 2022

Thanks again for Next.js 13! Finding a bunch of new ways to improve things 🙌

Just a quick PR to switch the Jest configuration file with next/jest to ESM to eliminate another instance of CommonJS.

ESM requires a .js extension on the import.

An alternative would be to switch to a TypeScript config file (jest.config.ts) which would (I am guessing) not require this file extension (but still allow switching to an ESM-style import syntax).

New jest.config.mjs file:

import nextJest from 'next/jest.js'

const createJestConfig = nextJest({
  // Provide the path to your Next.js app to load next.config.js and .env files in your test environment
  dir: './',
})

// Add any custom config to be passed to Jest
/** @type {import('jest').Config} */
const config = {
  // Add more setup options before each test is run
  // setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
  // if using TypeScript with a baseUrl set to the root directory then you need the below for alias' to work
  moduleDirectories: ['node_modules', '<rootDir>/'],
  testEnvironment: 'jest-environment-jsdom',
}

// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
export default createJestConfig(config)

Bug

  • Related issues linked using fixes #number
  • Integration tests added
  • Errors have a helpful link attached, see contributing.md

Feature

  • Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
  • Related issues linked using fixes #number
  • Integration tests added
  • Documentation added
  • Telemetry added. In case of a feature if it's used or not.
  • Errors have a helpful link attached, see contributing.md

Documentation / Examples

  • Make sure the linting passes by running pnpm build && pnpm lint
  • The "examples guidelines" are followed from our contributing doc

@ijjk ijjk force-pushed the canary branch 2 times, most recently from e078ebe to 6b863fe Compare December 2, 2022 05:49
@ijjk ijjk requested a review from jankaifer as a code owner March 2, 2023 23:39
@shuding shuding requested a review from a team as a code owner March 28, 2023 00:04
@kodiakhq kodiakhq bot merged commit 45e2c1e into vercel:canary Mar 28, 2023
@karlhorky karlhorky deleted the patch-1 branch March 28, 2023 15:41
@karlhorky
Copy link
Contributor Author

Thanks for the review and merge!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 28, 2023
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.

3 participants