Skip to content

Commit e8fa2d0

Browse files
authored
test(rsc): test build with NODE_ENV=development and vice versa (#606)
1 parent cadd7d2 commit e8fa2d0

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

packages/plugin-rsc/e2e/basic.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import { createHash } from 'node:crypto'
22
import { readFileSync } from 'node:fs'
33
import { type Page, expect, test } from '@playwright/test'
44
import { type Fixture, setupIsolatedFixture, useFixture } from './fixture'
5-
import { expectNoReload, testNoJs, waitForHydration } from './helper'
5+
import {
6+
expectNoPageError,
7+
expectNoReload,
8+
testNoJs,
9+
waitForHydration,
10+
} from './helper'
611
import path from 'node:path'
712
import os from 'node:os'
813

@@ -73,6 +78,7 @@ test.describe(() => {
7378

7479
function defineTest(f: Fixture) {
7580
test('basic', async ({ page }) => {
81+
using _ = expectNoPageError(page)
7682
await page.goto(f.url())
7783
await waitForHydration(page)
7884
})

packages/plugin-rsc/e2e/starter.test.ts

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { expect, test } from '@playwright/test'
22
import { setupInlineFixture, type Fixture, useFixture } from './fixture'
33
import {
4+
expectNoPageError,
45
expectNoReload,
56
testNoJs,
67
waitForHydration as waitForHydration_,
@@ -42,6 +43,48 @@ test.describe('build-no-ssr', () => {
4243
})
4344
})
4445

46+
test.describe('dev-production', () => {
47+
const f = useFixture({
48+
root: 'examples/starter',
49+
mode: 'dev',
50+
cliOptions: {
51+
env: { NODE_ENV: 'production' },
52+
},
53+
})
54+
defineTest(f, 'dev-production')
55+
56+
test('verify production', async ({ page }) => {
57+
await page.goto(f.url())
58+
await waitForHydration_(page)
59+
const res = await page.request.get(f.url('src/client.tsx'))
60+
expect(await res.text()).not.toContain('jsxDEV')
61+
})
62+
})
63+
64+
test.describe('build-development', () => {
65+
const f = useFixture({
66+
root: 'examples/starter',
67+
mode: 'build',
68+
cliOptions: {
69+
env: { NODE_ENV: 'development' },
70+
},
71+
})
72+
defineTest(f)
73+
74+
test('verify development', async ({ page }) => {
75+
let output!: string
76+
page.on('response', async (response) => {
77+
if (response.url().match(/\/assets\/client-[\w-]+\.js$/)) {
78+
output = await response.text()
79+
}
80+
})
81+
await page.goto(f.url())
82+
await waitForHydration_(page)
83+
console.log({ output })
84+
expect(output).toContain('jsxDEV')
85+
})
86+
})
87+
4588
test.describe(() => {
4689
const root = 'examples/e2e/temp/react-compiler'
4790

@@ -203,11 +246,12 @@ test.describe(() => {
203246
})
204247
})
205248

206-
function defineTest(f: Fixture, variant?: 'no-ssr') {
249+
function defineTest(f: Fixture, variant?: 'no-ssr' | 'dev-production') {
207250
const waitForHydration: typeof waitForHydration_ = (page) =>
208251
waitForHydration_(page, variant === 'no-ssr' ? '#root' : 'body')
209252

210253
test('basic', async ({ page }) => {
254+
using _ = expectNoPageError(page)
211255
await page.goto(f.url())
212256
await waitForHydration(page)
213257
})
@@ -242,7 +286,7 @@ function defineTest(f: Fixture, variant?: 'no-ssr') {
242286
})
243287

244288
test('client hmr', async ({ page }) => {
245-
test.skip(f.mode === 'build')
289+
test.skip(f.mode === 'build' || variant === 'dev-production')
246290

247291
await page.goto(f.url())
248292
await waitForHydration(page)

0 commit comments

Comments
 (0)