From 4cac6847397638f6ed05cf7c8c8d9ba08a1e074a Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Mon, 4 Apr 2022 15:04:14 -0500 Subject: [PATCH 1/4] Update repo to use react 18 by default --- package.json | 10 +++--- .../basic/styled-components/next.config.js | 16 ++------- test/integration/react-18/app/next.config.js | 6 ++-- test/integration/react-18/app/package.json | 2 -- test/integration/react-18/test/index.test.js | 2 +- .../react-18/test/with-react-18.js | 14 -------- .../app/next.config.js | 6 ++-- .../app/package.json | 8 ++--- .../switchable-runtime/next.config.js | 6 ++-- .../switchable-runtime/package.json | 7 ++-- .../test/utils.js | 2 +- .../unsupported-native-module/next.config.js | 6 ++-- .../unsupported-native-module/package.json | 7 ++-- .../react-17-require-hook.js} | 12 +++---- test/lib/with-react-17.js | 14 ++++++++ yarn.lock | 36 +++++++++---------- 16 files changed, 64 insertions(+), 90 deletions(-) delete mode 100644 test/integration/react-18/test/with-react-18.js rename test/{integration/react-18/test/require-hook.js => lib/react-17-require-hook.js} (56%) create mode 100644 test/lib/with-react-17.js diff --git a/package.json b/package.json index 8f2221b5907829e..e960d5867e5b2bf 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "lint-staged": "lint-staged", "next-with-deps": "./scripts/next-with-deps.sh", "next": "node --trace-deprecation --enable-source-maps packages/next/dist/bin/next", - "next-react-18": "node --trace-deprecation --enable-source-maps -r ./test/integration/react-18/test/require-hook.js packages/next/dist/bin/next", + "next-react-17": "node --trace-deprecation --enable-source-maps -r ./test/lib/react-17-require-hook.js packages/next/dist/bin/next", "next-no-sourcemaps": "node --trace-deprecation packages/next/dist/bin/next", "clean-trace-jaeger": "rm -rf test/integration/basic/.next && TRACE_TARGET=JAEGER node --trace-deprecation --enable-source-maps packages/next/dist/bin/next build test/integration/basic", "debug": "node --inspect packages/next/dist/bin/next", @@ -145,10 +145,10 @@ "pretty-bytes": "5.3.0", "pretty-ms": "7.0.0", "random-seed": "0.3.0", - "react": "17.0.2", - "react-18": "npm:react@18.0.0", - "react-dom": "17.0.2", - "react-dom-18": "npm:react-dom@18.0.0", + "react": "18.0.0", + "react-17": "npm:react@17.0.2", + "react-dom": "18.0.0", + "react-dom-17": "npm:react-dom@17.0.2", "react-ssr-prepass": "1.0.8", "react-virtualized": "9.22.3", "relay-compiler": "13.0.2", diff --git a/test/development/basic/styled-components/next.config.js b/test/development/basic/styled-components/next.config.js index b03e60f7ad06dbd..91f693fda5258b9 100644 --- a/test/development/basic/styled-components/next.config.js +++ b/test/development/basic/styled-components/next.config.js @@ -1,17 +1,5 @@ -const path = require('path') - -let withReact18 = (config) => config - -try { - // only used when running inside of the monorepo not when isolated - withReact18 = require(path.join( - __dirname, - '../../../integration/react-18/test/with-react-18' - )) -} catch (_) {} - -module.exports = withReact18({ +module.exports = { compiler: { styledComponents: true, }, -}) +} diff --git a/test/integration/react-18/app/next.config.js b/test/integration/react-18/app/next.config.js index 270a344a62435f5..a44130da4430cd9 100644 --- a/test/integration/react-18/app/next.config.js +++ b/test/integration/react-18/app/next.config.js @@ -1,6 +1,4 @@ -const withReact18 = require('../test/with-react-18') - -module.exports = withReact18({ +module.exports = { // reactStrictMode: true, experimental: { reactRoot: true, @@ -12,4 +10,4 @@ module.exports = withReact18({ path: 'https://example.com/myaccount/', loader: 'imgix', }, -}) +} diff --git a/test/integration/react-18/app/package.json b/test/integration/react-18/app/package.json index 478f826a5969982..58c9b712c7ed06d 100644 --- a/test/integration/react-18/app/package.json +++ b/test/integration/react-18/app/package.json @@ -1,7 +1,5 @@ { "scripts": { - "next": "node -r ../test/require-hook.js ../../../../packages/next/dist/bin/next", - "debug": "NODE_OPTIONS='--inspect' node -r ../../react-18/test/require-hook.js ../../../../packages/next/dist/bin/next", "dev": "yarn next dev", "build": "yarn next build", "start": "yarn next start" diff --git a/test/integration/react-18/test/index.test.js b/test/integration/react-18/test/index.test.js index 7d89aa3ec179175..7155004b6d19142 100644 --- a/test/integration/react-18/test/index.test.js +++ b/test/integration/react-18/test/index.test.js @@ -19,7 +19,7 @@ import strictMode from './strict-mode' import webdriver from 'next-webdriver' // overrides react and react-dom to v18 -const nodeArgs = ['-r', join(__dirname, 'require-hook.js')] +const nodeArgs = [] const appDir = join(__dirname, '../app') const nextConfig = new File(join(appDir, 'next.config.js')) const invalidPage = new File(join(appDir, 'pages/invalid.js')) diff --git a/test/integration/react-18/test/with-react-18.js b/test/integration/react-18/test/with-react-18.js deleted file mode 100644 index abbec9e348a48f2..000000000000000 --- a/test/integration/react-18/test/with-react-18.js +++ /dev/null @@ -1,14 +0,0 @@ -module.exports = function withReact18(config) { - config.webpack = (webpackConfig) => { - const { alias } = webpackConfig.resolve - // Use react 18 - alias['react'] = 'react-18' - alias['react-dom'] = 'react-dom-18' - alias['react-dom/client'] = 'react-dom-18/client' - alias['react-dom/server'] = 'react-dom-18/server' - alias['react-dom/server.browser'] = 'react-dom-18/server.browser' - - return webpackConfig - } - return config -} diff --git a/test/integration/react-streaming-and-server-components/app/next.config.js b/test/integration/react-streaming-and-server-components/app/next.config.js index add280d239bb309..098961310844329 100644 --- a/test/integration/react-streaming-and-server-components/app/next.config.js +++ b/test/integration/react-streaming-and-server-components/app/next.config.js @@ -1,6 +1,4 @@ -const withReact18 = require('../../react-18/test/with-react-18') - -module.exports = withReact18({ +module.exports = { reactStrictMode: true, onDemandEntries: { maxInactiveAge: 1000 * 60 * 60, @@ -10,4 +8,4 @@ module.exports = withReact18({ serverComponents: true, runtime: 'edge', }, -}) +} diff --git a/test/integration/react-streaming-and-server-components/app/package.json b/test/integration/react-streaming-and-server-components/app/package.json index 603a5787defc3ba..942c2d268df9a2a 100644 --- a/test/integration/react-streaming-and-server-components/app/package.json +++ b/test/integration/react-streaming-and-server-components/app/package.json @@ -1,11 +1,9 @@ { "private": true, "scripts": { - "lnext": "node -r ../../react-18/test/require-hook.js ../../../../packages/next/dist/bin/next", - "debug": "NODE_OPTIONS='--inspect' node -r ../../react-18/test/require-hook.js ../../../../packages/next/dist/bin/next", - "dev": "yarn lnext dev", - "build": "yarn lnext build", - "start": "yarn lnext start" + "dev": "yarn next dev", + "build": "yarn next build", + "start": "yarn next start" }, "dependencies": { "moment": "*" diff --git a/test/integration/react-streaming-and-server-components/switchable-runtime/next.config.js b/test/integration/react-streaming-and-server-components/switchable-runtime/next.config.js index 7b4ccb839cd641c..4917114735fd34a 100644 --- a/test/integration/react-streaming-and-server-components/switchable-runtime/next.config.js +++ b/test/integration/react-streaming-and-server-components/switchable-runtime/next.config.js @@ -1,9 +1,7 @@ -const withReact18 = require('../../react-18/test/with-react-18') - -module.exports = withReact18({ +module.exports = { reactStrictMode: true, experimental: { serverComponents: true, // runtime: 'edge', }, -}) +} diff --git a/test/integration/react-streaming-and-server-components/switchable-runtime/package.json b/test/integration/react-streaming-and-server-components/switchable-runtime/package.json index 90af0ce830c998e..e34e41c75f5ab8c 100644 --- a/test/integration/react-streaming-and-server-components/switchable-runtime/package.json +++ b/test/integration/react-streaming-and-server-components/switchable-runtime/package.json @@ -1,9 +1,8 @@ { "private": true, "scripts": { - "lnext": "node -r ../../react-18/test/require-hook.js ../../../../packages/next/dist/bin/next", - "dev": "yarn lnext dev", - "build": "yarn lnext build", - "start": "yarn lnext start" + "dev": "yarn next dev", + "build": "yarn next build", + "start": "yarn next start" } } diff --git a/test/integration/react-streaming-and-server-components/test/utils.js b/test/integration/react-streaming-and-server-components/test/utils.js index 56e3e4527ee18ba..65bae002ce679f2 100644 --- a/test/integration/react-streaming-and-server-components/test/utils.js +++ b/test/integration/react-streaming-and-server-components/test/utils.js @@ -7,7 +7,7 @@ import { } from 'next-test-utils' import cheerio from 'cheerio' -const nodeArgs = ['-r', join(__dirname, '../../react-18/test/require-hook.js')] +const nodeArgs = [] export const appDir = join(__dirname, '../app') export const nativeModuleTestAppDir = join( diff --git a/test/integration/react-streaming-and-server-components/unsupported-native-module/next.config.js b/test/integration/react-streaming-and-server-components/unsupported-native-module/next.config.js index deb87bcba88d7c6..190994aa291b476 100644 --- a/test/integration/react-streaming-and-server-components/unsupported-native-module/next.config.js +++ b/test/integration/react-streaming-and-server-components/unsupported-native-module/next.config.js @@ -1,8 +1,6 @@ -const withReact18 = require('../../react-18/test/with-react-18') - -module.exports = withReact18({ +module.exports = { experimental: { reactRoot: true, serverComponents: true, }, -}) +} diff --git a/test/integration/react-streaming-and-server-components/unsupported-native-module/package.json b/test/integration/react-streaming-and-server-components/unsupported-native-module/package.json index 90af0ce830c998e..e34e41c75f5ab8c 100644 --- a/test/integration/react-streaming-and-server-components/unsupported-native-module/package.json +++ b/test/integration/react-streaming-and-server-components/unsupported-native-module/package.json @@ -1,9 +1,8 @@ { "private": true, "scripts": { - "lnext": "node -r ../../react-18/test/require-hook.js ../../../../packages/next/dist/bin/next", - "dev": "yarn lnext dev", - "build": "yarn lnext build", - "start": "yarn lnext start" + "dev": "yarn next dev", + "build": "yarn next build", + "start": "yarn next start" } } diff --git a/test/integration/react-18/test/require-hook.js b/test/lib/react-17-require-hook.js similarity index 56% rename from test/integration/react-18/test/require-hook.js rename to test/lib/react-17-require-hook.js index 390d0f0a447e015..ec7a5e80528a7cd 100644 --- a/test/integration/react-18/test/require-hook.js +++ b/test/lib/react-17-require-hook.js @@ -1,12 +1,12 @@ const mod = require('module') const hookPropertyMap = new Map([ - ['react', 'react-18'], - ['react/jsx-runtime', 'react-18/jsx-runtime'], - ['react/jsx-dev-runtime', 'react-18/jsx-dev-runtime'], - ['react-dom', 'react-dom-18'], - ['react-dom/server', 'react-dom-18/server'], - ['react-dom/server.browser', 'react-dom-18/server.browser'], + ['react', 'react-17'], + ['react/jsx-runtime', 'react-17/jsx-runtime'], + ['react/jsx-dev-runtime', 'react-17/jsx-dev-runtime'], + ['react-dom', 'react-dom-17'], + ['react-dom/server', 'react-dom-17/server'], + ['react-dom/server.browser', 'react-dom-17/server.browser'], ]) const resolveFilename = mod._resolveFilename diff --git a/test/lib/with-react-17.js b/test/lib/with-react-17.js new file mode 100644 index 000000000000000..f9000274aa341f0 --- /dev/null +++ b/test/lib/with-react-17.js @@ -0,0 +1,14 @@ +module.exports = function withReact17(config) { + config.webpack = (webpackConfig) => { + const { alias } = webpackConfig.resolve + // Use react 18 + alias['react'] = 'react-17' + alias['react-dom'] = 'react-dom-17' + alias['react-dom/client'] = 'react-dom-17/client' + alias['react-dom/server'] = 'react-dom-17/server' + alias['react-dom/server.browser'] = 'react-dom-17/server.browser' + + return webpackConfig + } + return config +} diff --git a/yarn.lock b/yarn.lock index 3720f64a30b9c45..0d8a5613e112b16 100644 --- a/yarn.lock +++ b/yarn.lock @@ -17778,22 +17778,15 @@ rc@^1.0.1, rc@^1.1.6, rc@^1.2.7, rc@^1.2.8: minimist "^1.2.0" strip-json-comments "~2.0.1" -"react-18@npm:react@18.0.0": - version "18.0.0" - resolved "https://registry.yarnpkg.com/react/-/react-18.0.0.tgz#b468736d1f4a5891f38585ba8e8fb29f91c3cb96" - integrity sha512-x+VL6wbT4JRVPm7EGxXhZ8w8LTROaxPXOqhlGyVSrv0sB1jkyFGgXxJ8LVoPRLvPR6/CIZGFmfzqUa2NYeMr2A== - dependencies: - loose-envify "^1.1.0" - -"react-dom-18@npm:react-dom@18.0.0": - version "18.0.0" - resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-18.0.0.tgz#26b88534f8f1dbb80853e1eabe752f24100d8023" - integrity sha512-XqX7uzmFo0pUceWFCt7Gff6IyIMzFUn7QMZrbrQfGxtaxXZIcGQzoNpRLE3fQLnS4XzLLPMZX2T9TRcSrasicw== +"react-17@npm:react@17.0.2": + version "17.0.2" + resolved "https://registry.yarnpkg.com/react/-/react-17.0.2.tgz#d0b5cc516d29eb3eee383f75b62864cfb6800037" + integrity sha512-gnhPt75i/dq/z3/6q/0asP78D0u592D5L1pd7M8P+dck6Fu/jJeL6iVVK23fptSUZj8Vjf++7wXA8UNclGQcbA== dependencies: loose-envify "^1.1.0" - scheduler "^0.21.0" + object-assign "^4.1.1" -react-dom@17.0.2: +"react-dom-17@npm:react-dom@17.0.2": version "17.0.2" resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-17.0.2.tgz#ecffb6845e3ad8dbfcdc498f0d0a939736502c23" integrity sha512-s4h96KtLDUQlsENhMn1ar8t2bEa+q/YAtj8pPPdIjPDGBDIVNsrD9aXNWqspUe6AzKCIG0C1HZZLqLV7qpOBGA== @@ -17802,6 +17795,14 @@ react-dom@17.0.2: object-assign "^4.1.1" scheduler "^0.20.2" +react-dom@18.0.0: + version "18.0.0" + resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-18.0.0.tgz#26b88534f8f1dbb80853e1eabe752f24100d8023" + integrity sha512-XqX7uzmFo0pUceWFCt7Gff6IyIMzFUn7QMZrbrQfGxtaxXZIcGQzoNpRLE3fQLnS4XzLLPMZX2T9TRcSrasicw== + dependencies: + loose-envify "^1.1.0" + scheduler "^0.21.0" + react-is@17.0.2: version "17.0.2" resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0" @@ -17853,13 +17854,12 @@ react-virtualized@9.22.3: prop-types "^15.7.2" react-lifecycles-compat "^3.0.4" -react@17.0.2: - version "17.0.2" - resolved "https://registry.yarnpkg.com/react/-/react-17.0.2.tgz#d0b5cc516d29eb3eee383f75b62864cfb6800037" - integrity sha512-gnhPt75i/dq/z3/6q/0asP78D0u592D5L1pd7M8P+dck6Fu/jJeL6iVVK23fptSUZj8Vjf++7wXA8UNclGQcbA== +react@18.0.0: + version "18.0.0" + resolved "https://registry.yarnpkg.com/react/-/react-18.0.0.tgz#b468736d1f4a5891f38585ba8e8fb29f91c3cb96" + integrity sha512-x+VL6wbT4JRVPm7EGxXhZ8w8LTROaxPXOqhlGyVSrv0sB1jkyFGgXxJ8LVoPRLvPR6/CIZGFmfzqUa2NYeMr2A== dependencies: loose-envify "^1.1.0" - object-assign "^4.1.1" read-cmd-shim@^2.0.0: version "2.0.0" From c8d10aa584e9d66ef376e6a126e8904e4d460c20 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Mon, 4 Apr 2022 23:20:19 -0500 Subject: [PATCH 2/4] Fix test cases --- packages/next/build/entries.ts | 10 ++++---- packages/next/build/index.ts | 3 ++- packages/next/server/dev/hot-reloader.ts | 6 +++-- .../amphtml-custom-optimizer/next.config.js | 5 ++-- .../test/index.test.js | 13 ++++++---- .../amphtml-fragment-style/next.config.js | 2 ++ .../amphtml-fragment-style/test/index.test.js | 24 +++++++++---------- test/integration/amphtml/next.config.js | 5 ++-- test/integration/amphtml/test/index.test.js | 22 ++++++++--------- test/integration/app-document/next.config.js | 5 ++-- .../app-document/test/index.test.js | 4 ++++ .../app/next.config.js | 4 +++- .../custom-server/test/index.test.js | 5 +++- .../middleware/with-eval/test/index.test.js | 2 +- .../test/index.test.js | 8 +++++-- .../integration/production/test/index.test.js | 4 +++- test/unit/link-rendering.test.ts | 2 +- 17 files changed, 75 insertions(+), 49 deletions(-) create mode 100644 test/integration/amphtml-fragment-style/next.config.js diff --git a/packages/next/build/entries.ts b/packages/next/build/entries.ts index cde116766a2f08f..220af7f4aa974c8 100644 --- a/packages/next/build/entries.ts +++ b/packages/next/build/entries.ts @@ -109,7 +109,8 @@ const cachedPageRuntimeConfig = new Map() // could be thousands of pages existing. export async function getPageRuntime( pageFilePath: string, - nextConfig: Partial + nextConfig: Partial, + isDev?: boolean ): Promise { if (!nextConfig.experimental?.reactRoot) return undefined @@ -125,7 +126,7 @@ export async function getPageRuntime( encoding: 'utf8', }) } catch (err) { - if (process.env.NODE_ENV === 'production') throw err + if (!isDev) throw err return undefined } @@ -216,7 +217,8 @@ export async function createEntrypoints( previewMode: __ApiPreviewProps, config: NextConfigComplete, loadedEnvFiles: LoadedEnvFiles, - pagesDir: string + pagesDir: string, + isDev?: boolean ): Promise { const client: webpack5.EntryObject = {} const server: webpack5.EntryObject = {} @@ -271,7 +273,7 @@ export async function createEntrypoints( const pageFilePath = isInternalPages ? require.resolve(absolutePagePath) : join(pagesDir, absolutePagePath.replace(PAGES_DIR_ALIAS, '')) - const pageRuntime = await getPageRuntime(pageFilePath, config) + const pageRuntime = await getPageRuntime(pageFilePath, config, isDev) const isEdgeRuntime = pageRuntime === 'edge' if (page.match(MIDDLEWARE_ROUTE)) { diff --git a/packages/next/build/index.ts b/packages/next/build/index.ts index e304f9347aea76f..44fd308b454c780 100644 --- a/packages/next/build/index.ts +++ b/packages/next/build/index.ts @@ -317,7 +317,8 @@ export default async function build( previewProps, config, loadedEnvFiles, - pagesDir + pagesDir, + false ) ) const pageKeys = Object.keys(mappedPages) diff --git a/packages/next/server/dev/hot-reloader.ts b/packages/next/server/dev/hot-reloader.ts index e4240446806f2c3..2d3702b9bea987f 100644 --- a/packages/next/server/dev/hot-reloader.ts +++ b/packages/next/server/dev/hot-reloader.ts @@ -339,7 +339,8 @@ export default class HotReloader { this.previewProps, this.config, [], - this.pagesDir + this.pagesDir, + true ) ) @@ -418,7 +419,8 @@ export default class HotReloader { this.previewProps, this.config, [], - this.pagesDir + this.pagesDir, + true ) ).client, hasReactRoot: this.hasReactRoot, diff --git a/test/integration/amphtml-custom-optimizer/next.config.js b/test/integration/amphtml-custom-optimizer/next.config.js index 072c5b3965f9754..32d983dc28dfa00 100644 --- a/test/integration/amphtml-custom-optimizer/next.config.js +++ b/test/integration/amphtml-custom-optimizer/next.config.js @@ -1,4 +1,5 @@ -module.exports = { +const path = require('path') +module.exports = require(path.join(__dirname, '../../lib/with-react-17.js'))({ experimental: { amp: { optimizer: { @@ -9,4 +10,4 @@ module.exports = { skipValidation: true, }, }, -} +}) diff --git a/test/integration/amphtml-custom-optimizer/test/index.test.js b/test/integration/amphtml-custom-optimizer/test/index.test.js index 3643a0bb944d9a3..b9a35e01a9b6770 100644 --- a/test/integration/amphtml-custom-optimizer/test/index.test.js +++ b/test/integration/amphtml-custom-optimizer/test/index.test.js @@ -12,14 +12,19 @@ import { let app let appPort const appDir = join(__dirname, '../') +const nodeArgs = ['-r', join(appDir, '../../lib/react-17-require-hook.js')] describe('AMP Custom Optimizer', () => { it('should build and start for static page', async () => { - const { code } = await nextBuild(appDir, undefined) + const { code } = await nextBuild(appDir, undefined, { + nodeArgs, + }) expect(code).toBe(0) appPort = await findPort() - app = await nextStart(appDir, appPort) + app = await nextStart(appDir, appPort, { + nodeArgs, + }) const html = await renderViaHTTP(appPort, '/') await killApp(app) @@ -34,11 +39,11 @@ describe('AMP Custom Optimizer', () => { }) it('should build and start for dynamic page', async () => { - const { code } = await nextBuild(appDir, undefined) + const { code } = await nextBuild(appDir, undefined, { nodeArgs }) expect(code).toBe(0) appPort = await findPort() - app = await nextStart(appDir, appPort) + app = await nextStart(appDir, appPort, { nodeArgs }) const html = await renderViaHTTP(appPort, '/dynamic') await killApp(app) diff --git a/test/integration/amphtml-fragment-style/next.config.js b/test/integration/amphtml-fragment-style/next.config.js new file mode 100644 index 000000000000000..9c1c065bdfe31eb --- /dev/null +++ b/test/integration/amphtml-fragment-style/next.config.js @@ -0,0 +1,2 @@ +const path = require('path') +module.exports = require(path.join(__dirname, '../../lib/with-react-17.js'))({}) diff --git a/test/integration/amphtml-fragment-style/test/index.test.js b/test/integration/amphtml-fragment-style/test/index.test.js index 64cb949856093ba..3bccdd0303390a7 100644 --- a/test/integration/amphtml-fragment-style/test/index.test.js +++ b/test/integration/amphtml-fragment-style/test/index.test.js @@ -4,31 +4,29 @@ import { join } from 'path' import cheerio from 'cheerio' import { validateAMP } from 'amp-test-utils' import { - stopApp, - startApp, nextBuild, - nextServer, renderViaHTTP, + nextStart, + findPort, + killApp, } from 'next-test-utils' const appDir = join(__dirname, '../') +const nodeArgs = ['-r', join(appDir, '../../lib/react-17-require-hook.js')] let appPort -let server let app describe('AMP Fragment Styles', () => { beforeAll(async () => { - await nextBuild(appDir) - app = nextServer({ - dir: join(__dirname, '../'), - dev: false, - quiet: true, + await nextBuild(appDir, [], { + nodeArgs, + }) + appPort = await findPort() + app = await nextStart(appDir, appPort, { + nodeArgs, }) - - server = await startApp(app) - appPort = server.address().port }) - afterAll(() => stopApp(server)) + afterAll(() => killApp(app)) it('adds styles from fragment in AMP mode correctly', async () => { const html = await renderViaHTTP(appPort, '/', { amp: 1 }) diff --git a/test/integration/amphtml/next.config.js b/test/integration/amphtml/next.config.js index 9645154cca88575..32cc43dcc39328f 100644 --- a/test/integration/amphtml/next.config.js +++ b/test/integration/amphtml/next.config.js @@ -1,4 +1,5 @@ -module.exports = { +const path = require('path') +module.exports = require(path.join(__dirname, '../../lib/with-react-17.js'))({ onDemandEntries: { // Make sure entries are not getting disposed. maxInactiveAge: 1000 * 60 * 60, @@ -7,4 +8,4 @@ module.exports = { canonicalBase: 'http://localhost:1234', }, // edit here -} +}) diff --git a/test/integration/amphtml/test/index.test.js b/test/integration/amphtml/test/index.test.js index bd90039b7c458c6..7251e628559e9e9 100644 --- a/test/integration/amphtml/test/index.test.js +++ b/test/integration/amphtml/test/index.test.js @@ -10,18 +10,16 @@ import { killApp, launchApp, nextBuild, - nextServer, + nextStart, renderViaHTTP, - startApp, - stopApp, waitFor, } from 'next-test-utils' import webdriver from 'next-webdriver' import { join } from 'path' const appDir = join(__dirname, '../') +const nodeArgs = ['-r', join(appDir, '../../lib/react-17-require-hook.js')] let appPort -let server let app const context = {} @@ -38,24 +36,21 @@ describe('AMP Usage', () => { const result = await nextBuild(appDir, undefined, { stdout: true, stderr: true, + nodeArgs, }) output = result.stdout + result.stderr - app = nextServer({ - dir: join(__dirname, '../'), - dev: false, - quiet: true, + appPort = context.appPort = await findPort() + app = await nextStart(appDir, context.appPort, { + nodeArgs, }) - - server = await startApp(app) - context.appPort = appPort = server.address().port }) afterAll(async () => { await rename( join(appDir, 'pages/invalid-amp.js.bak'), join(appDir, 'pages/invalid-amp.js') ) - return stopApp(server) + return killApp(app) }) it('should have amp optimizer in trace', async () => { @@ -281,6 +276,7 @@ describe('AMP Usage', () => { onStderr(msg) { inspectPayload += msg }, + nodeArgs, }) await renderViaHTTP(dynamicAppPort, '/only-amp') @@ -305,6 +301,7 @@ describe('AMP Usage', () => { onStderr(msg) { output += msg }, + nodeArgs, }) }) @@ -552,6 +549,7 @@ describe('AMP Usage', () => { onStderr(msg) { inspectPayload += msg }, + nodeArgs, }) await renderViaHTTP(dynamicAppPort, '/invalid-amp') diff --git a/test/integration/app-document/next.config.js b/test/integration/app-document/next.config.js index 5eca4ccca5570eb..e6b08f8f595f5d5 100644 --- a/test/integration/app-document/next.config.js +++ b/test/integration/app-document/next.config.js @@ -1,3 +1,4 @@ -module.exports = { +const path = require('path') +module.exports = require(path.join(__dirname, '../../lib/with-react-17.js'))({ crossOrigin: 'anonymous', -} +}) diff --git a/test/integration/app-document/test/index.test.js b/test/integration/app-document/test/index.test.js index cb606f37c4643e4..6edbe398077d0bd 100644 --- a/test/integration/app-document/test/index.test.js +++ b/test/integration/app-document/test/index.test.js @@ -28,6 +28,10 @@ describe('Document and App', () => { context.server = await launchApp(join(__dirname, '../'), context.appPort, { onStdout: collectOutput, onStderr: collectOutput, + nodeArgs: [ + '-r', + join(__dirname, '../../../lib/react-17-require-hook.js'), + ], }) // pre-build all pages at the start diff --git a/test/integration/build-trace-extra-entries/app/next.config.js b/test/integration/build-trace-extra-entries/app/next.config.js index bb188bcf77e89b5..5a9fa362be0f2e4 100644 --- a/test/integration/build-trace-extra-entries/app/next.config.js +++ b/test/integration/build-trace-extra-entries/app/next.config.js @@ -1,4 +1,5 @@ const path = require('path') +let handledServer = false module.exports = { webpack(cfg, { isServer }) { @@ -7,7 +8,8 @@ module.exports = { cfg.entry = async () => { const origEntries = await origEntry() - if (isServer) { + if (isServer && !handledServer) { + handledServer = true const curEntry = origEntries['pages/_app'] origEntries['pages/_app'] = [ path.join(__dirname, 'lib/get-data.js'), diff --git a/test/integration/custom-server/test/index.test.js b/test/integration/custom-server/test/index.test.js index c64615fc413fd09..330fe4b1c4ef5b3 100644 --- a/test/integration/custom-server/test/index.test.js +++ b/test/integration/custom-server/test/index.test.js @@ -98,7 +98,10 @@ describe('Custom Server', () => { }) describe('with generateEtags enabled', () => { - beforeAll(() => startServer({ GENERATE_ETAGS: 'true' })) + beforeAll(async () => { + await nextBuild(appDir) + await startServer({ GENERATE_ETAGS: 'true', NODE_ENV: 'production' }) + }) afterAll(() => killApp(server)) it('response includes etag header', async () => { diff --git a/test/integration/middleware/with-eval/test/index.test.js b/test/integration/middleware/with-eval/test/index.test.js index 3a5c44757db4adf..ce2239fd02a77ae 100644 --- a/test/integration/middleware/with-eval/test/index.test.js +++ b/test/integration/middleware/with-eval/test/index.test.js @@ -62,7 +62,7 @@ describe('Middleware usage of dynamic code evaluation', () => { it('does not has problems with eval in page or server code', async () => { const html = await renderViaHTTP(context.appPort, `/`) - expect(html).toMatch(/>100 and 100<\//) + expect(html).toMatch(/>.*?100.*?and.*?100.*?<\//) await waitFor(500) expect(output).not.toContain(DYNAMIC_CODE_ERROR) }) diff --git a/test/integration/next-dynamic-lazy-compilation/test/index.test.js b/test/integration/next-dynamic-lazy-compilation/test/index.test.js index e76b1176b91ee68..9a35a187fbe4944 100644 --- a/test/integration/next-dynamic-lazy-compilation/test/index.test.js +++ b/test/integration/next-dynamic-lazy-compilation/test/index.test.js @@ -29,7 +29,9 @@ function runTests() { const browser = await webdriver(appPort, '/') const text = await browser.elementByCss('#before-hydration').text() - expect(text).toBe('Index12344') + expect(text).toBe( + 'Index12344' + ) expect(await browser.eval('window.caughtErrors')).toBe('') }) @@ -37,7 +39,9 @@ function runTests() { const browser = await webdriver(appPort, '/') const text = await browser.elementByCss('#first-render').text() - expect(text).toBe('Index12344') + expect(text).toBe( + 'Index12344' + ) expect(await browser.eval('window.caughtErrors')).toBe('') }) } diff --git a/test/integration/production/test/index.test.js b/test/integration/production/test/index.test.js index 2bc0028cb86df9c..aa77bb1698bde01 100644 --- a/test/integration/production/test/index.test.js +++ b/test/integration/production/test/index.test.js @@ -377,7 +377,9 @@ describe('Production Usage', () => { expect(res2.status).toBe(304) }) - it('should allow etag header support with getServerSideProps', async () => { + // TODO: should we generate weak etags for streaming getServerSideProps? + // this is currently not expected to work with react-18 + it.skip('should allow etag header support with getServerSideProps', async () => { const url = `http://localhost:${appPort}` const etag = (await fetchViaHTTP(url, '/fully-dynamic')).headers.get( 'ETag' diff --git a/test/unit/link-rendering.test.ts b/test/unit/link-rendering.test.ts index fb78704b9175102..7b79b5ebc90e346 100644 --- a/test/unit/link-rendering.test.ts +++ b/test/unit/link-rendering.test.ts @@ -14,7 +14,7 @@ describe('Link rendering', () => { ) const html = ReactDOM.renderToString(element) expect(html).toMatchInlineSnapshot( - `"to another page"` + `"to another page"` ) }) }) From 7a91eb80c3db751df22bfea2c1e6b134c289f93b Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Tue, 5 Apr 2022 10:32:57 -0500 Subject: [PATCH 3/4] Update tests --- package.json | 2 +- .../client-navigation-a11y/next.config.js | 3 +- .../client-navigation-a11y/test/index.test.js | 2 + test/integration/critical-css/next.config.js | 1 + .../critical-css/test/index.test.js | 17 +++-- .../next.config.js | 2 + .../test/index.test.js | 9 ++- .../middleware/core/test/index.test.js | 10 +-- .../next-dynamic/test/index.test.js | 4 +- .../styled-jsx-module/app/next.config.js | 4 ++ .../styled-jsx-module/test/index.test.js | 13 +++- test/unit/link-warnings.test.tsx | 12 ++-- yarn.lock | 69 ++++++++++--------- 13 files changed, 89 insertions(+), 59 deletions(-) create mode 100644 test/integration/critical-css/next.config.js create mode 100644 test/integration/custom-error-page-exception/next.config.js create mode 100644 test/integration/styled-jsx-module/app/next.config.js diff --git a/package.json b/package.json index e960d5867e5b2bf..42ab470b3d61dd9 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "@svgr/webpack": "5.5.0", "@swc/cli": "0.1.55", "@swc/core": "1.2.148", - "@testing-library/react": "11.2.5", + "@testing-library/react": "13.0.0", "@types/cheerio": "0.22.16", "@types/fs-extra": "8.1.0", "@types/html-validator": "5.0.2", diff --git a/test/integration/client-navigation-a11y/next.config.js b/test/integration/client-navigation-a11y/next.config.js index 4ba52ba2c8df675..9c1c065bdfe31eb 100644 --- a/test/integration/client-navigation-a11y/next.config.js +++ b/test/integration/client-navigation-a11y/next.config.js @@ -1 +1,2 @@ -module.exports = {} +const path = require('path') +module.exports = require(path.join(__dirname, '../../lib/with-react-17.js'))({}) diff --git a/test/integration/client-navigation-a11y/test/index.test.js b/test/integration/client-navigation-a11y/test/index.test.js index 97ccb29b6523254..94a5c3b699e234b 100644 --- a/test/integration/client-navigation-a11y/test/index.test.js +++ b/test/integration/client-navigation-a11y/test/index.test.js @@ -11,6 +11,7 @@ import { join } from 'path' const context = {} const appDir = join(__dirname, '../') +const nodeArgs = ['-r', join(appDir, '../../lib/react-17-require-hook.js')] const navigateTo = async (browser, selector) => await browser @@ -31,6 +32,7 @@ describe('Client Navigation accessibility', () => { context.appPort = await findPort() context.server = await launchApp(appDir, context.appPort, { env: { __NEXT_TEST_WITH_DEVTOOL: 1 }, + nodeArgs, }) const prerender = [ diff --git a/test/integration/critical-css/next.config.js b/test/integration/critical-css/next.config.js new file mode 100644 index 000000000000000..9bd93fa75fa967d --- /dev/null +++ b/test/integration/critical-css/next.config.js @@ -0,0 +1 @@ +module.exports = { experimental: { optimizeCss: true } } diff --git a/test/integration/critical-css/test/index.test.js b/test/integration/critical-css/test/index.test.js index 2c1469866c4c43b..2178f1f516c182b 100644 --- a/test/integration/critical-css/test/index.test.js +++ b/test/integration/critical-css/test/index.test.js @@ -14,6 +14,7 @@ import fs from 'fs-extra' const glob = promisify(globOrigig) const appDir = join(__dirname, '../') const nextConfig = join(appDir, 'next.config.js') +const nodeArgs = ['-r', join(appDir, '../../lib/react-17-require-hook.js')] let appPort let app @@ -67,9 +68,13 @@ describe('CSS optimization for SSR apps', () => { if (fs.pathExistsSync(join(appDir, '.next'))) { await fs.remove(join(appDir, '.next')) } - await nextBuild(appDir) + await nextBuild(appDir, undefined, { + nodeArgs, + }) appPort = await findPort() - app = await nextStart(appDir, appPort) + app = await nextStart(appDir, appPort, { + nodeArgs, + }) }) afterAll(async () => { await killApp(app) @@ -85,9 +90,13 @@ describe('Font optimization for emulated serverless apps', () => { `module.exports = { target: 'experimental-serverless-trace', experimental: {optimizeCss: true} }`, 'utf8' ) - await nextBuild(appDir) + await nextBuild(appDir, undefined, { + nodeArgs, + }) appPort = await findPort() - app = await nextStart(appDir, appPort) + app = await nextStart(appDir, appPort, { + nodeArgs, + }) }) afterAll(async () => { await killApp(app) diff --git a/test/integration/custom-error-page-exception/next.config.js b/test/integration/custom-error-page-exception/next.config.js new file mode 100644 index 000000000000000..9c1c065bdfe31eb --- /dev/null +++ b/test/integration/custom-error-page-exception/next.config.js @@ -0,0 +1,2 @@ +const path = require('path') +module.exports = require(path.join(__dirname, '../../lib/with-react-17.js'))({}) diff --git a/test/integration/custom-error-page-exception/test/index.test.js b/test/integration/custom-error-page-exception/test/index.test.js index 1920ac969d4063f..707dcc209959f50 100644 --- a/test/integration/custom-error-page-exception/test/index.test.js +++ b/test/integration/custom-error-page-exception/test/index.test.js @@ -5,14 +5,19 @@ import webdriver from 'next-webdriver' import { nextBuild, nextStart, findPort, killApp, check } from 'next-test-utils' const appDir = join(__dirname, '..') +const nodeArgs = ['-r', join(appDir, '../../lib/react-17-require-hook.js')] let appPort let app describe('Custom error page exception', () => { beforeAll(async () => { - await nextBuild(appDir) + await nextBuild(appDir, undefined, { + nodeArgs, + }) appPort = await findPort() - app = await nextStart(appDir, appPort) + app = await nextStart(appDir, appPort, { + nodeArgs, + }) }) afterAll(() => killApp(app)) it('should handle errors from _error render', async () => { diff --git a/test/integration/middleware/core/test/index.test.js b/test/integration/middleware/core/test/index.test.js index 536319514c31bfc..e2c5081241db425 100644 --- a/test/integration/middleware/core/test/index.test.js +++ b/test/integration/middleware/core/test/index.test.js @@ -628,7 +628,7 @@ function responseTests(locale = '') { `${locale}/responses/react?name=jack` ) const html = await res.text() - expect(html).toBe('

SSR with React! Hello, jack

') + expect(html).toBe('

SSR with React! Hello, jack

') }) it(`${locale} should stream a React component`, async () => { @@ -637,9 +637,7 @@ function responseTests(locale = '') { `${locale}/responses/react-stream` ) const html = await res.text() - expect(html).toBe( - '

I am a stream

I am another stream

' - ) + expect(html).toBe('

I am a stream

I am another stream

') }) it(`${locale} should stream a long response`, async () => { @@ -812,7 +810,9 @@ function interfaceTests(locale = '') { const element = await browser.elementByCss('.title') expect(await element.text()).toEqual('Parts page') const logs = await browser.log() - expect(logs.every((log) => log.source === 'log')).toEqual(true) + expect( + logs.every((log) => log.source === 'log' || log.source === 'info') + ).toEqual(true) }) } diff --git a/test/integration/next-dynamic/test/index.test.js b/test/integration/next-dynamic/test/index.test.js index e0c8f9be9ae73cd..ee70ca8b4dce8d3 100644 --- a/test/integration/next-dynamic/test/index.test.js +++ b/test/integration/next-dynamic/test/index.test.js @@ -29,7 +29,9 @@ function runTests() { const text = await browser.elementByCss('#first-render').text() // Failure case is 'Index3' - expect(text).toBe('Index12344') + expect(text).toBe( + 'Index12344' + ) expect(await browser.eval('window.caughtErrors')).toBe('') }) } diff --git a/test/integration/styled-jsx-module/app/next.config.js b/test/integration/styled-jsx-module/app/next.config.js new file mode 100644 index 000000000000000..40b089d571fe176 --- /dev/null +++ b/test/integration/styled-jsx-module/app/next.config.js @@ -0,0 +1,4 @@ +const path = require('path') +module.exports = require(path.join(__dirname, '../../../lib/with-react-17.js'))( + {} +) diff --git a/test/integration/styled-jsx-module/test/index.test.js b/test/integration/styled-jsx-module/test/index.test.js index 3bad07cb13c47fb..0243f07266ebc1a 100644 --- a/test/integration/styled-jsx-module/test/index.test.js +++ b/test/integration/styled-jsx-module/test/index.test.js @@ -12,6 +12,7 @@ import { } from 'next-test-utils' const appDir = join(__dirname, '../app') +const nodeArgs = ['-r', join(appDir, '../../../lib/react-17-require-hook.js')] let appPort let app @@ -48,9 +49,13 @@ function runTests() { describe('styled-jsx using in node_modules', () => { describe('Production', () => { beforeAll(async () => { - await nextBuild(appDir) + await nextBuild(appDir, undefined, { + nodeArgs, + }) appPort = await findPort() - app = await nextStart(appDir, appPort) + app = await nextStart(appDir, appPort, { + nodeArgs, + }) }) afterAll(() => killApp(app)) @@ -60,7 +65,9 @@ describe('styled-jsx using in node_modules', () => { describe('Development', () => { beforeAll(async () => { appPort = await findPort() - app = await launchApp(appDir, appPort) + app = await launchApp(appDir, appPort, { + nodeArgs, + }) }) afterAll(() => killApp(app)) diff --git a/test/unit/link-warnings.test.tsx b/test/unit/link-warnings.test.tsx index cbcbc7fbccd686d..d102876f6a361e3 100644 --- a/test/unit/link-warnings.test.tsx +++ b/test/unit/link-warnings.test.tsx @@ -4,20 +4,16 @@ import { act, render } from '@testing-library/react' import Link from 'next/link' import React from 'react' -import { getPackageVersion } from 'next/dist/lib/get-package-version' -import semver from 'next/dist/compiled/semver' describe('', () => { let spy let expectedErrors beforeAll(async () => { - spy = jest.spyOn(console, 'error').mockImplementation(() => {}) - - const reactVersion = await getPackageVersion({ - cwd: __dirname, - name: 'react-dom', + spy = jest.spyOn(console, 'error').mockImplementation((...args) => { + console.log(...args) }) - expectedErrors = reactVersion && semver.gte(reactVersion, '18.0.0') ? 1 : 0 + + expectedErrors = 0 }) it('test link with unmount', () => { diff --git a/yarn.lock b/yarn.lock index 0d8a5613e112b16..9bbd24e3987e7b3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3330,17 +3330,6 @@ "@types/yargs" "^15.0.0" chalk "^4.0.0" -"@jest/types@^26.6.2": - version "26.6.2" - resolved "https://registry.yarnpkg.com/@jest/types/-/types-26.6.2.tgz#bef5a532030e1d88a2f5a6d933f84e97226ed48e" - integrity sha512-fC6QCp7Sc5sX6g8Tvbmj4XUTbyrik0akgRy03yjXbQaBWWNWGE7SGtJk98m0N8nzegD/7SggrUlivxo5ax4KWQ== - dependencies: - "@types/istanbul-lib-coverage" "^2.0.0" - "@types/istanbul-reports" "^3.0.0" - "@types/node" "*" - "@types/yargs" "^15.0.0" - chalk "^4.0.0" - "@jest/types@^27.0.6": version "27.0.6" resolved "https://registry.yarnpkg.com/@jest/types/-/types-27.0.6.tgz#9a992bc517e0c49f035938b8549719c2de40706b" @@ -4715,27 +4704,28 @@ dependencies: chokidar "^1.7.0" -"@testing-library/dom@^7.28.1": - version "7.29.4" - resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-7.29.4.tgz#1647c2b478789621ead7a50614ad81ab5ae5b86c" - integrity sha512-CtrJRiSYEfbtNGtEsd78mk1n1v2TUbeABlNIcOCJdDfkN5/JTOwQEbbQpoSRxGqzcWPgStMvJ4mNolSuBRv1NA== +"@testing-library/dom@^8.5.0": + version "8.13.0" + resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-8.13.0.tgz#bc00bdd64c7d8b40841e27a70211399ad3af46f5" + integrity sha512-9VHgfIatKNXQNaZTtLnalIy0jNZzY35a4S3oi08YAt9Hv1VsfZ/DfA45lM8D/UhtHBGJ4/lGwp0PZkVndRkoOQ== dependencies: "@babel/code-frame" "^7.10.4" "@babel/runtime" "^7.12.5" "@types/aria-query" "^4.2.0" - aria-query "^4.2.2" + aria-query "^5.0.0" chalk "^4.1.0" - dom-accessibility-api "^0.5.4" + dom-accessibility-api "^0.5.9" lz-string "^1.4.4" - pretty-format "^26.6.2" + pretty-format "^27.0.2" -"@testing-library/react@11.2.5": - version "11.2.5" - resolved "https://registry.yarnpkg.com/@testing-library/react/-/react-11.2.5.tgz#ae1c36a66c7790ddb6662c416c27863d87818eb9" - integrity sha512-yEx7oIa/UWLe2F2dqK0FtMF9sJWNXD+2PPtp39BvE0Kh9MJ9Kl0HrZAgEuhUJR+Lx8Di6Xz+rKwSdEPY2UV8ZQ== +"@testing-library/react@13.0.0": + version "13.0.0" + resolved "https://registry.yarnpkg.com/@testing-library/react/-/react-13.0.0.tgz#8cdaf4667c6c2b082eb0513731551e9db784e8bc" + integrity sha512-p0lYA1M7uoEmk2LnCbZLGmHJHyH59sAaZVXChTXlyhV/PRW9LoIh4mdf7tiXsO8BoNG+vN8UnFJff1hbZeXv+w== dependencies: "@babel/runtime" "^7.12.5" - "@testing-library/dom" "^7.28.1" + "@testing-library/dom" "^8.5.0" + "@types/react-dom" "*" "@tootallnate/once@1": version "1.1.2" @@ -5233,6 +5223,13 @@ version "1.2.3" resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.3.tgz#7ee330ba7caafb98090bece86a5ee44115904c2c" +"@types/react-dom@*": + version "17.0.14" + resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-17.0.14.tgz#c8f917156b652ddf807711f5becbd2ab018dea9f" + integrity sha512-H03xwEP1oXmSfl3iobtmQ/2dHF5aBHr8aUMwyGZya6OW45G+xtdzmq6HkncefiBt5JU8DVyaWl/nWZbjZCnzAQ== + dependencies: + "@types/react" "*" + "@types/react-dom@16.9.4": version "16.9.4" resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-16.9.4.tgz#0b58df09a60961dcb77f62d4f1832427513420df" @@ -6282,6 +6279,11 @@ aria-query@^4.2.2: "@babel/runtime" "^7.10.2" "@babel/runtime-corejs3" "^7.10.2" +aria-query@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/aria-query/-/aria-query-5.0.0.tgz#210c21aaf469613ee8c9a62c7f86525e058db52c" + integrity sha512-V+SM7AbUwJ+EBnB8+DXs0hPZHO0W6pqBcc0dW90OwtVG02PswOu/teuARoLQjdDOH+t9pJgGnW5/Qmouf3gPJg== + arr-diff@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/arr-diff/-/arr-diff-2.0.0.tgz#8f3b827f955a8bd669697e4a4256ac3ceae356cf" @@ -9071,10 +9073,10 @@ doctrine@^3.0.0: dependencies: esutils "^2.0.2" -dom-accessibility-api@^0.5.4: - version "0.5.4" - resolved "https://registry.yarnpkg.com/dom-accessibility-api/-/dom-accessibility-api-0.5.4.tgz#b06d059cdd4a4ad9a79275f9d414a5c126241166" - integrity sha512-TvrjBckDy2c6v6RLxPv5QXOnU+SmF9nBII5621Ve5fu6Z/BDrENurBEvlC1f44lKEUVqOpK4w9E5Idc5/EgkLQ== +dom-accessibility-api@^0.5.9: + version "0.5.13" + resolved "https://registry.yarnpkg.com/dom-accessibility-api/-/dom-accessibility-api-0.5.13.tgz#102ee5f25eacce09bdf1cfa5a298f86da473be4b" + integrity sha512-R305kwb5CcMDIpSHUnLyIAp7SrSPBx6F0VfQFB3M75xVMHhXJJIdePYgbPPh1o57vCHNu5QztokWUPsLjWzFqw== dom-helpers@^5.1.3: version "5.2.1" @@ -17340,14 +17342,13 @@ pretty-format@^26.0.1: ansi-styles "^4.0.0" react-is "^16.12.0" -pretty-format@^26.6.2: - version "26.6.2" - resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-26.6.2.tgz#e35c2705f14cb7fe2fe94fa078345b444120fc93" - integrity sha512-7AeGuCYNGmycyQbCqd/3PWH4eOoX/OiCa0uphp57NVTeAGdJGaAliecxwBDHYQCIvrW7aDBZCYeNTP/WX69mkg== +pretty-format@^27.0.2: + version "27.5.1" + resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-27.5.1.tgz#2181879fdea51a7a5851fb39d920faa63f01d88e" + integrity sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ== dependencies: - "@jest/types" "^26.6.2" - ansi-regex "^5.0.0" - ansi-styles "^4.0.0" + ansi-regex "^5.0.1" + ansi-styles "^5.0.0" react-is "^17.0.1" pretty-format@^27.0.6: From 6f998bbbb292df03c366d60bf5f9b5bd296a46aa Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Tue, 5 Apr 2022 11:34:13 -0500 Subject: [PATCH 4/4] more test updates --- .../custom-routes/test/index.test.js | 4 +- .../fixtures/with-google/next.config.js | 8 +- .../fixtures/with-typekit/next.config.js | 8 +- .../font-optimization/test/index.test.js | 76 ++++++++++++------- .../react-18-invalid-config/index.test.js | 13 +++- test/lib/next-test-utils.js | 12 ++- 6 files changed, 82 insertions(+), 39 deletions(-) diff --git a/test/integration/custom-routes/test/index.test.js b/test/integration/custom-routes/test/index.test.js index 691fee293c345a1..2c5fda4cee3ded4 100644 --- a/test/integration/custom-routes/test/index.test.js +++ b/test/integration/custom-routes/test/index.test.js @@ -177,7 +177,7 @@ const runTests = (isDev = false) => { const browser = await webdriver(appPort, '/rewriting-to-auto-export') await check( () => browser.eval(() => document.documentElement.innerHTML), - /auto-export hello/ + /auto-export.*?hello/ ) expect(JSON.parse(await browser.elementByCss('#query').text())).toEqual({ rewrite: '1', @@ -2181,7 +2181,7 @@ describe('Custom routes', () => { const browser = await webdriver(appPort, '/auto-export/my-slug') await check( () => browser.eval(() => document.documentElement.innerHTML), - /auto-export my-slug/ + /auto-export.*?my-slug/ ) }) }) diff --git a/test/integration/font-optimization/fixtures/with-google/next.config.js b/test/integration/font-optimization/fixtures/with-google/next.config.js index 48d01ad0e21d265..4dc780b4c615050 100644 --- a/test/integration/font-optimization/fixtures/with-google/next.config.js +++ b/test/integration/font-optimization/fixtures/with-google/next.config.js @@ -1,3 +1,7 @@ -module.exports = { +const path = require('path') +module.exports = require(path.join( + __dirname, + '../../../../lib/with-react-17.js' +))({ cleanDistDir: false, -} +}) diff --git a/test/integration/font-optimization/fixtures/with-typekit/next.config.js b/test/integration/font-optimization/fixtures/with-typekit/next.config.js index 48d01ad0e21d265..4dc780b4c615050 100644 --- a/test/integration/font-optimization/fixtures/with-typekit/next.config.js +++ b/test/integration/font-optimization/fixtures/with-typekit/next.config.js @@ -1,3 +1,7 @@ -module.exports = { +const path = require('path') +module.exports = require(path.join( + __dirname, + '../../../../lib/with-react-17.js' +))({ cleanDistDir: false, -} +}) diff --git a/test/integration/font-optimization/test/index.test.js b/test/integration/font-optimization/test/index.test.js index f4a4bdd18c6b47b..ef546afe6f6365e 100644 --- a/test/integration/font-optimization/test/index.test.js +++ b/test/integration/font-optimization/test/index.test.js @@ -15,6 +15,10 @@ import { import webdriver from 'next-webdriver' const fixturesDir = join(__dirname, '..', 'fixtures') +const nodeArgs = [ + '-r', + join(__dirname, '../../../lib/react-17-require-hook.js'), +] const fsExists = (file) => fs @@ -26,14 +30,14 @@ async function getBuildId(appDir) { return fs.readFile(join(appDir, '.next', 'BUILD_ID'), 'utf8') } -const startServerlessEmulator = async (dir, port) => { +const startServerlessEmulator = async (dir, port, opts = {}) => { const scriptPath = join(dir, 'server.js') const env = Object.assign( {}, { ...process.env }, { PORT: port, BUILD_ID: await getBuildId(dir) } ) - return initNextServerScript(scriptPath, /ready on/i, env, false, {}) + return initNextServerScript(scriptPath, /ready on/i, env, false, opts) } describe('Font Optimization', () => { @@ -218,7 +222,9 @@ describe('Font Optimization', () => { // Re-run build to check if it works when build is cached it('should work when build is cached', async () => { - await nextBuild(appDir) + await nextBuild(appDir, undefined, { + nodeArgs, + }) const testJson = JSON.parse( await fs.readFile(builtPage('font-manifest.json'), { encoding: 'utf-8', @@ -230,18 +236,16 @@ describe('Font Optimization', () => { describe('Font optimization for SSR apps', () => { beforeAll(async () => { - await fs.writeFile( - nextConfig, - `module.exports = { cleanDistDir: false }`, - 'utf8' - ) - if (fs.pathExistsSync(join(appDir, '.next'))) { await fs.remove(join(appDir, '.next')) } - await nextBuild(appDir) + await nextBuild(appDir, undefined, { + nodeArgs, + }) appPort = await findPort() - app = await nextStart(appDir, appPort) + app = await nextStart(appDir, appPort, { + nodeArgs, + }) builtServerPagesDir = join(appDir, '.next', 'server') builtPage = (file) => join(builtServerPagesDir, file) }) @@ -250,37 +254,58 @@ describe('Font Optimization', () => { }) describe('Font optimization for serverless apps', () => { + const origNextConfig = fs.readFileSync(nextConfig) + beforeAll(async () => { await fs.writeFile( nextConfig, - `module.exports = { target: 'serverless', cleanDistDir: false }`, + ` + const path = require('path') + module.exports = require(path.join(__dirname, '../../../../lib/with-react-17.js'))({ target: 'serverless', cleanDistDir: false }) + `, 'utf8' ) - await nextBuild(appDir) + await nextBuild(appDir, undefined, { + nodeArgs, + }) appPort = await findPort() - app = await nextStart(appDir, appPort) + app = await nextStart(appDir, appPort, { + nodeArgs, + }) builtServerPagesDir = join(appDir, '.next', 'serverless') builtPage = (file) => join(builtServerPagesDir, file) }) - afterAll(() => killApp(app)) + afterAll(async () => { + await fs.writeFile(nextConfig, origNextConfig) + await killApp(app) + }) runTests() }) describe('Font optimization for emulated serverless apps', () => { + const origNextConfig = fs.readFileSync(nextConfig) + beforeAll(async () => { await fs.writeFile( nextConfig, - `module.exports = { target: 'experimental-serverless-trace', cleanDistDir: false }`, + ` + const path = require('path') + module.exports = require(path.join(__dirname, '../../../../lib/with-react-17.js'))({ target: 'experimental-serverless-trace', cleanDistDir: false }) + `, 'utf8' ) - await nextBuild(appDir) + await nextBuild(appDir, undefined, { + nodeArgs, + }) appPort = await findPort() - app = await startServerlessEmulator(appDir, appPort) + app = await startServerlessEmulator(appDir, appPort, { + nodeArgs, + }) builtServerPagesDir = join(appDir, '.next', 'serverless') builtPage = (file) => join(builtServerPagesDir, file) }) afterAll(async () => { - await fs.remove(nextConfig) + await fs.writeFile(nextConfig, origNextConfig) await killApp(app) }) runTests() @@ -288,19 +313,18 @@ describe('Font Optimization', () => { describe('Font optimization for unreachable font definitions.', () => { beforeAll(async () => { - await fs.writeFile( - nextConfig, - `module.exports = { cleanDistDir: false }`, - 'utf8' - ) - await nextBuild(appDir) + await nextBuild(appDir, undefined, { + nodeArgs, + }) await fs.writeFile( join(appDir, '.next', 'server', 'font-manifest.json'), '[]', 'utf8' ) appPort = await findPort() - app = await nextStart(appDir, appPort) + app = await nextStart(appDir, appPort, { + nodeArgs, + }) builtServerPagesDir = join(appDir, '.next', 'serverless') builtPage = (file) => join(builtServerPagesDir, file) }) diff --git a/test/integration/react-18-invalid-config/index.test.js b/test/integration/react-18-invalid-config/index.test.js index 50d3c8bb51409df..9cde36de3148d1b 100644 --- a/test/integration/react-18-invalid-config/index.test.js +++ b/test/integration/react-18-invalid-config/index.test.js @@ -5,11 +5,17 @@ import { join } from 'path' import { File, nextBuild } from 'next-test-utils' const appDir = __dirname +const nodeArgs = ['-r', join(appDir, '../../lib/react-17-require-hook.js')] const nextConfig = new File(join(appDir, 'next.config.js')) const reactDomPackagePah = join(appDir, 'node_modules/react-dom') function writeNextConfig(config) { - const content = `module.exports = { experimental: ${JSON.stringify(config)} }` + const content = ` + const path = require('path') + module.exports = require(path.join(__dirname, '../../lib/with-react-17.js'))({ experimental: ${JSON.stringify( + config + )} }) + ` nextConfig.write(content) } @@ -18,7 +24,7 @@ describe('Invalid react 18 webpack config', () => { writeNextConfig({ runtime: 'edge', }) - const { stderr } = await nextBuild(appDir, [], { stderr: true }) + const { stderr } = await nextBuild(appDir, [], { stderr: true, nodeArgs }) nextConfig.restore() expect(stderr).toContain( @@ -42,7 +48,7 @@ describe('React 17 with React 18 config', () => { }) it('should warn user when not using react 18 and `experimental.reactRoot` is enabled', async () => { - const { stderr } = await nextBuild(appDir, [], { stderr: true }) + const { stderr } = await nextBuild(appDir, [], { stderr: true, nodeArgs }) expect(stderr).toContain( 'You have to use React 18 to use `experimental.reactRoot`.' ) @@ -51,6 +57,7 @@ describe('React 17 with React 18 config', () => { it('suspense is not allowed in blocking rendering mode', async () => { const { stderr, code } = await nextBuild(appDir, [], { stderr: true, + nodeArgs, }) expect(stderr).toContain( 'Invalid suspense option usage in next/dynamic. Read more: https://nextjs.org/docs/messages/invalid-dynamic-suspense' diff --git a/test/lib/next-test-utils.js b/test/lib/next-test-utils.js index 3e084bd0553e508..c90aaa433e25d6e 100644 --- a/test/lib/next-test-utils.js +++ b/test/lib/next-test-utils.js @@ -29,10 +29,14 @@ export function initNextServerScript( opts ) { return new Promise((resolve, reject) => { - const instance = spawn('node', ['--no-deprecation', scriptPath], { - env, - cwd: opts && opts.cwd, - }) + const instance = spawn( + 'node', + [...((opts && opts.nodeArgs) || []), '--no-deprecation', scriptPath], + { + env, + cwd: opts && opts.cwd, + } + ) function handleStdout(data) { const message = data.toString()