From af9d6ae9f855c1639c502a9a2953b528bdb0805d Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Wed, 23 Jun 2021 23:33:34 -0500 Subject: [PATCH 1/2] Separate node polyfill test from basic suite --- test/integration/basic/test/index.test.js | 36 -------------- .../polyfill-node-modules/next.config.js | 6 +++ .../pages/node-browser-polyfills.js | 0 .../polyfill-node-modules/test/index.test.js | 49 +++++++++++++++++++ 4 files changed, 55 insertions(+), 36 deletions(-) create mode 100644 test/integration/polyfill-node-modules/next.config.js rename test/integration/{basic => polyfill-node-modules}/pages/node-browser-polyfills.js (100%) create mode 100644 test/integration/polyfill-node-modules/test/index.test.js diff --git a/test/integration/basic/test/index.test.js b/test/integration/basic/test/index.test.js index e605903b21e61..e94c48e373f69 100644 --- a/test/integration/basic/test/index.test.js +++ b/test/integration/basic/test/index.test.js @@ -2,7 +2,6 @@ import { join } from 'path' import { renderViaHTTP, findPort, launchApp, killApp } from 'next-test-utils' -import webdriver from 'next-webdriver' // test suits import hmr from './hmr' @@ -34,41 +33,6 @@ describe('Basic Features', () => { }) afterAll(() => killApp(context.server)) - it('should polyfill Node.js modules', async () => { - const browser = await webdriver(context.appPort, '/node-browser-polyfills') - - console.error({ - logs: await browser.log('browser'), - content: await browser.eval('document.documentElement.innerHTML'), - }) - - await browser.waitForCondition('window.didRender') - - const data = await browser - .waitForElementByCss('#node-browser-polyfills') - .text() - const parsedData = JSON.parse(data) - - expect(parsedData.vm).toBe(105) - expect(parsedData.hash).toBe( - 'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9' - ) - expect(parsedData.buffer).toBe('hello world') - expect(parsedData.stream).toBe(true) - expect(parsedData.assert).toBe(true) - expect(parsedData.constants).toBe(7) - expect(parsedData.domain).toBe(true) - expect(parsedData.http).toBe(true) - expect(parsedData.https).toBe(true) - expect(parsedData.os).toBe('\n') - expect(parsedData.path).toBe('/hello/world/test.txt') - expect(parsedData.process).toBe('browser') - expect(parsedData.querystring).toBe('a=b') - expect(parsedData.stringDecoder).toBe(true) - expect(parsedData.sys).toBe(true) - expect(parsedData.timers).toBe(true) - }) - dynamic(context, (p, q) => renderViaHTTP(context.appPort, p, q)) hmr(context, (p, q) => renderViaHTTP(context.appPort, p, q)) errorRecovery(context, (p, q) => renderViaHTTP(context.appPort, p, q)) diff --git a/test/integration/polyfill-node-modules/next.config.js b/test/integration/polyfill-node-modules/next.config.js new file mode 100644 index 0000000000000..cc17cf48c578f --- /dev/null +++ b/test/integration/polyfill-node-modules/next.config.js @@ -0,0 +1,6 @@ +module.exports = { + onDemandEntries: { + // Make sure entries are not getting disposed. + maxInactiveAge: 1000 * 60 * 60, + }, +} diff --git a/test/integration/basic/pages/node-browser-polyfills.js b/test/integration/polyfill-node-modules/pages/node-browser-polyfills.js similarity index 100% rename from test/integration/basic/pages/node-browser-polyfills.js rename to test/integration/polyfill-node-modules/pages/node-browser-polyfills.js diff --git a/test/integration/polyfill-node-modules/test/index.test.js b/test/integration/polyfill-node-modules/test/index.test.js new file mode 100644 index 0000000000000..c10aa4b488c19 --- /dev/null +++ b/test/integration/polyfill-node-modules/test/index.test.js @@ -0,0 +1,49 @@ +/* eslint-env jest */ + +import { join } from 'path' +import webdriver from 'next-webdriver' +import { findPort, launchApp, killApp } from 'next-test-utils' + +jest.setTimeout(1000 * 60 * 2) + +const appDir = join(__dirname, '../') +let appPort +let app + +describe('Basic Features', () => { + beforeAll(async () => { + appPort = await findPort() + app = await launchApp(appDir, appPort) + }) + afterAll(() => killApp(app)) + + it('should polyfill Node.js modules', async () => { + const browser = await webdriver(appPort, '/node-browser-polyfills') + + await browser.waitForCondition('window.didRender') + + const data = await browser + .waitForElementByCss('#node-browser-polyfills') + .text() + const parsedData = JSON.parse(data) + + expect(parsedData.vm).toBe(105) + expect(parsedData.hash).toBe( + 'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9' + ) + expect(parsedData.buffer).toBe('hello world') + expect(parsedData.stream).toBe(true) + expect(parsedData.assert).toBe(true) + expect(parsedData.constants).toBe(7) + expect(parsedData.domain).toBe(true) + expect(parsedData.http).toBe(true) + expect(parsedData.https).toBe(true) + expect(parsedData.os).toBe('\n') + expect(parsedData.path).toBe('/hello/world/test.txt') + expect(parsedData.process).toBe('browser') + expect(parsedData.querystring).toBe('a=b') + expect(parsedData.stringDecoder).toBe(true) + expect(parsedData.sys).toBe(true) + expect(parsedData.timers).toBe(true) + }) +}) From 4a840b3797df5b456c6d520243505cc30d9488be Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Thu, 24 Jun 2021 12:35:36 -0500 Subject: [PATCH 2/2] update test --- test/integration/basic/test/index.test.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/test/integration/basic/test/index.test.js b/test/integration/basic/test/index.test.js index e94c48e373f69..ee09fae3a2a02 100644 --- a/test/integration/basic/test/index.test.js +++ b/test/integration/basic/test/index.test.js @@ -20,16 +20,6 @@ describe('Basic Features', () => { context.server = await launchApp(join(__dirname, '../'), context.appPort, { env: { __NEXT_TEST_WITH_DEVTOOL: 1 }, }) - - // pre-build all pages at the start - await Promise.all([ - renderViaHTTP(context.appPort, '/process-env'), - - renderViaHTTP(context.appPort, '/hmr/about'), - renderViaHTTP(context.appPort, '/hmr/style'), - renderViaHTTP(context.appPort, '/hmr/contact'), - renderViaHTTP(context.appPort, '/hmr/counter'), - ]) }) afterAll(() => killApp(context.server))