From 0b3754ad2a4c4fc1dfeabc802fe400cb7677a0bb Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Fri, 11 Jun 2021 14:38:51 -0500 Subject: [PATCH] Ensure correct browser env is used (#26014) * Ensure correct browser env is used * Fix production suite in webpack 4 mode * fix page count on webpack 4 --- .github/workflows/build_test_deploy.yml | 6 +- .../integration/production/test/index.test.js | 140 ++++++++++-------- 2 files changed, 84 insertions(+), 62 deletions(-) diff --git a/.github/workflows/build_test_deploy.yml b/.github/workflows/build_test_deploy.yml index 9ec49756c9ed2..89b53c1815d15 100644 --- a/.github/workflows/build_test_deploy.yml +++ b/.github/workflows/build_test_deploy.yml @@ -183,7 +183,7 @@ jobs: needs: build env: HEADLESS: true - BROWSERNAME: 'firefox' + BROWSER_NAME: 'firefox' NEXT_TELEMETRY_DISABLED: 1 steps: - uses: actions/cache@v2 @@ -201,7 +201,7 @@ jobs: needs: build env: BROWSERSTACK: true - BROWSERNAME: 'safari' + BROWSER_NAME: 'safari' NEXT_TELEMETRY_DISABLED: 1 SKIP_LOCAL_SELENIUM_SERVER: true BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }} @@ -223,7 +223,7 @@ jobs: env: BROWSERSTACK: true LEGACY_SAFARI: true - BROWSERNAME: 'safari' + BROWSER_NAME: 'safari' NEXT_TELEMETRY_DISABLED: 1 SKIP_LOCAL_SELENIUM_SERVER: true BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }} diff --git a/test/integration/production/test/index.test.js b/test/integration/production/test/index.test.js index cc0bef8a6746b..06e717affcf7a 100644 --- a/test/integration/production/test/index.test.js +++ b/test/integration/production/test/index.test.js @@ -40,6 +40,13 @@ const context = {} describe('Production Usage', () => { let output = '' beforeAll(async () => { + if (process.env.NEXT_PRIVATE_TEST_WEBPACK4_MODE) { + await fs.rename( + join(appDir, 'pages/static-image.js'), + join(appDir, 'pages/static-image.js.bak') + ) + } + const result = await runNextCommand(['build', appDir], { stderr: true, stdout: true, @@ -60,31 +67,44 @@ describe('Production Usage', () => { server = await startApp(app) context.appPort = appPort = server.address().port }) - afterAll(() => stopApp(server)) + afterAll(async () => { + if (process.env.NEXT_PRIVATE_TEST_WEBPACK4_MODE) { + await fs.rename( + join(appDir, 'pages/static-image.js.bak'), + join(appDir, 'pages/static-image.js') + ) + } + await stopApp(server) + }) it('should contain generated page count in output', async () => { - expect(output).toContain('Generating static pages (0/38)') - expect(output).toContain('Generating static pages (38/38)') + const pageCount = process.env.NEXT_PRIVATE_TEST_WEBPACK4_MODE ? 37 : 38 + expect(output).toContain(`Generating static pages (0/${pageCount})`) + expect(output).toContain( + `Generating static pages (${pageCount}/${pageCount})` + ) // we should only have 4 segments and the initial message logged out expect(output.match(/Generating static pages/g).length).toBe(5) }) - it('should not contain currentScript usage for publicPath', async () => { - const globResult = await glob('webpack-*.js', { - cwd: join(appDir, '.next/static/chunks'), - }) + if (!process.env.NEXT_PRIVATE_TEST_WEBPACK4_MODE) { + it('should not contain currentScript usage for publicPath', async () => { + const globResult = await glob('webpack-*.js', { + cwd: join(appDir, '.next/static/chunks'), + }) - if (!globResult || globResult.length !== 1) { - throw new Error('could not find webpack-hash.js chunk') - } + if (!globResult || globResult.length !== 1) { + throw new Error('could not find webpack-hash.js chunk') + } - const content = await fs.readFile( - join(appDir, '.next/static/chunks', globResult[0]), - 'utf8' - ) + const content = await fs.readFile( + join(appDir, '.next/static/chunks', globResult[0]), + 'utf8' + ) - expect(content).not.toContain('.currentScript') - }) + expect(content).not.toContain('.currentScript') + }) + } describe('With basic usage', () => { it('should render the page', async () => { @@ -917,54 +937,56 @@ describe('Production Usage', () => { expect(await browser.eval('window.location.pathname')).toBe('/non-existent') }) - it('should remove placeholder for next/image correctly', async () => { - const browser = await webdriver(context.appPort, '/') - - await browser.eval(`(function() { - window.beforeNav = 1 - window.next.router.push('/static-image') - })()`) - await browser.waitForElementByCss('#static-image') - - expect(await browser.eval('window.beforeNav')).toBe(1) + if (!process.env.NEXT_PRIVATE_TEST_WEBPACK4_MODE) { + it('should remove placeholder for next/image correctly', async () => { + const browser = await webdriver(context.appPort, '/') - await check( - () => browser.elementByCss('img').getComputedCss('background-image'), - 'none' - ) + await browser.eval(`(function() { + window.beforeNav = 1 + window.next.router.push('/static-image') + })()`) + await browser.waitForElementByCss('#static-image') - await browser.eval(`(function() { - window.beforeNav = 1 - window.next.router.push('/') - })()`) - await browser.waitForElementByCss('.index-page') - await waitFor(1000) + expect(await browser.eval('window.beforeNav')).toBe(1) - await browser.eval(`(function() { - window.beforeNav = 1 - window.next.router.push('/static-image') - })()`) - await browser.waitForElementByCss('#static-image') - - expect(await browser.eval('window.beforeNav')).toBe(1) + await check( + () => browser.elementByCss('img').getComputedCss('background-image'), + 'none' + ) - await check( - () => - browser - .elementByCss('#static-image') - .getComputedCss('background-image'), - 'none' - ) + await browser.eval(`(function() { + window.beforeNav = 1 + window.next.router.push('/') + })()`) + await browser.waitForElementByCss('.index-page') + await waitFor(1000) + + await browser.eval(`(function() { + window.beforeNav = 1 + window.next.router.push('/static-image') + })()`) + await browser.waitForElementByCss('#static-image') + + expect(await browser.eval('window.beforeNav')).toBe(1) + + await check( + () => + browser + .elementByCss('#static-image') + .getComputedCss('background-image'), + 'none' + ) - for (let i = 0; i < 5; i++) { - expect( - await browser - .elementByCss('#static-image') - .getComputedCss('background-image') - ).toBe('none') - await waitFor(500) - } - }) + for (let i = 0; i < 5; i++) { + expect( + await browser + .elementByCss('#static-image') + .getComputedCss('background-image') + ).toBe('none') + await waitFor(500) + } + }) + } dynamicImportTests(context, (p, q) => renderViaHTTP(context.appPort, p, q))