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
Adapter for NextJS + NextJS example #60
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think your PR is great so far. Thank you very much. Let's extract your customize implementation to a function and use rollup to bundle it.
It should have typing support so we might need to modify our building process a little bit.
examples/nextjs/jest.config.js
Outdated
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async | ||
module.exports = async () => { | ||
const config = await createJestConfig(customJestConfig)(); | ||
if (typeof config === 'object') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment in which case config is not an object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thanhsonng We do not need the logic if (typeof config === 'object')
anymore, don't we?
Just add a reference on default Next's Jest Config here {
setupFilesAfterEnv: [ '<rootDir>/jest.setup.js' ],
moduleNameMapper: {
'^.+\\.module\\.(css|sass|scss)$': '/my_folder/node_modules/next/dist/build/jest/object-proxy.js',
'^.+\\.(css|sass|scss)$': '/my_folder/node_modules/next/dist/build/jest/__mocks__/styleMock.js',
'^.+\\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$': '/my_folder/node_modules/next/dist/build/jest/__mocks__/fileMock.js',
'^@/components/(.*)$': '<rootDir>/components/$1',
'^@/pages/(.*)$': '<rootDir>/pages/$1'
},
testEnvironment: 'jest-environment-jsdom',
testPathIgnorePatterns: [ '/node_modules/', '/.next/' ],
transform: {
'^.+\\.(js|jsx|ts|tsx|mjs)$': [
'/my_folder/node_modules/next/dist/build/swc/jest-transformer.js',
[Object]
]
},
transformIgnorePatterns: [ '/node_modules/', '^.+\\.module\\.(css|sass|scss)$' ],
watchPathIgnorePatterns: [ '/.next/' ]
}
{
setupFilesAfterEnv: [ '<rootDir>/jest.setup.js' ],
moduleNameMapper: {
'^.+\\.module\\.(css|sass|scss)$': '/my_folder/node_modules/next/dist/build/jest/object-proxy.js',
'^.+\\.(css|sass|scss)$': '/my_folder/node_modules/next/dist/build/jest/__mocks__/styleMock.js',
'^.+\\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$': '/my_folder/node_modules/next/dist/build/jest/__mocks__/fileMock.js',
'^@/components/(.*)$': '<rootDir>/components/$1',
'^@/pages/(.*)$': '<rootDir>/pages/$1'
},
testEnvironment: 'jest-environment-jsdom',
testPathIgnorePatterns: [ '/node_modules/', '/.next/' ],
transform: {
'^.+\\.(js|jsx|ts|tsx|mjs)$': [
'/my_folder/node_modules/next/dist/build/swc/jest-transformer.js',
[Object]
]
},
transformIgnorePatterns: [ '/node_modules/', '^.+\\.module\\.(css|sass|scss)$' ],
watchPathIgnorePatterns: [ '/.next/' ]
} |
Also, we are removing |
✅ Deploy Preview for jest-preview-library canceled.
|
@thanhsonng Thank you for your work. I think the PR is almost ready to merge. I leave some comments, most of them related to documentation. Please take a look. |
Co-authored-by: Hung Viet Nguyen <nguyenviethunghl00@gmail.com>
@nvh95 I will open a new PR for that. This PR should be closed ASAP 😝 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. I think I need a little bit of time to think about the name configureNextJest
.
Actually, at first I think it's fine to not place preview
in the API name. But when reading
module.exports = configureNextJest(createJestConfig(customJestConfig));
makes me confused. So I'm thinking of configureNextJestPreview
. What do you think @thanhsonng?
I actually think the word |
I see your point. However, the current implementation of Naming is hard, since it's one of two hard things in CS. We already have
Absolutely agree. |
Let's ship it in |
@all-contributors please add @thanhsonng for code and example. |
I've put up a pull request to add @thanhsonng! 🎉 |
Welcome to contributors 🎉! |
Issue: #33
Features
maybecurrently namednextJestPreview
enableJestPreview
Chores
jest-preview
work with Next.js (using Next.js compiler written in Rust)jest-preview
work with Next.js (using Babel)<Image />
work (Normally, Image is lazy and will only load when entering viewport. When run byjest-preview
, it never loads)Misc.
jest-preview