Skip to content

Commit 5336438

Browse files
committed
chore: sync tests
1 parent 6ae9a61 commit 5336438

7 files changed

Lines changed: 174 additions & 24 deletions

test/e2e-not-nuxt/cloudflare-satori.test.ts

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import { globby } from 'globby'
66
import { $fetch } from 'ofetch'
77
import { exec } from 'tinyexec'
88
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
9-
import { extractOgImageUrl, setupImageSnapshots, SNAPSHOT_STRICT } from '../utils'
9+
import { ensureLocalModuleStub, extractOgImageUrl, getWranglerTestEnv, isWranglerRuntimeUnsupportedError, readLatestWranglerLog, setupImageSnapshots, SNAPSHOT_STRICT } from '../utils'
1010

1111
const { resolve } = createResolver(import.meta.url)
1212
const fixtureDir = resolve('../fixtures/cloudflare-satori')
13+
const wranglerEnvName = 'cloudflare-satori'
1314

1415
setupImageSnapshots(SNAPSHOT_STRICT)
1516

@@ -27,7 +28,11 @@ catch {
2728
// Check if wrangler is available
2829
let hasWrangler = false
2930
try {
30-
await exec('wrangler', ['--version'])
31+
await exec('wrangler', ['--version'], {
32+
nodeOptions: {
33+
env: getWranglerTestEnv(process.env, wranglerEnvName),
34+
},
35+
})
3136
hasWrangler = true
3237
}
3338
catch {
@@ -36,11 +41,14 @@ catch {
3641

3742
const canRunTests = hasSatoriDeps && hasWrangler
3843
const isCI = !!process.env.CI
44+
const hasSandboxedRuntime = !!process.env.CODEX_SANDBOX_NETWORK_DISABLED || !!process.env.NUXT_OG_IMAGE_SKIP_EDGE_RUNTIME
3945

4046
let wranglerProcess: ChildProcess | null = null
4147
let serverUrl = ''
48+
let skipWranglerRuntime = false
4249

4350
async function buildFixture() {
51+
await ensureLocalModuleStub()
4452
await exec('nuxt', ['build'], {
4553
nodeOptions: {
4654
cwd: fixtureDir,
@@ -51,28 +59,48 @@ async function buildFixture() {
5159

5260
async function startWrangler(): Promise<string> {
5361
return new Promise((resolve, reject) => {
62+
let settled = false
5463
const proc = spawn('wrangler', ['dev', '--port', '8789'], {
5564
cwd: fixtureDir,
65+
env: {
66+
...getWranglerTestEnv(process.env, wranglerEnvName),
67+
CI: '1',
68+
},
5669
stdio: ['ignore', 'pipe', 'pipe'],
5770
})
5871

5972
wranglerProcess = proc
6073
let output = ''
74+
const finish = (value: string) => {
75+
if (settled)
76+
return
77+
settled = true
78+
resolve(value)
79+
}
80+
const fail = (message: string) => {
81+
if (settled)
82+
return
83+
settled = true
84+
reject(new Error(`Wrangler failed to start: ${message}`))
85+
}
6186

6287
proc.stdout?.on('data', (data) => {
6388
output += data.toString()
6489
const match = output.match(/Ready on (http:\/\/\S+)/)
65-
if (match?.[1]) {
66-
resolve(match[1])
67-
}
90+
if (match?.[1])
91+
finish(match[1])
6892
})
6993

7094
proc.stderr?.on('data', (data) => {
7195
output += data.toString()
7296
})
7397

74-
proc.on('error', reject)
75-
setTimeout(() => reject(new Error(`Wrangler failed to start: ${output}`)), 30000)
98+
proc.on('error', error => fail(`${output}\n${error.message}`.trim()))
99+
proc.on('close', async (code) => {
100+
if (!settled && code)
101+
fail([output, await readLatestWranglerLog(wranglerEnvName)].filter(Boolean).join('\n'))
102+
})
103+
setTimeout(fail, 30000, output)
76104
})
77105
}
78106

@@ -111,17 +139,29 @@ describe('cloudflare-satori', () => {
111139
})
112140
})
113141

114-
// Skip wrangler runtime in CI - inspector port 9229 conflicts with other processes
115-
describe.runIf(canRunTests && !isCI)('wrangler runtime', () => {
142+
// Skip wrangler runtime in CI or sandboxed environments where local interfaces are unavailable
143+
describe.runIf(canRunTests && !isCI && !hasSandboxedRuntime)('wrangler runtime', () => {
116144
beforeAll(async () => {
117-
serverUrl = await startWrangler()
145+
try {
146+
serverUrl = await startWrangler()
147+
}
148+
catch (error) {
149+
if (isWranglerRuntimeUnsupportedError(error)) {
150+
skipWranglerRuntime = true
151+
return
152+
}
153+
throw error
154+
}
118155
}, 60000)
119156

120157
afterAll(() => {
121158
stopWrangler()
122159
})
123160

124161
it('serves prerendered og images via wrangler', async () => {
162+
if (skipWranglerRuntime)
163+
return
164+
125165
const html = await $fetch<string>(serverUrl)
126166
const ogImagePath = extractOgImageUrl(html)
127167
expect(ogImagePath).toBeTruthy()
@@ -136,6 +176,9 @@ describe('cloudflare-satori', () => {
136176
}, 30000)
137177

138178
it('generates og images dynamically at runtime via wrangler', async () => {
179+
if (skipWranglerRuntime)
180+
return
181+
139182
const image = await $fetch(`${serverUrl}/_og/d/image?path=/`, {
140183
responseType: 'arrayBuffer' as const,
141184
})

test/e2e-not-nuxt/cloudflare-takumi.test.ts

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import { $fetch } from 'ofetch'
77
import { join } from 'pathe'
88
import { exec } from 'tinyexec'
99
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
10-
import { extractOgImageUrl, setupImageSnapshots, SNAPSHOT_STRICT } from '../utils'
10+
import { ensureLocalModuleStub, extractOgImageUrl, getWranglerTestEnv, isWranglerRuntimeUnsupportedError, readLatestWranglerLog, setupImageSnapshots, SNAPSHOT_STRICT } from '../utils'
1111

1212
const { resolve } = createResolver(import.meta.url)
1313
const fixtureDir = resolve('../fixtures/cloudflare-takumi')
14+
const wranglerEnvName = 'cloudflare-takumi'
1415

1516
setupImageSnapshots(SNAPSHOT_STRICT)
1617

@@ -28,7 +29,11 @@ catch {
2829
// Check if wrangler is available
2930
let hasWrangler = false
3031
try {
31-
await exec('wrangler', ['--version'])
32+
await exec('wrangler', ['--version'], {
33+
nodeOptions: {
34+
env: getWranglerTestEnv(process.env, wranglerEnvName),
35+
},
36+
})
3237
hasWrangler = true
3338
}
3439
catch {
@@ -37,11 +42,15 @@ catch {
3742

3843
const canRunTests = hasTakumiWasm && hasWrangler
3944
const isCI = !!process.env.CI
45+
const hasSandboxedRuntime = !!process.env.CODEX_SANDBOX_NETWORK_DISABLED || !!process.env.NUXT_OG_IMAGE_SKIP_EDGE_RUNTIME
4046

4147
let wranglerProcess: ChildProcess | null = null
4248
let serverUrl = ''
49+
let skipWranglerRuntime = false
4350

4451
async function buildFixture(retries = 2) {
52+
await ensureLocalModuleStub()
53+
4554
for (let attempt = 0; attempt <= retries; attempt++) {
4655
const result = exec('nuxt', ['build'], {
4756
nodeOptions: {
@@ -62,28 +71,48 @@ async function buildFixture(retries = 2) {
6271

6372
async function startWrangler(): Promise<string> {
6473
return new Promise((resolve, reject) => {
74+
let settled = false
6575
const proc = spawn('wrangler', ['dev', '--port', '8788'], {
6676
cwd: fixtureDir,
77+
env: {
78+
...getWranglerTestEnv(process.env, wranglerEnvName),
79+
CI: '1',
80+
},
6781
stdio: ['ignore', 'pipe', 'pipe'],
6882
})
6983

7084
wranglerProcess = proc
7185
let output = ''
86+
const finish = (value: string) => {
87+
if (settled)
88+
return
89+
settled = true
90+
resolve(value)
91+
}
92+
const fail = (message: string) => {
93+
if (settled)
94+
return
95+
settled = true
96+
reject(new Error(`Wrangler failed to start: ${message}`))
97+
}
7298

7399
proc.stdout?.on('data', (data) => {
74100
output += data.toString()
75101
const match = output.match(/Ready on (http:\/\/\S+)/)
76-
if (match?.[1]) {
77-
resolve(match[1])
78-
}
102+
if (match?.[1])
103+
finish(match[1])
79104
})
80105

81106
proc.stderr?.on('data', (data) => {
82107
output += data.toString()
83108
})
84109

85-
proc.on('error', reject)
86-
setTimeout(() => reject(new Error(`Wrangler failed to start: ${output}`)), 30000)
110+
proc.on('error', error => fail(`${output}\n${error.message}`.trim()))
111+
proc.on('close', async (code) => {
112+
if (!settled && code)
113+
fail([output, await readLatestWranglerLog(wranglerEnvName)].filter(Boolean).join('\n'))
114+
})
115+
setTimeout(fail, 30000, output)
87116
})
88117
}
89118

@@ -124,17 +153,29 @@ describe('cloudflare-takumi', () => {
124153
})
125154
})
126155

127-
// Skip wrangler runtime in CI - inspector port 9229 conflicts with other processes
128-
describe.runIf(canRunTests && !isCI)('wrangler runtime', () => {
156+
// Skip wrangler runtime in CI or sandboxed environments where local interfaces are unavailable
157+
describe.runIf(canRunTests && !isCI && !hasSandboxedRuntime)('wrangler runtime', () => {
129158
beforeAll(async () => {
130-
serverUrl = await startWrangler()
159+
try {
160+
serverUrl = await startWrangler()
161+
}
162+
catch (error) {
163+
if (isWranglerRuntimeUnsupportedError(error)) {
164+
skipWranglerRuntime = true
165+
return
166+
}
167+
throw error
168+
}
131169
}, 60000)
132170

133171
afterAll(() => {
134172
stopWrangler()
135173
})
136174

137175
it('serves og images dynamically via wrangler', async () => {
176+
if (skipWranglerRuntime)
177+
return
178+
138179
const html = await $fetch<string>(serverUrl)
139180
const ogImagePath = extractOgImageUrl(html)
140181
expect(ogImagePath).toBeTruthy()

test/e2e-not-nuxt/prerender-app.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import { createResolver } from '@nuxt/kit'
33
import { globby } from 'globby'
44
import { exec } from 'tinyexec'
55
import { describe, expect, it } from 'vitest'
6-
import { setupImageSnapshots, SNAPSHOT_STRICT } from '../utils'
6+
import { ensureLocalModuleStub, setupImageSnapshots, SNAPSHOT_STRICT } from '../utils'
77

88
const { resolve } = createResolver(import.meta.url)
99

1010
setupImageSnapshots(SNAPSHOT_STRICT)
1111

1212
describe('prerender', () => {
1313
it('basic', async () => {
14+
await ensureLocalModuleStub()
1415
await exec('nuxt', ['generate'], { nodeOptions: { cwd: resolve('../fixtures/app-dir') } })
1516
const imagePath = resolve('../fixtures/app-dir/.output/public/_og')
1617
const images = await globby('**/*.png', { cwd: imagePath }).then((r: string[]) => r.sort())

test/e2e-not-nuxt/vercel-edge-satori.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { globby } from 'globby'
44
import { $fetch } from 'ofetch'
55
import { exec } from 'tinyexec'
66
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
7-
import { setupImageSnapshots, SNAPSHOT_STRICT } from '../utils'
7+
import { ensureLocalModuleStub, setupImageSnapshots, SNAPSHOT_STRICT } from '../utils'
88

99
const { resolve } = createResolver(import.meta.url)
1010
const fixtureDir = resolve('../fixtures/vercel-edge-satori')
@@ -40,6 +40,7 @@ const vercelScope = process.env.VERCEL_SCOPE || 'my-team-47a10b37'
4040
let deploymentUrl = ''
4141

4242
async function buildFixture() {
43+
await ensureLocalModuleStub()
4344
await exec('nuxt', ['build'], {
4445
nodeOptions: {
4546
cwd: fixtureDir,

test/e2e-not-nuxt/zeroRuntimeBuild.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createResolver } from '@nuxt/kit'
33
import { globby } from 'globby'
44
import { exec } from 'tinyexec'
55
import { afterEach, describe, expect, it } from 'vitest'
6-
import { setupImageSnapshots, SNAPSHOT_STRICT } from '../utils'
6+
import { ensureLocalModuleStub, setupImageSnapshots, SNAPSHOT_STRICT } from '../utils'
77

88
const { resolve } = createResolver(import.meta.url)
99

@@ -23,6 +23,7 @@ describe('zeroRuntime', () => {
2323
})
2424

2525
it('basic', async () => {
26+
await ensureLocalModuleStub()
2627
await exec('nuxt', ['cleanup'], { nodeOptions: { cwd: fixtureDir } })
2728
await exec('nuxt', ['build'], { nodeOptions: { cwd: fixtureDir } })
2829
const serverOutputPath = resolve('../fixtures/zero-runtime/.output/server')
@@ -54,6 +55,7 @@ describe('zeroRuntime', () => {
5455
}, 120000)
5556

5657
it('local fonts in config', async () => {
58+
await ensureLocalModuleStub()
5759
originalConfig = await readFile(nuxtConfigPath, 'utf-8')
5860

5961
const modifiedConfig = originalConfig.replace(

0 commit comments

Comments
 (0)