Skip to content

Commit d257ef4

Browse files
authored
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
1 parent 6eb6e30 commit d257ef4

File tree

2 files changed

+84
-62
lines changed

2 files changed

+84
-62
lines changed

.github/workflows/build_test_deploy.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ jobs:
183183
needs: build
184184
env:
185185
HEADLESS: true
186-
BROWSERNAME: 'firefox'
186+
BROWSER_NAME: 'firefox'
187187
NEXT_TELEMETRY_DISABLED: 1
188188
steps:
189189
- uses: actions/cache@v2
@@ -201,7 +201,7 @@ jobs:
201201
needs: build
202202
env:
203203
BROWSERSTACK: true
204-
BROWSERNAME: 'safari'
204+
BROWSER_NAME: 'safari'
205205
NEXT_TELEMETRY_DISABLED: 1
206206
SKIP_LOCAL_SELENIUM_SERVER: true
207207
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
@@ -223,7 +223,7 @@ jobs:
223223
env:
224224
BROWSERSTACK: true
225225
LEGACY_SAFARI: true
226-
BROWSERNAME: 'safari'
226+
BROWSER_NAME: 'safari'
227227
NEXT_TELEMETRY_DISABLED: 1
228228
SKIP_LOCAL_SELENIUM_SERVER: true
229229
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}

test/integration/production/test/index.test.js

Lines changed: 81 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ const context = {}
4040
describe('Production Usage', () => {
4141
let output = ''
4242
beforeAll(async () => {
43+
if (process.env.NEXT_PRIVATE_TEST_WEBPACK4_MODE) {
44+
await fs.rename(
45+
join(appDir, 'pages/static-image.js'),
46+
join(appDir, 'pages/static-image.js.bak')
47+
)
48+
}
49+
4350
const result = await runNextCommand(['build', appDir], {
4451
stderr: true,
4552
stdout: true,
@@ -60,31 +67,44 @@ describe('Production Usage', () => {
6067
server = await startApp(app)
6168
context.appPort = appPort = server.address().port
6269
})
63-
afterAll(() => stopApp(server))
70+
afterAll(async () => {
71+
if (process.env.NEXT_PRIVATE_TEST_WEBPACK4_MODE) {
72+
await fs.rename(
73+
join(appDir, 'pages/static-image.js.bak'),
74+
join(appDir, 'pages/static-image.js')
75+
)
76+
}
77+
await stopApp(server)
78+
})
6479

6580
it('should contain generated page count in output', async () => {
66-
expect(output).toContain('Generating static pages (0/38)')
67-
expect(output).toContain('Generating static pages (38/38)')
81+
const pageCount = process.env.NEXT_PRIVATE_TEST_WEBPACK4_MODE ? 37 : 38
82+
expect(output).toContain(`Generating static pages (0/${pageCount})`)
83+
expect(output).toContain(
84+
`Generating static pages (${pageCount}/${pageCount})`
85+
)
6886
// we should only have 4 segments and the initial message logged out
6987
expect(output.match(/Generating static pages/g).length).toBe(5)
7088
})
7189

72-
it('should not contain currentScript usage for publicPath', async () => {
73-
const globResult = await glob('webpack-*.js', {
74-
cwd: join(appDir, '.next/static/chunks'),
75-
})
90+
if (!process.env.NEXT_PRIVATE_TEST_WEBPACK4_MODE) {
91+
it('should not contain currentScript usage for publicPath', async () => {
92+
const globResult = await glob('webpack-*.js', {
93+
cwd: join(appDir, '.next/static/chunks'),
94+
})
7695

77-
if (!globResult || globResult.length !== 1) {
78-
throw new Error('could not find webpack-hash.js chunk')
79-
}
96+
if (!globResult || globResult.length !== 1) {
97+
throw new Error('could not find webpack-hash.js chunk')
98+
}
8099

81-
const content = await fs.readFile(
82-
join(appDir, '.next/static/chunks', globResult[0]),
83-
'utf8'
84-
)
100+
const content = await fs.readFile(
101+
join(appDir, '.next/static/chunks', globResult[0]),
102+
'utf8'
103+
)
85104

86-
expect(content).not.toContain('.currentScript')
87-
})
105+
expect(content).not.toContain('.currentScript')
106+
})
107+
}
88108

89109
describe('With basic usage', () => {
90110
it('should render the page', async () => {
@@ -917,54 +937,56 @@ describe('Production Usage', () => {
917937
expect(await browser.eval('window.location.pathname')).toBe('/non-existent')
918938
})
919939

920-
it('should remove placeholder for next/image correctly', async () => {
921-
const browser = await webdriver(context.appPort, '/')
922-
923-
await browser.eval(`(function() {
924-
window.beforeNav = 1
925-
window.next.router.push('/static-image')
926-
})()`)
927-
await browser.waitForElementByCss('#static-image')
928-
929-
expect(await browser.eval('window.beforeNav')).toBe(1)
940+
if (!process.env.NEXT_PRIVATE_TEST_WEBPACK4_MODE) {
941+
it('should remove placeholder for next/image correctly', async () => {
942+
const browser = await webdriver(context.appPort, '/')
930943

931-
await check(
932-
() => browser.elementByCss('img').getComputedCss('background-image'),
933-
'none'
934-
)
944+
await browser.eval(`(function() {
945+
window.beforeNav = 1
946+
window.next.router.push('/static-image')
947+
})()`)
948+
await browser.waitForElementByCss('#static-image')
935949

936-
await browser.eval(`(function() {
937-
window.beforeNav = 1
938-
window.next.router.push('/')
939-
})()`)
940-
await browser.waitForElementByCss('.index-page')
941-
await waitFor(1000)
950+
expect(await browser.eval('window.beforeNav')).toBe(1)
942951

943-
await browser.eval(`(function() {
944-
window.beforeNav = 1
945-
window.next.router.push('/static-image')
946-
})()`)
947-
await browser.waitForElementByCss('#static-image')
948-
949-
expect(await browser.eval('window.beforeNav')).toBe(1)
952+
await check(
953+
() => browser.elementByCss('img').getComputedCss('background-image'),
954+
'none'
955+
)
950956

951-
await check(
952-
() =>
953-
browser
954-
.elementByCss('#static-image')
955-
.getComputedCss('background-image'),
956-
'none'
957-
)
957+
await browser.eval(`(function() {
958+
window.beforeNav = 1
959+
window.next.router.push('/')
960+
})()`)
961+
await browser.waitForElementByCss('.index-page')
962+
await waitFor(1000)
963+
964+
await browser.eval(`(function() {
965+
window.beforeNav = 1
966+
window.next.router.push('/static-image')
967+
})()`)
968+
await browser.waitForElementByCss('#static-image')
969+
970+
expect(await browser.eval('window.beforeNav')).toBe(1)
971+
972+
await check(
973+
() =>
974+
browser
975+
.elementByCss('#static-image')
976+
.getComputedCss('background-image'),
977+
'none'
978+
)
958979

959-
for (let i = 0; i < 5; i++) {
960-
expect(
961-
await browser
962-
.elementByCss('#static-image')
963-
.getComputedCss('background-image')
964-
).toBe('none')
965-
await waitFor(500)
966-
}
967-
})
980+
for (let i = 0; i < 5; i++) {
981+
expect(
982+
await browser
983+
.elementByCss('#static-image')
984+
.getComputedCss('background-image')
985+
).toBe('none')
986+
await waitFor(500)
987+
}
988+
})
989+
}
968990

969991
dynamicImportTests(context, (p, q) => renderViaHTTP(context.appPort, p, q))
970992

0 commit comments

Comments
 (0)