Skip to content

Commit

Permalink
Move vitest timeouts to the top level
Browse files Browse the repository at this point in the history
  • Loading branch information
petebacondarwin committed Jun 13, 2023
1 parent be15640 commit 772f67c
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 117 deletions.
1 change: 1 addition & 0 deletions fixtures/no-bundle-import/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"deploy": "wrangler deploy",
"start": "wrangler dev",
"test": "vitest run",
"test:ci": "vitest run",
"test:watch": "npx vitest"
},
"devDependencies": {
Expand Down
30 changes: 14 additions & 16 deletions fixtures/node-app-pages/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,20 @@ import { describe, it } from "vitest";
import { runWranglerPagesDev } from "../../shared/src/run-wrangler-long-lived";

describe("Pages Dev", () => {
it(
"should work with `--node-compat` when running code requiring polyfills",
async ({ expect }) => {
const { ip, port, stop } = await runWranglerPagesDev(
resolve(__dirname, ".."),
"public",
["--node-compat", "--port=0"]
);
const response = await fetch(`http://${ip}:${port}/stripe`);
it("should work with `--node-compat` when running code requiring polyfills", async ({
expect,
}) => {
const { ip, port, stop } = await runWranglerPagesDev(
resolve(__dirname, ".."),
"public",
["--node-compat", "--port=0"]
);
const response = await fetch(`http://${ip}:${port}/stripe`);

await expect(response.text()).resolves.toContain(
`"PATH":"path/to/some-file","STRIPE_OBJECT"`
);
await expect(response.text()).resolves.toContain(
`"PATH":"path/to/some-file","STRIPE_OBJECT"`
);

await stop();
},
{ timeout: 10_000 }
);
await stop();
});
});
100 changes: 46 additions & 54 deletions fixtures/pages-workerjs-app/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,53 @@ import { describe, it } from "vitest";
import { runWranglerPagesDev } from "../../shared/src/run-wrangler-long-lived";

describe("Pages _worker.js", () => {
it(
"should throw an error when the _worker.js file imports something and --bundle is false",
({ expect }) => {
expect(() =>
execSync("npm run dev -- --bundle=false", {
cwd: path.resolve(__dirname, ".."),
stdio: "ignore",
})
).toThrowError();
},
{ timeout: 10_000 }
);
it("should throw an error when the _worker.js file imports something and --bundle is false", ({
expect,
}) => {
expect(() =>
execSync("npm run dev -- --bundle=false", {
cwd: path.resolve(__dirname, ".."),
stdio: "ignore",
})
).toThrowError();
});

it(
"should throw an error when the _worker.js file imports something and --no-bundle is true",
({ expect }) => {
expect(() =>
execSync("npm run dev -- --no-bundle", {
cwd: path.resolve(__dirname, ".."),
stdio: "ignore",
})
).toThrowError();
},
{ timeout: 10_000 }
);
it("should throw an error when the _worker.js file imports something and --no-bundle is true", ({
expect,
}) => {
expect(() =>
execSync("npm run dev -- --no-bundle", {
cwd: path.resolve(__dirname, ".."),
stdio: "ignore",
})
).toThrowError();
});

it(
"should not throw an error when the _worker.js file imports something if --no-bundle is false",
async ({ expect }) => {
const { ip, port, stop } = await runWranglerPagesDev(
resolve(__dirname, ".."),
"./workerjs-test",
["--no-bundle=false", "--port=0"]
);
await expect(
fetch(`http://${ip}:${port}/`).then((resp) => resp.text())
).resolves.toContain("test");
await stop();
},
{ timeout: 10_000 }
);
it("should not throw an error when the _worker.js file imports something if --no-bundle is false", async ({
expect,
}) => {
const { ip, port, stop } = await runWranglerPagesDev(
resolve(__dirname, ".."),
"./workerjs-test",
["--no-bundle=false", "--port=0"]
);
await expect(
fetch(`http://${ip}:${port}/`).then((resp) => resp.text())
).resolves.toContain("test");
await stop();
});

it(
"should not throw an error when the _worker.js file imports something if --bundle is true",
async ({ expect }) => {
const { ip, port, stop } = await runWranglerPagesDev(
resolve(__dirname, ".."),
"./workerjs-test",
["--bundle", "--port=0"]
);
await expect(
fetch(`http://${ip}:${port}/`).then((resp) => resp.text())
).resolves.toContain("test");
await stop();
},
{ timeout: 10_000 }
);
it("should not throw an error when the _worker.js file imports something if --bundle is true", async ({
expect,
}) => {
const { ip, port, stop } = await runWranglerPagesDev(
resolve(__dirname, ".."),
"./workerjs-test",
["--bundle", "--port=0"]
);
await expect(
fetch(`http://${ip}:${port}/`).then((resp) => resp.text())
).resolves.toContain("test");
await stop();
});
});
84 changes: 37 additions & 47 deletions fixtures/pages-workerjs-directory/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,45 @@ import { describe, it } from "vitest";
import { runWranglerPagesDev } from "../../shared/src/run-wrangler-long-lived";

describe("Pages _worker.js/ directory", () => {
it(
"should support non-bundling with 'dev'",
async ({ expect }) => {
const { ip, port, stop } = await runWranglerPagesDev(
resolve(__dirname, ".."),
"public",
["--port=0", "--d1=D1"]
);
await expect(
fetch(`http://${ip}:${port}/`).then((resp) => resp.text())
).resolves.toContain("Hello, world!");
await expect(
fetch(`http://${ip}:${port}/wasm`).then((resp) => resp.text())
).resolves.toContain("3");
await expect(
fetch(`http://${ip}:${port}/static`).then((resp) => resp.text())
).resolves.toContain("static");
await expect(
fetch(`http://${ip}:${port}/other-script.js`).then((resp) =>
resp.text()
)
).resolves.toContain("other-script-test");
await expect(
fetch(`http://${ip}:${port}/d1`).then((resp) => resp.text())
).resolves.toContain('{"1":1}');
await stop();
},
{ timeout: 10_000 }
);
it("should support non-bundling with 'dev'", async ({ expect }) => {
const { ip, port, stop } = await runWranglerPagesDev(
resolve(__dirname, ".."),
"public",
["--port=0", "--d1=D1"]
);
await expect(
fetch(`http://${ip}:${port}/`).then((resp) => resp.text())
).resolves.toContain("Hello, world!");
await expect(
fetch(`http://${ip}:${port}/wasm`).then((resp) => resp.text())
).resolves.toContain("3");
await expect(
fetch(`http://${ip}:${port}/static`).then((resp) => resp.text())
).resolves.toContain("static");
await expect(
fetch(`http://${ip}:${port}/other-script.js`).then((resp) => resp.text())
).resolves.toContain("other-script-test");
await expect(
fetch(`http://${ip}:${port}/d1`).then((resp) => resp.text())
).resolves.toContain('{"1":1}');
await stop();
});

it(
"should bundle",
async ({ expect }) => {
const dir = tmpdir();
const file = join(dir, "./_worker.bundle");
it("should bundle", async ({ expect }) => {
const dir = tmpdir();
const file = join(dir, "./_worker.bundle");

execSync(
`npx wrangler pages functions build --build-output-directory public --outfile ${file} --bindings="{\\"d1_databases\\":{\\"D1\\":{}}}"`,
{
cwd: path.resolve(__dirname, ".."),
}
);
execSync(
`npx wrangler pages functions build --build-output-directory public --outfile ${file} --bindings="{\\"d1_databases\\":{\\"D1\\":{}}}"`,
{
cwd: path.resolve(__dirname, ".."),
}
);

const contents = readFileSync(file, "utf-8");
const contents = readFileSync(file, "utf-8");

expect(contents).toContain("D1_ERROR");
expect(contents).toContain('"other-script-test"');
expect(contents).toContain('import staticMod from "./static.js";');
},
{ timeout: 10_000 }
);
expect(contents).toContain("D1_ERROR");
expect(contents).toContain('"other-script-test"');
expect(contents).toContain('import staticMod from "./static.js";');
});
});
9 changes: 9 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from "vitest/config";

// This default gets pulled in by all the Vitest runs in the monorepo.
export default defineConfig({
test: {
testTimeout: 30_000,
hookTimeout: 30_000,
},
});

0 comments on commit 772f67c

Please sign in to comment.