Testing with Next.js #28173
Replies: 14 comments 76 replies
-
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
WRT using a stand-alone node server to mock network requests, before I had
Cypress to mock requests/responses, I used Mountebank
<https://github.com/bbyars/mountebank> with decent success.
…On Mon, Sep 6, 2021 at 3:44 AM Eric Burel ***@***.***> wrote:
MSW seems a nice tool for unifying the way we mock frontend requests
across frameworks. But first, it's not very good for Graphql, because in
GraphQL you have only one endpoint that can receive many different request.
You would prefer mock-apollo-client
<https://www.npmjs.com/package/mock-apollo-client>, if you use Apollo.
Also for the backend calls there is still something to invent/discover
that would catch requests at the network level. I am pretty sure it's
doable in Node, a kind of proxy whose sole role is to intercept all
requests on localhost:XXX, mock some of them, let the other slip.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#28173 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAVL4BDA3VJNWD5GLWKVTT3UARWPFANCNFSM5CIB7XVA>
.
|
Beta Was this translation helpful? Give feedback.
-
First of all the docs look great, it would be great to add some use case specific code examples/youtube videos for stuff like:
|
Beta Was this translation helpful? Give feedback.
-
Hi team, I am trying to migrate from next.js 11 to 12 but I am facing issues in doing so. Can you please help me out?
// next.config.js
/* eslint @typescript-eslint/no-var-requires: "off" */
const withPlugins = require('next-compose-plugins');
const offline = require('next-offline');
const optimizedImages = require('next-optimized-images');
const CopyPlugin = require('copy-webpack-plugin');
const path = require('path');
const withImages = require('next-images');
const nextConfig = {
target: process.env.NODE_ENV !== 'production' ? 'server' : 'serverless',
i18n: {
locales: ['en', 'de', 'fr'],
defaultLocale: 'en',
},
dontAutoRegisterSw: true,
generateSw: false,
devSwSrc: './public/static/sw.js',
workboxOpts: {
swSrc: './public/static/sw.js',
swDest: './public/static/service-worker.js',
},
images: {
disableStaticImages: true,
domains: ['trryst-dev.imgix.net', ''],
},
webpack5: true,
typescript: {
// !! WARN !!
// Dangerously allow production builds to successfully complete even if
// your project has type errors.
// !! WARN !!
//ignoreBuildErrors: true,
},
// Exposes Server ENV Vars To Client Using Webpack
env: {
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID,
AUTH0_DOMAIN: process.env.AUTH0_DOMAIN,
BASE_APIPATH: process.env.STAGE === 'dev' ? 'http://localhost:8080' : process.env.ROOT_URL,
//AWS_APIPATH: 'https://o4xqxux7eh.execute-api.eu-west-2.amazonaws.com/dev',
//AWS_APIPATH: 'https://w2bytuti78.execute-api.eu-west-2.amazonaws.com/prod',
AWS_APIPATH: process.env.AWS_APIPATH,
PUBNUB_PUBLISH_KEY: process.env.PUBNUB_PUBLISH_KEY,
PUBNUB_SUBSCRIBE_KEY: process.env.PUBNUB_SUBSCRIBE_KEY,
GA_TRACKING_ID: process.env.GA_TRACKING_ID,
TINYMCE_KEY: process.env.TINYMCE_KEY,
TAWKTO_PROPERTY_ID: process.env.TAWKTO_PROPERTY_ID,
TAWKTO_KEY: process.env.TAWKTO_KEY,
STAGE: process.env.STAGE,
},
resolve: {
alias: {
'@mui/material/styles': require.resolve('@mui/material/styles'),
},
},
webpack(config, options) {
const { isServer } = options;
config.module.rules.push({
test: /\.svg$/,
use: ['@svgr/webpack'],
});
config.module.rules.push({
test: /\.(mp3|wav|mpe?g|ogg|gif)?$/i,
exclude: config.exclude,
use: [
{
loader: require.resolve('file-loader'),
options: {
limit: config.inlineImageLimit,
publicPath: `${config.assetPrefix}/_next/static/images/`,
outputPath: `${isServer ? '../' : ''}static/images/`,
name: '[name]-[hash].[ext]',
esModule: config.esModule || false,
},
},
],
});
return config;
},
headers: {
source: '/api/:path*',
headers: [
{ key: 'Access-Control-Allow-Credentials', value: 'true' },
{ key: 'Access-Control-Allow-Origin', value: 'https://chatserver.vboard.tk' },
{ key: 'Access-Control-Allow-Methods', value: 'GET,OPTIONS,PATCH,DELETE,POST,PUT' },
{
key: 'Access-Control-Allow-Headers',
value:
'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version',
},
],
},
};
const withTM = require('next-transpile-modules')([
'@fullcalendar/react',
'@fullcalendar/daygrid',
'@fullcalendar/interaction',
'@fullcalendar/list',
'@fullcalendar/timegrid',
'@fullcalendar/timeline',
'@fullcalendar/common',
]);
module.exports = {
//below completely for selfhosted tinymce... ditch if not using it
swcMinify: true,
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
config.plugins.push(
new CopyPlugin([
{
from: path.join(__dirname, 'node_modules/tinymce/skins'),
to: path.join(__dirname, 'public/assets/libs/tinymce/skins'),
}, /// Copy to public folder
]),
);
return config;
},
webpackDevMiddleware: config => {
return config;
},
};
module.exports = withPlugins([[offline], [withTM], [withImages, { inlineImageLimit: false }]], nextConfig); Error: Thanks in advance |
Beta Was this translation helpful? Give feedback.
-
It would be great if you make a guideline of where to put our test codes. In (non-Next.js) React development, there are three common directory structures for testing.
In my opinion, the third option is worst since it forces you to make a twin directory structure all the time. But since Next.js discourages you to put any non-page codes to Of course you may replicate the same structure of
And also you might choose different rules for each If there is any guideline about test code directory structure, it would be helpful to someone who is pretty new to both testing and Next.js (like me) :) |
Beta Was this translation helpful? Give feedback.
-
Hi, How do you test dynamic page I can't import |
Beta Was this translation helpful? Give feedback.
-
An example of a Jest test that tests a file using See #44270 |
Beta Was this translation helpful? Give feedback.
-
I've read the doc and I see several issues: E2E tests should be mentioned lastThe first thing you mention are E2E tests like it's the most important thing, this should be the last thing mentioned here's why: Ham Vocke, martinFowler.com - The Practical Test Pyramid, 2018https://martinfowler.com/articles/practical-test-pyramid.html#End-to-endTests
Mike Cohn, Succeeding with Agile, 2010
![]() “Why We Killed Our End-to-End Test Suite”, 2021/09/24
https://building.nubank.com.br/why-we-killed-our-end-to-end-test-suite/ E2E tests are the last thing you write when everything else has been done. If it’s the first and/or only thing you do, you should reconsider. Cypress is a good but Playwright is superior and thus should be favored![]() https://twitter.com/housecor/status/1597954687705104385 ![]() https://twitter.com/garybernhardt/status/1605635546952261632 https://twitter.com/housecor/status/1525205004637839361 You can find more comments about Playwright vs Cypress on Reddit, Hacker News, Twitter... Conclusion: suggested order of sections
(the opposite of what you are currently doing: 1. Cypress, 2. Playwright, 3. React Testing Library) |
Beta Was this translation helpful? Give feedback.
-
Here's an example with e2e testing with playwright, with recording of API calls both client and server side: https://github.com/jwickens/next-page-e2e-testing/tree/main |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there 👋
I'm Delba, Developer Advocate at Vercel. We recently released the first version of our Next.js Testing Docs which we want to continue iterating on.
It would be helpful to learn more about your Next.js testing story and any suggestions of how we could improve.
I've provided some prompts below to help you get started!
Reminder: This discussion will be moderated. Please read our Code of Conduct. Comments that do not meet CoC will not be accepted.
Beta Was this translation helpful? Give feedback.
All reactions