Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate node polyfill test from basic suite #26550

Merged
merged 5 commits into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 0 additions & 46 deletions test/integration/basic/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -21,54 +20,9 @@ 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))

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))
Expand Down
6 changes: 6 additions & 0 deletions test/integration/polyfill-node-modules/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
onDemandEntries: {
// Make sure entries are not getting disposed.
maxInactiveAge: 1000 * 60 * 60,
},
}
49 changes: 49 additions & 0 deletions test/integration/polyfill-node-modules/test/index.test.js
Original file line number Diff line number Diff line change
@@ -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)
})
})