Skip to content

Commit

Permalink
workaround test
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed May 10, 2024
1 parent 0e73a58 commit 6eb4adc
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions test/e2e/module-layer/module-layer.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'
import { getRedboxSource, hasRedbox, retry } from 'next-test-utils'

describe('module layer', () => {
const { next, isNextStart, isNextDev } = nextTestSetup({
const { next, isNextStart, isNextDev, isTurbopack } = nextTestSetup({
files: __dirname,
})

@@ -65,8 +65,12 @@ describe('module layer', () => {
const middlewareFile = 'middleware.js'
let middlewareContent = ''

beforeAll(async () => {
await next.stop()
afterAll(async () => {
await next.patchFile(middlewareFile, middlewareContent)
})

it('should error when import server packages in middleware', async () => {
const browser = await next.browser('/')

middlewareContent = await next.readFile(middlewareFile)

@@ -77,21 +81,22 @@ describe('module layer', () => {
.replace("// import './lib/mixed-lib'", "import './lib/mixed-lib'")
)

await next.start()
})
afterAll(async () => {
await next.patchFile(middlewareFile, middlewareContent)
})

it('should error when import server packages in middleware', async () => {
const existingCliOutputLength = next.cliOutput.length
await next.fetch('/')
await retry(async () => {
expect(await hasRedbox(browser)).toBe(true)
const source = await getRedboxSource(browser)
expect(source).toContain(
`'client-only' cannot be imported from a Server Component module. It should only be used from a Client Component.`
)
})

const newCliOutput = next.cliOutput.slice(existingCliOutputLength)
expect(newCliOutput).toContain('./middleware.js')
expect(newCliOutput).toContain(
`'client-only' cannot be imported from a Server Component module. It should only be used from a Client Component`
)
if (!isTurbopack) {
const newCliOutput = next.cliOutput.slice(existingCliOutputLength)
expect(newCliOutput).toContain('./middleware.js')
expect(newCliOutput).toContain(
`'client-only' cannot be imported from a Server Component module. It should only be used from a Client Component`
)
}
})
})

0 comments on commit 6eb4adc

Please sign in to comment.