Unverified Commit d257ef40 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

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
parent 6eb6e302
...@@ -183,7 +183,7 @@ jobs: ...@@ -183,7 +183,7 @@ jobs:
needs: build needs: build
env: env:
HEADLESS: true HEADLESS: true
BROWSERNAME: 'firefox' BROWSER_NAME: 'firefox'
NEXT_TELEMETRY_DISABLED: 1 NEXT_TELEMETRY_DISABLED: 1
steps: steps:
- uses: actions/cache@v2 - uses: actions/cache@v2
...@@ -201,7 +201,7 @@ jobs: ...@@ -201,7 +201,7 @@ jobs:
needs: build needs: build
env: env:
BROWSERSTACK: true BROWSERSTACK: true
BROWSERNAME: 'safari' BROWSER_NAME: 'safari'
NEXT_TELEMETRY_DISABLED: 1 NEXT_TELEMETRY_DISABLED: 1
SKIP_LOCAL_SELENIUM_SERVER: true SKIP_LOCAL_SELENIUM_SERVER: true
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }} BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
...@@ -223,7 +223,7 @@ jobs: ...@@ -223,7 +223,7 @@ jobs:
env: env:
BROWSERSTACK: true BROWSERSTACK: true
LEGACY_SAFARI: true LEGACY_SAFARI: true
BROWSERNAME: 'safari' BROWSER_NAME: 'safari'
NEXT_TELEMETRY_DISABLED: 1 NEXT_TELEMETRY_DISABLED: 1
SKIP_LOCAL_SELENIUM_SERVER: true SKIP_LOCAL_SELENIUM_SERVER: true
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }} BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
......
...@@ -40,6 +40,13 @@ const context = {} ...@@ -40,6 +40,13 @@ const context = {}
describe('Production Usage', () => { describe('Production Usage', () => {
let output = '' let output = ''
beforeAll(async () => { 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], { const result = await runNextCommand(['build', appDir], {
stderr: true, stderr: true,
stdout: true, stdout: true,
...@@ -60,31 +67,44 @@ describe('Production Usage', () => { ...@@ -60,31 +67,44 @@ describe('Production Usage', () => {
server = await startApp(app) server = await startApp(app)
context.appPort = appPort = server.address().port 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 () => { it('should contain generated page count in output', async () => {
expect(output).toContain('Generating static pages (0/38)') const pageCount = process.env.NEXT_PRIVATE_TEST_WEBPACK4_MODE ? 37 : 38
expect(output).toContain('Generating static pages (38/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 // we should only have 4 segments and the initial message logged out
expect(output.match(/Generating static pages/g).length).toBe(5) expect(output.match(/Generating static pages/g).length).toBe(5)
}) })
it('should not contain currentScript usage for publicPath', async () => { if (!process.env.NEXT_PRIVATE_TEST_WEBPACK4_MODE) {
const globResult = await glob('webpack-*.js', { it('should not contain currentScript usage for publicPath', async () => {
cwd: join(appDir, '.next/static/chunks'), const globResult = await glob('webpack-*.js', {
}) cwd: join(appDir, '.next/static/chunks'),
})
if (!globResult || globResult.length !== 1) { if (!globResult || globResult.length !== 1) {
throw new Error('could not find webpack-hash.js chunk') throw new Error('could not find webpack-hash.js chunk')
} }
const content = await fs.readFile( const content = await fs.readFile(
join(appDir, '.next/static/chunks', globResult[0]), join(appDir, '.next/static/chunks', globResult[0]),
'utf8' 'utf8'
) )
expect(content).not.toContain('.currentScript') expect(content).not.toContain('.currentScript')
}) })
}
describe('With basic usage', () => { describe('With basic usage', () => {
it('should render the page', async () => { it('should render the page', async () => {
...@@ -917,54 +937,56 @@ describe('Production Usage', () => { ...@@ -917,54 +937,56 @@ describe('Production Usage', () => {
expect(await browser.eval('window.location.pathname')).toBe('/non-existent') expect(await browser.eval('window.location.pathname')).toBe('/non-existent')
}) })
it('should remove placeholder for next/image correctly', async () => { if (!process.env.NEXT_PRIVATE_TEST_WEBPACK4_MODE) {
const browser = await webdriver(context.appPort, '/') 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)
await check( await browser.eval(`(function() {
() => browser.elementByCss('img').getComputedCss('background-image'), window.beforeNav = 1
'none' window.next.router.push('/static-image')
) })()`)
await browser.waitForElementByCss('#static-image')
await browser.eval(`(function() { expect(await browser.eval('window.beforeNav')).toBe(1)
window.beforeNav = 1
window.next.router.push('/')
})()`)
await browser.waitForElementByCss('.index-page')
await waitFor(1000)
await browser.eval(`(function() { await check(
window.beforeNav = 1 () => browser.elementByCss('img').getComputedCss('background-image'),
window.next.router.push('/static-image') 'none'
})()`) )
await browser.waitForElementByCss('#static-image')
expect(await browser.eval('window.beforeNav')).toBe(1)
await check( await browser.eval(`(function() {
() => window.beforeNav = 1
browser window.next.router.push('/')
.elementByCss('#static-image') })()`)
.getComputedCss('background-image'), await browser.waitForElementByCss('.index-page')
'none' 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++) { for (let i = 0; i < 5; i++) {
expect( expect(
await browser await browser
.elementByCss('#static-image') .elementByCss('#static-image')
.getComputedCss('background-image') .getComputedCss('background-image')
).toBe('none') ).toBe('none')
await waitFor(500) await waitFor(500)
} }
}) })
}
dynamicImportTests(context, (p, q) => renderViaHTTP(context.appPort, p, q)) dynamicImportTests(context, (p, q) => renderViaHTTP(context.appPort, p, q))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment