Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run fixture tests with vitest #2496

Merged
merged 11 commits into from
Jan 5, 2023
2 changes: 2 additions & 0 deletions .github/workflows/codecov-context.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ jobs:

- name: Run tests & collect coverage
run: npm run test:ci -w wrangler
env:
NODE_OPTIONS: "--max_old_space_size=8192"

- name: Report Code Coverage
uses: codecov/codecov-action@v3
2 changes: 2 additions & 0 deletions .github/workflows/d1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:

- name: Check for errors
run: npm run check
env:
NODE_OPTIONS: "--max_old_space_size=8192"

- name: Modify package.json version
run: node .github/version-script.js
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/experimental-wasm-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ jobs:

- name: Check for errors
run: npm run check
env:
NODE_OPTIONS: "--max_old_space_size=8192"

- name: Publish `wrangler@wasm` to NPM
run: npm publish --tag wasm
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/prereleases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ jobs:

- name: Check for errors
run: npm run check
env:
NODE_OPTIONS: "--max_old_space_size=8192"

- name: Publish Beta to NPM
run: npm publish --tag beta
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pullrequests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ jobs:

- name: Check for errors
run: npm run check
env:
NODE_OPTIONS: "--max_old_space_size=8192"

test:
name: "Tests"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/queues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:

- name: Check for errors
run: npm run check
env:
NODE_OPTIONS: "--max_old_space_size=8192"

- name: Modify package.json version
run: node .github/version-script.js
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:

- name: Check for other errors
run: npm run check
env:
NODE_OPTIONS: "--max_old_space_size=8192"

