Unverified Commit de4f2f03 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Enable more tests for Turbopack, II (#83600)

parent db2c7bf7
...@@ -2,7 +2,7 @@ import { join } from 'path' ...@@ -2,7 +2,7 @@ import { join } from 'path'
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { assertNoRedbox } from 'next-test-utils' import { assertNoRedbox } from 'next-test-utils'
// Skipped in Turbopack, will be added later. // This is implemented in Turbopack, but Turbopack doesn't log the module count.
;(process.env.IS_TURBOPACK_TEST ? describe.skip : describe)( ;(process.env.IS_TURBOPACK_TEST ? describe.skip : describe)(
'Skipped in Turbopack', 'Skipped in Turbopack',
() => { () => {
......
import { join } from 'path' import { join } from 'path'
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
// Skipped in Turbopack, will be added later.
// This is implemented in Turbopack, but Turbopack doesn't log the module count.
;(process.env.IS_TURBOPACK_TEST ? describe.skip : describe)( ;(process.env.IS_TURBOPACK_TEST ? describe.skip : describe)(
'Skipped in Turbopack', 'Skipped in Turbopack',
() => { () => {
......
...@@ -6,53 +6,48 @@ import { retry } from 'next-test-utils' ...@@ -6,53 +6,48 @@ import { retry } from 'next-test-utils'
// TODO: Somehow the warning doesn't show up with Turbopack, even though the transform is not enabled. // TODO: Somehow the warning doesn't show up with Turbopack, even though the transform is not enabled.
// TODO: It no longer shows up with Webpack either in tests. // TODO: It no longer shows up with Webpack either in tests.
;(process.env.IS_TURBOPACK_TEST ? describe.skip : describe.skip)( describe.skip('styled-components SWC transform', () => {
'styled-components SWC transform', let next: NextInstance
() => {
let next: NextInstance
beforeAll(async () => { beforeAll(async () => {
next = await createNext({ next = await createNext({
files: { files: {
'next.config.js': new FileRef( 'next.config.js': new FileRef(
join(__dirname, 'styled-components-disabled/next.config.js') join(__dirname, 'styled-components-disabled/next.config.js')
), ),
pages: new FileRef( pages: new FileRef(join(__dirname, 'styled-components-disabled/pages')),
join(__dirname, 'styled-components-disabled/pages') },
), dependencies: {
}, 'styled-components': '6.1.16',
dependencies: { },
'styled-components': '6.1.16',
},
})
}) })
afterAll(() => next.destroy()) })
afterAll(() => next.destroy())
it('should have hydration mismatch with styled-components transform disabled', async () => { it('should have hydration mismatch with styled-components transform disabled', async () => {
let browser let browser
try { try {
// Compile /_error // Compile /_error
browser = await webdriver(next.url, '/404') browser = await webdriver(next.url, '/404')
await browser.loadPage(new URL('/', next.url).toString()) await browser.loadPage(new URL('/', next.url).toString())
await retry(async () => { await retry(async () => {
const logs = await browser.log() const logs = await browser.log()
expect(logs).toEqual( expect(logs).toEqual(
expect.arrayContaining([ expect.arrayContaining([
{ {
message: expect.stringContaining( message: expect.stringContaining(
'https://react.dev/link/hydration-mismatch' 'https://react.dev/link/hydration-mismatch'
), ),
source: 'error', source: 'error',
}, },
]) ])
) )
}) })
} finally { } finally {
if (browser) { if (browser) {
await browser.close() await browser.close()
}
} }
}) }
} })
) })
...@@ -55,34 +55,30 @@ describe('use-cache', () => { ...@@ -55,34 +55,30 @@ describe('use-cache', () => {
expect(await browser.waitForElementByCss('#r').text()).toContain('rnd') expect(await browser.waitForElementByCss('#r').text()).toContain('rnd')
}) })
if (!process.env.TURBOPACK_BUILD) { it('should cache results custom handler', async () => {
it('should cache results custom handler', async () => { const browser = await next.browser(`/custom-handler?n=1`)
const browser = await next.browser(`/custom-handler?n=1`) expect(await browser.waitForElementByCss('#x').text()).toBe('1')
expect(await browser.waitForElementByCss('#x').text()).toBe('1') const random1a = await browser.waitForElementByCss('#y').text()
const random1a = await browser.waitForElementByCss('#y').text()
await browser.loadPage(
new URL(`/custom-handler?n=2`, next.url).toString()
)
expect(await browser.waitForElementByCss('#x').text()).toBe('2')
const random2 = await browser.waitForElementByCss('#y').text()
await browser.loadPage( await browser.loadPage(new URL(`/custom-handler?n=2`, next.url).toString())
new URL(`/custom-handler?n=1&unrelated`, next.url).toString() expect(await browser.waitForElementByCss('#x').text()).toBe('2')
) const random2 = await browser.waitForElementByCss('#y').text()
expect(await browser.waitForElementByCss('#x').text()).toBe('1')
const random1b = await browser.waitForElementByCss('#y').text()
// The two navigations to n=1 should use a cached value. await browser.loadPage(
expect(random1a).toBe(random1b) new URL(`/custom-handler?n=1&unrelated`, next.url).toString()
)
expect(await browser.waitForElementByCss('#x').text()).toBe('1')
const random1b = await browser.waitForElementByCss('#y').text()
// The navigation to n=2 should be some other random value. // The two navigations to n=1 should use a cached value.
expect(random1a).not.toBe(random2) expect(random1a).toBe(random1b)
// Client component child should have rendered but not invalidated the cache. // The navigation to n=2 should be some other random value.
expect(await browser.waitForElementByCss('#r').text()).toContain('rnd') expect(random1a).not.toBe(random2)
})
} // Client component child should have rendered but not invalidated the cache.
expect(await browser.waitForElementByCss('#r').text()).toContain('rnd')
})
it('should cache complex args', async () => { it('should cache complex args', async () => {
// Use two bytes that can't be encoded as UTF-8 to ensure serialization works. // Use two bytes that can't be encoded as UTF-8 to ensure serialization works.
......
...@@ -6,6 +6,7 @@ import io from 'socket.io-client' ...@@ -6,6 +6,7 @@ import io from 'socket.io-client'
let socket let socket
export default function Home() { export default function Home() {
const [connected, setConnected] = useState(false)
const [value, setValue] = useState('') const [value, setValue] = useState('')
const socketInitializer = async () => { const socketInitializer = async () => {
...@@ -26,7 +27,10 @@ export default function Home() { ...@@ -26,7 +27,10 @@ export default function Home() {
} }
const sendMessageHandler = async (e) => { const sendMessageHandler = async (e) => {
if (!socket) return if (!socket) {
console.error('No socket connection yet for message')
return
}
const value = e.target.value const value = e.target.value
setValue(value) setValue(value)
...@@ -34,8 +38,15 @@ export default function Home() { ...@@ -34,8 +38,15 @@ export default function Home() {
} }
useEffect(() => { useEffect(() => {
socketInitializer() socketInitializer().then(() => {
setConnected(true)
})
}, []) }, [])
return <input value={value} onChange={sendMessageHandler} /> return (
<>
<span id="status">{connected ? 'Connected' : 'Disconnected'}</span>
<input value={value} onChange={sendMessageHandler} />
</>
)
} }
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { check } from 'next-test-utils' import { retry } from 'next-test-utils'
describe('socket-io', () => { describe('socket-io', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
...@@ -27,17 +27,32 @@ describe('socket-io', () => { ...@@ -27,17 +27,32 @@ describe('socket-io', () => {
}, },
}) })
await Promise.all([
retry(async () =>
expect(await browser1.elementByCss('#status').text()).toBe('Connected')
),
retry(async () =>
expect(await browser2.elementByCss('#status').text()).toBe('Connected')
),
])
const input1 = await browser1.elementByCss('input') const input1 = await browser1.elementByCss('input')
const input2 = await browser2.elementByCss('input') const input2 = await browser2.elementByCss('input')
await input1.fill('hello world') await input1.fill('hello world')
await check(() => input2.inputValue(), /hello world/) await retry(
async () => expect(await input2.inputValue()).toContain('hello world'),
10000
)
expect(requestsCount).toBeGreaterThan(0) expect(requestsCount).toBeGreaterThan(0)
const currentRequestsCount = requestsCount const currentRequestsCount = requestsCount
await input1.fill('123456') await input1.fill('123456')
await check(() => input2.inputValue(), /123456/) await retry(
async () => expect(await input2.inputValue()).toContain('123456'),
10000
)
// There should be no new requests (polling) and using the existing WS connection // There should be no new requests (polling) and using the existing WS connection
expect(requestsCount).toBe(currentRequestsCount) expect(requestsCount).toBe(currentRequestsCount)
......
process.env.TEST_NODE_MIDDLEWARE = '1' process.env.TEST_NODE_MIDDLEWARE = '1'
if (process.env.IS_TURBOPACK_TEST) { require('./required-server-files.test')
it('should skip for now', () => {})
} else {
require('./required-server-files.test')
}
...@@ -377,29 +377,35 @@ describe('required server files', () => { ...@@ -377,29 +377,35 @@ describe('required server files', () => {
).toContain('"cacheMaxMemorySize":0') ).toContain('"cacheMaxMemorySize":0')
}) })
// TODO(mischnic) do these files even exist in turbopack? it('should output middleware correctly', async () => {
;(process.env.IS_TURBOPACK_TEST ? it.skip : it)( if (process.env.TEST_NODE_MIDDLEWARE) {
'should output middleware correctly',
async () => {
if (!process.env.TEST_NODE_MIDDLEWARE) {
// eslint-disable-next-line jest/no-standalone-expect
expect(
await fs.pathExists(
join(
next.testDir,
'standalone/.next/server/edge-runtime-webpack.js'
)
)
).toBe(true)
}
// eslint-disable-next-line jest/no-standalone-expect
expect( expect(
await fs.pathExists( await fs.pathExists(
join(next.testDir, 'standalone/.next/server/middleware.js') join(next.testDir, 'standalone/.next/server/middleware.js')
) )
).toBe(true) ).toBe(true)
} else {
let manifest = await fs.readJSON(
join(next.testDir, 'standalone/.next/server/middleware-manifest.json')
)
let middleware = manifest.middleware['/']
let files = [
...middleware.files,
...middleware.wasm.map((f) => f.filePath),
...middleware.assets.map((f) => f.filePath),
]
console.log(files)
for (const file of files) {
try {
expect(
await fs.pathExists(join(next.testDir, 'standalone/.next', file))
).toBe(true)
} catch (err) {
throw new Error('Missing file ' + file)
}
}
} }
) })
it('should output required-server-files manifest correctly', async () => { it('should output required-server-files manifest correctly', async () => {
expect(requiredFilesManifest.version).toBe(1) expect(requiredFilesManifest.version).toBe(1)
......
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