Skip to content

Commit 6526517

Browse files
fix(wrangler): Update vitest config to capture .tsx tests (#6277)
Our current vitest setup targets only "**/__tests__/**/*.test.ts" files. This incorrectly excludes `.tsx` test files, such as "**/__tests__/dev.test.tsx". This commit updates the vitest config file to target such test files as well.
1 parent 957d668 commit 6526517

File tree

2 files changed

+85
-82
lines changed

2 files changed

+85
-82
lines changed

packages/wrangler/src/__tests__/dev.test.tsx

Lines changed: 84 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ describe("wrangler dev", () => {
7979
await expect(
8080
runWrangler("dev --remote index.js")
8181
).rejects.toThrowErrorMatchingInlineSnapshot(
82-
`"You must be logged in to use wrangler dev in remote mode. Try logging in, or run wrangler dev --local."`
82+
`[Error: You must be logged in to use wrangler dev in remote mode. Try logging in, or run wrangler dev --local.]`
8383
);
8484
});
8585

@@ -167,7 +167,7 @@ describe("wrangler dev", () => {
167167
await expect(
168168
runWrangler("dev")
169169
).rejects.toThrowErrorMatchingInlineSnapshot(
170-
`"Missing entry-point: The entry-point should be specified via the command line (e.g. \`wrangler dev path/to/script\`) or the \`main\` config field."`
170+
`[Error: Missing entry-point: The entry-point should be specified via the command line (e.g. \`wrangler dev path/to/script\`) or the \`main\` config field.]`
171171
);
172172

173173
expect(std.out).toMatchInlineSnapshot(`""`);
@@ -400,9 +400,9 @@ describe("wrangler dev", () => {
400400
await fs.promises.writeFile("index.js", `export default {};`);
401401
await expect(runWrangler("dev --remote")).rejects
402402
.toThrowErrorMatchingInlineSnapshot(`
403-
"Could not find zone for \`does-not-exist.com\`. Make sure the domain is set up to be proxied by Cloudflare.
404-
For more details, refer to https://developers.cloudflare.com/workers/configuration/routing/routes/#set-up-a-route"
405-
`);
403+
[Error: Could not find zone for \`does-not-exist.com\`. Make sure the domain is set up to be proxied by Cloudflare.
404+
For more details, refer to https://developers.cloudflare.com/workers/configuration/routing/routes/#set-up-a-route]
405+
`);
406406
});
407407

408408
it("should fallback to zone_name when given the pattern */*", async () => {
@@ -553,9 +553,9 @@ describe("wrangler dev", () => {
553553
mockGetZones("some-host.com", []);
554554
await expect(runWrangler("dev --remote --host some-host.com")).rejects
555555
.toThrowErrorMatchingInlineSnapshot(`
556-
"Could not find zone for \`some-host.com\`. Make sure the domain is set up to be proxied by Cloudflare.
557-
For more details, refer to https://developers.cloudflare.com/workers/configuration/routing/routes/#set-up-a-route"
558-
`);
556+
[Error: Could not find zone for \`some-host.com\`. Make sure the domain is set up to be proxied by Cloudflare.
557+
For more details, refer to https://developers.cloudflare.com/workers/configuration/routing/routes/#set-up-a-route]
558+
`);
559559
});
560560

561561
it("should not try to resolve a zone when starting in local mode", async () => {
@@ -669,9 +669,9 @@ describe("wrangler dev", () => {
669669

670670
await expect(runWrangler("dev")).rejects
671671
.toThrowErrorMatchingInlineSnapshot(`
672-
"The expected output file at \\"index.js\\" was not found after running custom build: node -e \\"4+4;\\".
673-
The \`main\` property in wrangler.toml should point to the file generated by the custom build."
674-
`);
672+
[Error: The expected output file at "index.js" was not found after running custom build: node -e "4+4;".
673+
The \`main\` property in wrangler.toml should point to the file generated by the custom build.]
674+
`);
675675
expect(std.out).toMatchInlineSnapshot(`
676676
"Running custom build: node -e \\"4+4;\\"
677677
"
@@ -941,9 +941,9 @@ describe("wrangler dev", () => {
941941
fs.writeFileSync("index.js", `export default {};`);
942942
await expect(runWrangler("dev")).rejects
943943
.toThrowErrorMatchingInlineSnapshot(`
944-
"Processing wrangler.toml configuration:
945-
- Expected \\"dev.inspector_port\\" to be of type number but got \\"some string\\"."
946-
`);
944+
[Error: Processing wrangler.toml configuration:
945+
- Expected "dev.inspector_port" to be of type number but got "some string".]
946+
`);
947947
});
948948
});
949949

@@ -989,9 +989,9 @@ describe("wrangler dev", () => {
989989
fs.writeFileSync("index.js", `export default {};`);
990990
await expect(runWrangler("dev")).rejects
991991
.toThrowErrorMatchingInlineSnapshot(`
992-
"Processing wrangler.toml configuration:
993-
- Expected \\"dev.port\\" to be of type number but got \\"some string\\"."
994-
`);
992+
[Error: Processing wrangler.toml configuration:
993+
- Expected "dev.port" to be of type number but got "some string".]
994+
`);
995995
});
996996

997997
it("should use --port command line arg, if provided", async () => {
@@ -1178,67 +1178,70 @@ describe("wrangler dev", () => {
11781178
await expect(
11791179
runWrangler("dev --site")
11801180
).rejects.toThrowErrorMatchingInlineSnapshot(
1181-
`"Not enough arguments following: site"`
1181+
`[Error: Not enough arguments following: site]`
11821182
);
11831183

11841184
expect(std).toMatchInlineSnapshot(`
1185-
Object {
1186-
"debug": "",
1187-
"err": "X [ERROR] Not enough arguments following: site
1188-
1189-
",
1190-
"info": "",
1191-
"out": "
1192-
wrangler dev [script]
1193-
1194-
Start a local server for developing a worker
1195-
1196-
Positionals:
1197-
script The path to an entry point for your worker [string]
1198-
1199-
Global Flags:
1200-
-j, --experimental-json-config ⚑Experimental: support wrangler.json [boolean]
1201-
-c, --config ⚑Path to .toml configuration file [string]
1202-
-e, --env ⚑Environment to use for operations and .env files [string]
1203-
-h, --help ⚑Show help [boolean]
1204-
-v, --version ⚑Show version number [boolean]
1205-
1206-
Options:
1207-
--name Name of the worker [string]
1208-
--no-bundle Skip internal build steps and directly deploy script [boolean] [default: false]
1209-
--compatibility-date Date to use for compatibility checks [string]
1210-
--compatibility-flags, --compatibility-flag Flags to use for compatibility checks [array]
1211-
--latest Use the latest version of the worker runtime [boolean] [default: true]
1212-
--ip IP address to listen on [string]
1213-
--port Port to listen on [number]
1214-
--inspector-port Port for devtools to connect to [number]
1215-
--routes, --route Routes to upload [array]
1216-
--host Host to forward requests to, defaults to the zone of project [string]
1217-
--local-protocol Protocol to listen to requests on, defaults to http. [choices: \\"http\\", \\"https\\"]
1218-
--https-key-path Path to a custom certificate key [string]
1219-
--https-cert-path Path to a custom certificate [string]
1220-
--local-upstream Host to act as origin in local mode, defaults to dev.host or route [string]
1221-
--assets Static assets to be served [string]
1222-
--site Root folder of static assets for Workers Sites [string]
1223-
--site-include Array of .gitignore-style patterns that match file or directory names from the sites directory. Only matched items will be uploaded. [array]
1224-
--site-exclude Array of .gitignore-style patterns that match file or directory names from the sites directory. Matched items will not be uploaded. [array]
1225-
--upstream-protocol Protocol to forward requests to host on, defaults to https. [choices: \\"http\\", \\"https\\"]
1226-
--var A key-value pair to be injected into the script as a variable [array]
1227-
--define A key-value pair to be substituted in the script [array]
1228-
--jsx-factory The function that is called for each JSX element [string]
1229-
--jsx-fragment The function that is called for each JSX fragment [string]
1230-
--tsconfig Path to a custom tsconfig.json file [string]
1231-
-r, --remote Run on the global Cloudflare network with access to production resources [boolean] [default: false]
1232-
--minify Minify the script [boolean]
1233-
--node-compat Enable Node.js compatibility [boolean]
1234-
--persist-to Specify directory to use for local persistence (defaults to .wrangler/state) [string]
1235-
--live-reload Auto reload HTML pages when change is detected in local mode [boolean]
1236-
--test-scheduled Test scheduled events by visiting /__scheduled in browser [boolean] [default: false]
1237-
--log-level Specify logging level [choices: \\"debug\\", \\"info\\", \\"log\\", \\"warn\\", \\"error\\", \\"none\\"] [default: \\"log\\"]
1238-
--show-interactive-dev-session Show interactive dev session (defaults to true if the terminal supports interactivity) [boolean]",
1239-
"warn": "",
1240-
}
1241-
`);
1185+
Object {
1186+
"debug": "",
1187+
"err": "X [ERROR] Not enough arguments following: site
1188+
1189+
",
1190+
"info": "",
1191+
"out": "
1192+
wrangler dev [script]
1193+
1194+
👂 Start a local server for developing your Worker
1195+
1196+
POSITIONALS
1197+
script The path to an entry point for your worker [string]
1198+
1199+
GLOBAL FLAGS
1200+
-j, --experimental-json-config Experimental: support wrangler.json [boolean]
1201+
-c, --config Path to .toml configuration file [string]
1202+
-e, --env Environment to use for operations and .env files [string]
1203+
-h, --help Show help [boolean]
1204+
-v, --version Show version number [boolean]
1205+
1206+
OPTIONS
1207+
--name Name of the worker [string]
1208+
--no-bundle Skip internal build steps and directly deploy script [boolean] [default: false]
1209+
--compatibility-date Date to use for compatibility checks [string]
1210+
--compatibility-flags, --compatibility-flag Flags to use for compatibility checks [array]
1211+
--latest Use the latest version of the worker runtime [boolean] [default: true]
1212+
--ip IP address to listen on [string]
1213+
--port Port to listen on [number]
1214+
--inspector-port Port for devtools to connect to [number]
1215+
--routes, --route Routes to upload [array]
1216+
--host Host to forward requests to, defaults to the zone of project [string]
1217+
--local-protocol Protocol to listen to requests on, defaults to http. [choices: \\"http\\", \\"https\\"]
1218+
--https-key-path Path to a custom certificate key [string]
1219+
--https-cert-path Path to a custom certificate [string]
1220+
--local-upstream Host to act as origin in local mode, defaults to dev.host or route [string]
1221+
--assets Static assets to be served [string]
1222+
--site Root folder of static assets for Workers Sites [string]
1223+
--site-include Array of .gitignore-style patterns that match file or directory names from the sites directory. Only matched items will be uploaded. [array]
1224+
--site-exclude Array of .gitignore-style patterns that match file or directory names from the sites directory. Matched items will not be uploaded. [array]
1225+
--upstream-protocol Protocol to forward requests to host on, defaults to https. [choices: \\"http\\", \\"https\\"]
1226+
--var A key-value pair to be injected into the script as a variable [array]
1227+
--define A key-value pair to be substituted in the script [array]
1228+
--alias A module pair to be substituted in the script [array]
1229+
--jsx-factory The function that is called for each JSX element [string]
1230+
--jsx-fragment The function that is called for each JSX fragment [string]
1231+
--tsconfig Path to a custom tsconfig.json file [string]
1232+
-r, --remote Run on the global Cloudflare network with access to production resources [boolean] [default: false]
1233+
--minify Minify the script [boolean]
1234+
--node-compat Enable Node.js compatibility [boolean]
1235+
--persist-to Specify directory to use for local persistence (defaults to .wrangler/state) [string]
1236+
--live-reload Auto reload HTML pages when change is detected in local mode [boolean]
1237+
--test-scheduled Test scheduled events by visiting /__scheduled in browser [boolean] [default: false]
1238+
--log-level Specify logging level [choices: \\"debug\\", \\"info\\", \\"log\\", \\"warn\\", \\"error\\", \\"none\\"] [default: \\"log\\"]
1239+
--show-interactive-dev-session Show interactive dev session (defaults to true if the terminal supports interactivity) [boolean]
1240+
--experimental-dev-env, --x-dev-env Use the experimental DevEnv instantiation (unified across wrangler dev and unstable_dev) [boolean] [default: false]
1241+
--experimental-registry, --x-registry Use the experimental file based dev registry for multi-worker development [boolean] [default: false]",
1242+
"warn": "",
1243+
}
1244+
`);
12421245
});
12431246

12441247
it("should error if --assets and --site are used together", async () => {
@@ -1249,7 +1252,7 @@ describe("wrangler dev", () => {
12491252
await expect(
12501253
runWrangler("dev --assets abc --site xyz")
12511254
).rejects.toThrowErrorMatchingInlineSnapshot(
1252-
`"Cannot use Assets and Workers Sites in the same Worker."`
1255+
`[Error: Cannot use Assets and Workers Sites in the same Worker.]`
12531256
);
12541257
});
12551258

@@ -1264,7 +1267,7 @@ describe("wrangler dev", () => {
12641267
await expect(
12651268
runWrangler("dev --assets abc")
12661269
).rejects.toThrowErrorMatchingInlineSnapshot(
1267-
`"Cannot use Assets and Workers Sites in the same Worker."`
1270+
`[Error: Cannot use Assets and Workers Sites in the same Worker.]`
12681271
);
12691272
});
12701273

@@ -1277,7 +1280,7 @@ describe("wrangler dev", () => {
12771280
await expect(
12781281
runWrangler("dev --site xyz")
12791282
).rejects.toThrowErrorMatchingInlineSnapshot(
1280-
`"Cannot use Assets and Workers Sites in the same Worker."`
1283+
`[Error: Cannot use Assets and Workers Sites in the same Worker.]`
12811284
);
12821285
});
12831286

@@ -1293,7 +1296,7 @@ describe("wrangler dev", () => {
12931296
await expect(
12941297
runWrangler("dev --assets abc")
12951298
).rejects.toThrowErrorMatchingInlineSnapshot(
1296-
`"Cannot use Assets and Workers Sites in the same Worker."`
1299+
`[Error: Cannot use Assets and Workers Sites in the same Worker.]`
12971300
);
12981301
});
12991302

@@ -1564,7 +1567,7 @@ describe("wrangler dev", () => {
15641567
"dev index.js --compatibility-flag=nodejs_compat --node-compat"
15651568
)
15661569
).rejects.toThrowErrorMatchingInlineSnapshot(
1567-
`"The \`nodejs_compat\` compatibility flag cannot be used in conjunction with the legacy \`--node-compat\` flag. If you want to use the Workers runtime Node.js compatibility features, please remove the \`--node-compat\` argument from your CLI command or \`node_compat = true\` from your config file."`
1570+
`[Error: The \`nodejs_compat\` compatibility flag cannot be used in conjunction with the legacy \`--node-compat\` flag. If you want to use the Workers \`nodejs_compat\` compatibility flag, please remove the \`--node-compat\` argument from your CLI command or \`node_compat = true\` from your config file.]`
15681571
);
15691572
});
15701573
});
@@ -1575,7 +1578,7 @@ function mockGetZones(domain: string, zones: { id: string }[] = []) {
15751578
http.get("*/zones", ({ request }) => {
15761579
const url = new URL(request.url);
15771580

1578-
expect([...url.searchParams.entries()]).toEqual([["name", domain]]);
1581+
expect(url.searchParams.get("name")).toEqual(domain);
15791582

15801583
return HttpResponse.json(
15811584
{

packages/wrangler/vitest.config.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export default defineConfig({
6161
testTimeout: 15_000,
6262
pool: "forks",
6363
retry: 0,
64-
include: ["**/__tests__/**/*.test.ts"],
64+
include: ["**/__tests__/**/*.test.ts", "**/__tests__/**/*.test.tsx"],
6565
// eslint-disable-next-line turbo/no-undeclared-env-vars
6666
outputFile: process.env.TEST_REPORT_PATH ?? ".e2e-test-report/index.html",
6767
setupFiles: path.resolve(__dirname, "src/__tests__/vitest.setup.ts"),

0 commit comments

Comments
 (0)