1- import fs from "node:fs" ;
21import path from "node:path" ;
32import { platform } from "node:process" ;
43import { fileURLToPath } from "node:url" ;
54import { fetch } from "undici" ;
65import { afterAll , beforeAll , describe , expect , test } from "vitest" ;
6+ import workerdPath from "workerd" ;
77import { runWranglerDev } from "../../../fixtures/shared/src/run-wrangler-long-lived" ;
88import { TESTS } from "./worker/index" ;
99
1010// Root of the current package
1111const pkgDir = path . resolve ( fileURLToPath ( import . meta. url ) , "../.." ) ;
12- // workerd binary
13- const localWorkerdPath = path . join ( pkgDir , "node_modules/.bin/workerd" ) ;
1412// Base path for resolving `@cloudflare/unenv-preset` files
1513const localPresetResolveBaseDir = path . join ( pkgDir , "package.json" ) ;
1614// Base path for resolving `unjs/unenv` files
@@ -19,46 +17,41 @@ const localUnenvResolveBaseDir = path.join(
1917 "node_modules/unenv/package.json"
2018) ;
2119
22- // `runWranglerDev` + `MINIFLARE_WORKERD_PATH` is not supported on Windows
23- // See https://github.com/nodejs/node/issues/52554
24- describe . skipIf ( platform === "win32" ) (
25- `@cloudflare/unenv-preset ${ platform } ${ localWorkerdPath } ${ fs . existsSync ( localWorkerdPath ) } ` ,
26- ( ) => {
27- let wrangler : Awaited < ReturnType < typeof runWranglerDev > > | undefined ;
20+ describe ( `@cloudflare/unenv-preset ${ platform } ${ workerdPath } ` , ( ) => {
21+ let wrangler : Awaited < ReturnType < typeof runWranglerDev > > | undefined ;
2822
29- beforeAll ( async ( ) => {
30- // Use workerd binary install in `@cloudflare/unenv-preset`
31- // rather than the one bundled with wrangler.
32- const MINIFLARE_WORKERD_PATH = localWorkerdPath ;
23+ beforeAll ( async ( ) => {
24+ // Use workerd binary install in `@cloudflare/unenv-preset`
25+ // rather than the one bundled with wrangler.
26+ const MINIFLARE_WORKERD_PATH = workerdPath ;
3327
34- // Use the preset from the local `@cloudflare/unenv-preset` and `unjs/unenv`
35- // rather than the one bundled with wrangler.
36- const WRANGLER_UNENV_RESOLVE_PATHS = [
37- localPresetResolveBaseDir ,
38- localUnenvResolveBaseDir ,
39- ] . join ( "," ) ;
28+ // Use the preset from the local `@cloudflare/unenv-preset` and `unjs/unenv`
29+ // rather than the one bundled with wrangler.
30+ const WRANGLER_UNENV_RESOLVE_PATHS = [
31+ localPresetResolveBaseDir ,
32+ localUnenvResolveBaseDir ,
33+ ] . join ( "," ) ;
4034
41- wrangler = await runWranglerDev (
42- path . join ( __dirname , "worker" ) ,
43- [ "--port=0" , "--inspector-port=0" ] ,
44- {
45- MINIFLARE_WORKERD_PATH ,
46- WRANGLER_UNENV_RESOLVE_PATHS ,
47- }
48- ) ;
49- } ) ;
35+ wrangler = await runWranglerDev (
36+ path . join ( __dirname , "worker" ) ,
37+ [ "--port=0" , "--inspector-port=0" ] ,
38+ {
39+ MINIFLARE_WORKERD_PATH ,
40+ WRANGLER_UNENV_RESOLVE_PATHS ,
41+ }
42+ ) ;
43+ } ) ;
5044
51- afterAll ( async ( ) => {
52- await wrangler ?. stop ( ) ;
53- wrangler = undefined ;
54- } ) ;
45+ afterAll ( async ( ) => {
46+ await wrangler ?. stop ( ) ;
47+ wrangler = undefined ;
48+ } ) ;
5549
56- test . for ( Object . keys ( TESTS ) ) ( "%s" , async ( testName ) => {
57- expect ( wrangler ) . toBeDefined ( ) ;
58- const { ip, port } = wrangler ! ;
59- const response = await fetch ( `http://${ ip } :${ port } /${ testName } ` ) ;
60- const body = await response . text ( ) ;
61- expect ( body ) . toMatch ( "OK!" ) ;
62- } ) ;
63- }
64- ) ;
50+ test . for ( Object . keys ( TESTS ) ) ( "%s" , async ( testName ) => {
51+ expect ( wrangler ) . toBeDefined ( ) ;
52+ const { ip, port } = wrangler ! ;
53+ const response = await fetch ( `http://${ ip } :${ port } /${ testName } ` ) ;
54+ const body = await response . text ( ) ;
55+ expect ( body ) . toMatch ( "OK!" ) ;
56+ } ) ;
57+ } ) ;
0 commit comments