- name: Create Version PR or Publish to NPM
id: changesets
Expand Down
20 changes: 2 additions & 18 deletions fixtures/external-durable-objects-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,8 @@
"scripts": {
"check:type": "tsc && tsc -p tests/tsconfig.json",
"dev": "npx concurrently -s first -k \"wrangler dev a/index.ts --local --port 8400\" \"wrangler dev b/index.ts --local --port 8401\" \"npx wrangler dev c/index.ts --local --port 8402\" \"cd d && npx wrangler pages dev public --port 8403 --do PAGES_REFERENCED_DO=MyDurableObject@a\"",
"test": "npx jest --forceExit",
"test:ci": "npx jest --forceExit"
},
"jest": {
"restoreMocks": true,
"testRegex": ".*.(test|spec)\\.[jt]sx?$",
"testTimeout": 30000,
"transform": {
"^.+\\.c?(t|j)sx?$": [
"esbuild-jest",
{
"sourcemap": true
}
]
},
"transformIgnorePatterns": [
"node_modules/(?!find-up|locate-path|p-locate|p-limit|yocto-queue|path-exists|execa|strip-final-newline|npm-run-path|path-key|onetime|mimic-fn|human-signals|is-stream)"
]
"test": "npx vitest",
"test:ci": "npx vitest"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20221111.1"
Expand Down
1 change: 1 addition & 0 deletions fixtures/external-durable-objects-app/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { fork } from "child_process";
import * as path from "path";
import { fetch } from "undici";
import { describe, expect, it, beforeAll, afterAll } from "vitest";
import type { ChildProcess } from "child_process";

describe.skip("Pages Functions", () => {
Expand Down
4 changes: 2 additions & 2 deletions fixtures/external-durable-objects-app/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"types": ["node", "jest"]
"types": ["node"]
},
"include": ["**/*.ts"]
"include": ["**/*.ts", "../../../node-types.d.ts"]
}
18 changes: 2 additions & 16 deletions fixtures/node-app-pages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,8 @@
"scripts": {
"check:type": "tsc && tsc -p tests/tsconfig.json",
"dev": "npx wrangler pages dev public --port 12345 --node-compat",
"test": "npx jest --forceExit",
"test:ci": "npx jest --forceExit"
},
"jest": {
"testRegex": ".*.(test|spec)\\.[jt]sx?$",
"transform": {
"^.+\\.c?(t|j)sx?$": [
"esbuild-jest",
{
"sourcemap": true
}
]
},
"transformIgnorePatterns": [
"node_modules/(?!find-up|locate-path|p-locate|p-limit|yocto-queue|path-exists|execa|strip-final-newline|npm-run-path|path-key|onetime|mimic-fn|human-signals|is-stream)"
]
"test": "npx vitest",
"test:ci": "npx vitest"
Comment on lines +10 to +11
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a different script for CI?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just seems to be the pattern we've adopted everywhere. Didn't want to change too much all in this one PR so left as-was.

},
"dependencies": {
"stripe": "^9.1.0"
Expand Down
37 changes: 17 additions & 20 deletions fixtures/node-app-pages/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
import { fork } from "child_process";
import path from "path";
import { fetch } from "undici";
import { describe, it, beforeAll, afterAll } from "vitest";
import type { ChildProcess } from "child_process";

describe("Pages Dev", () => {
let wranglerProcess: ChildProcess;
let ip: string;
let port: number;
let resolveReadyPromise: (value: unknown) => void;
const readyPromise = new Promise((resolve) => {
resolveReadyPromise = resolve;
});

beforeAll(() => {
wranglerProcess = fork(
path.join("..", "..", "packages", "wrangler", "bin", "wrangler.js"),
["pages", "dev", "public", "--node-compat", "--port=0"],
{
stdio: ["inherit", "inherit", "inherit", "ipc"],
cwd: path.resolve(__dirname, ".."),
}
).on("message", (message) => {
const parsedMessage = JSON.parse(message.toString());
ip = parsedMessage.ip;
port = parsedMessage.port;
resolveReadyPromise(undefined);
beforeAll(async () => {
await new Promise((resolve) => {
wranglerProcess = fork(
path.join("..", "..", "packages", "wrangler", "bin", "wrangler.js"),
["pages", "dev", "public", "--node-compat", "--port=0"],
{
stdio: ["inherit", "inherit", "inherit", "ipc"],
cwd: path.resolve(__dirname, ".."),
}
).on("message", (message) => {
const parsedMessage = JSON.parse(message.toString());
ip = parsedMessage.ip;
port = parsedMessage.port;
resolve(null);
});
});
});

afterAll(async () => {
await readyPromise;
await new Promise((resolve, reject) => {
wranglerProcess.once("exit", (code) => {
if (!code) {
Expand All @@ -44,8 +42,7 @@ describe("Pages Dev", () => {

it.concurrent(
"should work with `--node-compat` when running code requiring polyfills",
async () => {
await readyPromise;
async ({ expect }) => {
const response = await fetch(`http://${ip}:${port}/stripe`);

await expect(response.text()).resolves.toContain(
Expand Down
4 changes: 2 additions & 2 deletions fixtures/node-app-pages/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"types": ["node", "jest"]
"types": ["node"]
},
"include": ["**/*.ts"]
"include": ["**/*.ts", "../../../node-types.d.ts"]
}
20 changes: 2 additions & 18 deletions fixtures/pages-d1-shim/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,8 @@
"scripts": {
"check:type": "tsc && tsc -p tests/tsconfig.json",
"dev": "npx wrangler pages dev ./public --d1 foobar --port 8777",
"test": "npx jest --forceExit --verbose",
"test:ci": "npx jest --forceExit"
},
"jest": {
"restoreMocks": true,
"testRegex": ".*.(test|spec)\\.[jt]sx?$",
"testTimeout": 30000,
"transform": {
"^.+\\.c?(t|j)sx?$": [
"esbuild-jest",
{
"sourcemap": true
}
]
},
"transformIgnorePatterns": [
"node_modules/(?!find-up|locate-path|p-locate|p-limit|yocto-queue|path-exists|execa|strip-final-newline|npm-run-path|path-key|onetime|mimic-fn|human-signals|is-stream)"
]
"test": "npx vitest",
"test:ci": "npx vitest"
},
"devDependencies": {
"undici": "^5.9.1"
Expand Down
5 changes: 3 additions & 2 deletions fixtures/pages-d1-shim/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { readFileSync } from "fs";
import { tmpdir } from "os";
import * as path from "path";
import { join } from "path";
import { describe, it } from "vitest";

describe("Pages Functions", () => {
it.concurrent("applies the d1 shim", async () => {
describe("Pages D1 shim", () => {
it.concurrent("applies the D1 shim", async ({ expect }) => {
const dir = tmpdir();
const file = join(dir, "./d1-pages.js");

Expand Down
5 changes: 2 additions & 3 deletions fixtures/pages-d1-shim/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"types": ["node", "jest"]
"types": ["node"]
},
"include": ["**/*.ts"],
"exclude": []
"include": ["**/*.ts", "../../../node-types.d.ts"]
}
20 changes: 2 additions & 18 deletions fixtures/pages-functions-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,8 @@
"scripts": {
"check:type": "tsc && tsc -p tests/tsconfig.json",
"dev": "npx wrangler pages dev public --binding=NAME=VALUE --binding=OTHER_NAME=THING=WITH=EQUALS --r2=BUCKET --port 8789",
"test": "npx jest --forceExit",
"test:ci": "npx jest --forceExit"
},
"jest": {
"restoreMocks": true,
"testRegex": ".*.(test|spec)\\.[jt]sx?$",
"testTimeout": 30000,
"transform": {
"^.+\\.c?(t|j)sx?$": [
"esbuild-jest",
{
"sourcemap": true
}
]
},
"transformIgnorePatterns": [
"node_modules/(?!find-up|locate-path|p-locate|p-limit|yocto-queue|path-exists|execa|strip-final-newline|npm-run-path|path-key|onetime|mimic-fn|human-signals|is-stream)"
]
"test": "npx vitest",
"test:ci": "npx vitest"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20221111.1",
Expand Down
Loading