Skip to content

Commit

Permalink
test: run tests on cloudflare workers (#1546)
Browse files Browse the repository at this point in the history
* test: run tests con cloudflare workers

* test: run tests con cloudflare workers

* test: run tests on cloudflare workers

* test: run tests on cloudflare workers

* test: run tests on cloudflare workers

* Revert "test: run tests on cloudflare workers"

This reverts commit 5b0453c.

* test: run tests on cloudflare workers

* test: run tests on cloudflare workers
  • Loading branch information
belgattitude authored Oct 12, 2024
1 parent b7c684f commit bdf9e19
Show file tree
Hide file tree
Showing 43 changed files with 1,540 additions and 1,016 deletions.
4 changes: 3 additions & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch"
"updateInternalDependencies": "patch",
"bumpVersionsWithWorkspaceProtocolOnly": true,
"exclude": ["@httpx/devtools-vitest"]
}
11 changes: 11 additions & 0 deletions .changeset/cuddly-ties-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@httpx/plain-object": patch
"@httpx/dsn-parser": patch
"@httpx/exception": patch
"@httpx/memo-intl": patch
"@httpx/json-api": patch
"@httpx/assert": patch
"@httpx/treeu": patch
---

Ensure CI tests on Clouflare workers and latest chrome (playwright)
13 changes: 13 additions & 0 deletions .github/workflows/ci-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ jobs:
if: matrix.node-version == '20.x'
run: yarn nx run-many --target=test-unit-edge --exclude='examples/**' --exclude='docs'

- name: 🧪 Unit tests (cloudflare - only node 20.x)
if: matrix.node-version == '20.x'
run: yarn nx run-many --target=test-unit-cloudflare --exclude='examples/**' --exclude='docs'

- name: ⚙️ Install Playwright Chrome (only node 20.x)
if: matrix.node-version == '20.x'
run: yarn playwright install chrome

# @todo make this working
#- name: 🧪 Unit tests (playwright chrome - only node 20.x)
# if: matrix.node-version == '20.x'
# run: yarn nx run-many --target=test-unit-browser --exclude='examples/**' --exclude='docs'

- name: 🏗 Build packages
run: yarn nx run-many --target=build --exclude='examples/**' --exclude='docs'

Expand Down
41 changes: 21 additions & 20 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,27 @@ If applicable:

## Local scripts

| Name | Description |
|------------------------------|---------------------------------------------------------------------------------------------------------------------------------------|
| `yarn g:changeset` | Add a changeset to declare a new version |
| `yarn g:typecheck` | Run typechecks in all workspaces |
| `yarn g:lint` | Display linter issues in all workspaces |
| `yarn g:lint --fix` | Attempt to run linter auto-fix in all workspaces |
| `yarn g:test-unit` | Run unit tests in all workspaces (node) |
| `yarn g:test-unit-edge` | Run unit tests in all workspaces (@vercel-edge-runtime) |
| `yarn g:test-unit-browser` | Run unit tests in all workspaces (latest chrome) |
| `yarn g:build` | Run build in all workspaces |
| `yarn g:clean` | Clean builds in all workspaces |
| `yarn g:check-dist` | Ensure build dist files passes es2017 (run `g:build` first). |
| `yarn g:check-size` | Ensure build files are within size limit (run `g:build` first). |
| `yarn g:docgen` | Build documentation (generally api doc) |
| `yarn g:bench` | Run benchmarks for all workspaces. |
| `yarn clean:global-cache` | Clean tooling caches (eslint, jest...) |
| `yarn deps:check --dep dev` | Will print what packages can be upgraded globally (see also [.ncurc.yml](https://github.com/belgattitude/httpx/blob/main/.ncurc.yml)) |
| `yarn deps:update --dep dev` | Apply possible updates (run `yarn install && yarn dedupe` after) |
| `yarn check:install` | Verify if there's no peer-deps missing in packages |
| `yarn dedupe` | Built-in yarn deduplication of the lock file |
| Name | Description |
|-------------------------------|---------------------------------------------------------------------------------------------------------------------------------------|
| `yarn g:changeset` | Add a changeset to declare a new version |
| `yarn g:typecheck` | Run typechecks in all workspaces |
| `yarn g:lint` | Display linter issues in all workspaces |
| `yarn g:lint --fix` | Attempt to run linter auto-fix in all workspaces |
| `yarn g:test-unit` | Run unit tests in all workspaces (node) |
| `yarn g:test-unit-edge` | Run unit tests in all workspaces (@vercel-edge-runtime) |
| `yarn g:test-unit-browser` | Run unit tests in all workspaces (latest chrome) |
| `yarn g:test-unit-cloudflare` | Run unit tests in all workspaces (latest chrome) |
| `yarn g:build` | Run build in all workspaces |
| `yarn g:clean` | Clean builds in all workspaces |
| `yarn g:check-dist` | Ensure build dist files passes es2017 (run `g:build` first). |
| `yarn g:check-size` | Ensure build files are within size limit (run `g:build` first). |
| `yarn g:docgen` | Build documentation (generally api doc) |
| `yarn g:bench` | Run benchmarks for all workspaces. |
| `yarn clean:global-cache` | Clean tooling caches (eslint, jest...) |
| `yarn deps:check --dep dev` | Will print what packages can be upgraded globally (see also [.ncurc.yml](https://github.com/belgattitude/httpx/blob/main/.ncurc.yml)) |
| `yarn deps:update --dep dev` | Apply possible updates (run `yarn install && yarn dedupe` after) |
| `yarn check:install` | Verify if there's no peer-deps missing in packages |
| `yarn dedupe` | Built-in yarn deduplication of the lock file |

## Git message format

Expand Down
45 changes: 45 additions & 0 deletions devtools/vitest/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Specific eslint rules for this workspace, learn how to compose
* @link https://github.com/belgattitude/perso/tree/main/packages/eslint-config-bases
*/

// Workaround for https://github.com/eslint/eslint/issues/3458
require('@belgattitude/eslint-config-bases/patch/modern-module-resolution');

const {
getDefaultIgnorePatterns,
} = require('@belgattitude/eslint-config-bases/helpers');

module.exports = {
extends: [
'@belgattitude/eslint-config-bases/typescript',
'@belgattitude/eslint-config-bases/simple-import-sort',
'@belgattitude/eslint-config-bases/import-x',
'@belgattitude/eslint-config-bases/sonar',
'@belgattitude/eslint-config-bases/regexp',
'@belgattitude/eslint-config-bases/jest',
'@belgattitude/eslint-config-bases/performance',

// Apply prettier and disable incompatible rules
'@belgattitude/eslint-config-bases/prettier-plugin',
],
ignorePatterns: [
...getDefaultIgnorePatterns(),
'**/build',
'**/.cache',
'**/dist',
'**/_release',
'.cache',
'**/docs',
],
overrides: [],
parser: '@typescript-eslint/parser',
parserOptions: {
projectService: true,
tsconfigRootDir: __dirname,
},
root: true,
rules: {
'import-x/no-extraneous-dependencies': 'off',
},
};
51 changes: 51 additions & 0 deletions devtools/vitest/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "@httpx/devtools-vitest",
"description": "Shareable dev setups for vitest",
"version": "0.0.1",
"private": true,
"license": "MIT",
"author": {
"name": "Vanvelthem Sébastien",
"url": "https://github.com/belgattitude"
},
"repository": {
"type": "git",
"url": "git+https://github.com/belgattitude/httpx.git",
"directory": "tools/vitest"
},
"sideEffects": false,
"exports": {
"./package.json": "./package.json",
"./wrangler.toml": "./wrangler.toml"
},
"scripts": {
"clean": "rimraf ./dist ./build ./coverage ./_release",
"fix-staged": "lint-staged --allow-empty",
"lint": "eslint . --ext .ts,.tsx,.js,.jsx,.mjs,.cjs,.mts,.cts",
"typecheck": "tsc --project tsconfig.json --noEmit",
"install-playwright": "playwright install chromium"
},
"peerDependencies": {
"vitest": "2.1.2"
},
"dependencies": {
"@belgattitude/eslint-config-bases": "6.0.0-canary.19",
"@cloudflare/vitest-pool-workers": "0.5.18",
"@codspeed/vitest-plugin": "3.1.1",
"@edge-runtime/vm": "4.0.3",
"@vitest/browser": "2.1.2",
"@vitest/coverage-istanbul": "2.1.2",
"@vitest/ui": "2.1.2",
"esbuild": "0.24.0",
"playwright": "1.48.0",
"typescript": "5.6.3",
"vite": "5.4.8",
"vite-tsconfig-paths": "5.0.1"
},
"devDependencies": {
"vitest": "2.1.2"
},
"engines": {
"node": ">=18"
}
}
33 changes: 33 additions & 0 deletions devtools/vitest/src/vitest.codspeed.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { defineWorkersConfig } from '@cloudflare/vitest-pool-workers/config';
import tsconfigPaths from 'vite-tsconfig-paths';

const testFiles = ['./src/**/*.test.{js,ts}', './test/**/*.test.{js,ts}'];

export default defineWorkersConfig({
esbuild: {
target: ['node18'],
},
plugins: [tsconfigPaths()],
cacheDir: '../../.cache/vite/httpx-dsn-parser-cloudflare',
test: {
// @link https://vitest.dev/config/#clearmocks
clearMocks: true,
poolOptions: {
workers: {
wrangler: { configPath: '../../tools/cloudflare/wrangler.toml' },
},
},
exclude: [
'**/node_modules/**',
'dist/**',
'**/coverage/**',
'**/.{idea,git,cache,output,temp}/**',
],
globals: true,
include: testFiles,
// To mimic Jest behaviour regarding mocks.
mockReset: true,
passWithNoTests: true,
restoreMocks: true,
},
});
62 changes: 62 additions & 0 deletions devtools/vitest/src/vitest.common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import codspeedPlugin from '@codspeed/vitest-plugin';
import tsconfigPaths from 'vite-tsconfig-paths';
import { defineConfig } from 'vitest/config';

const testFiles = ['./src/**/*.test.{js,ts}', './test/**/*.test.{js,ts}'];

const isCodeSpeedEnabled = process.env?.CODSPEED === '1';
const cspeed = isCodeSpeedEnabled ? codspeedPlugin() : undefined;

export default defineConfig({
esbuild: {
target: ['node18'],
},
plugins: [tsconfigPaths(), ...[cspeed].filter(Boolean)],
cacheDir: '../../.cache/vite/httpx-plain-object',
test: {
browser: {
provider: 'playwright',
name: 'chromium',
},
// @link https://vitest.dev/config/#clearmocks
clearMocks: true,
coverage: {
all: true,
include: ['src/**/*.{js,jsx,ts,tsx}'],
provider: 'istanbul',
reporter: ['text', 'json', 'clover'],
},
typecheck: {
enabled: false,
},
benchmark: {
reporters: ['default'],
outputJson: './bench/output/benchmark-results.json',
},
pool: 'forks',
poolOptions: {
vmThreads: {
// useAtomics: true,
},
threads: {
// minThreads: 1,
// maxThreads: 16,
useAtomics: true, // perf+
isolate: false, // perf+++
},
},
environment: 'node',
exclude: [
'**/node_modules/**',
'dist/**',
'**/coverage/**',
'**/.{idea,git,cache,output,temp}/**',
],
globals: true,
include: testFiles,
// To mimic Jest behaviour regarding mocks.
mockReset: true,
passWithNoTests: false,
restoreMocks: true,
},
});
24 changes: 24 additions & 0 deletions devtools/vitest/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"moduleResolution": "bundler",
"verbatimModuleSyntax": true,
"strict": true,
"paths": {},
"types": ["vitest/globals"]
},
"exclude": ["**/node_modules", "**/.*/*", "dist", "coverage"],
"include": [
".eslintrc.*",
"**/*.ts",
"**/*.tsx",
"**/*.js",
"**/*.jsx",
"**/*.cjs",
"**/*.mjs",
"**/*.json"
]
}
3 changes: 3 additions & 0 deletions devtools/vitest/wrangler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name = "basic-unit-integration-self"
compatibility_date = "2024-01-01"
compatibility_flags = ["nodejs_compat"]
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"react-dom": "18.3.1"
},
"devDependencies": {
"@belgattitude/eslint-config-bases": "6.0.0-canary.16",
"@belgattitude/eslint-config-bases": "6.0.0-canary.19",
"eslint": "8.57.1",
"eslint-config-next": "14.2.15",
"eslint-plugin-tailwindcss": "3.17.5",
Expand Down
2 changes: 1 addition & 1 deletion docs2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"@astrojs/check": "0.9.4",
"@astrojs/starlight": "0.28.3",
"astro": "4.16.1",
"astro": "4.16.2",
"sharp": "0.33.5",
"typescript": "5.6.3"
}
Expand Down
5 changes: 2 additions & 3 deletions examples/nextjs-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"ky": "1.7.2",
"next": "14.2.15",
"pino": "9.4.0",
"primeicons": "7.0.0",
"primereact": "10.8.4",
"react": "18.3.1",
"react-dom": "18.3.1",
Expand All @@ -39,10 +38,10 @@
"zod": "3.23.8"
},
"devDependencies": {
"@belgattitude/eslint-config-bases": "6.0.0-canary.9",
"@belgattitude/eslint-config-bases": "6.0.0-canary.19",
"@types/node": "22.7.5",
"@types/react": "18.3.11",
"@types/react-dom": "18.3.0",
"@types/react-dom": "18.3.1",
"@vitejs/plugin-react-swc": "3.7.1",
"@vitest/coverage-v8": "2.1.2",
"@vitest/ui": "2.1.2",
Expand Down
2 changes: 1 addition & 1 deletion integrations/prisma-exception/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
},
"devDependencies": {
"@arethetypeswrong/cli": "0.16.4",
"@belgattitude/eslint-config-bases": "6.0.0-canary.16",
"@belgattitude/eslint-config-bases": "6.0.0-canary.19",
"@size-limit/file": "11.1.6",
"@size-limit/webpack": "11.1.6",
"@size-limit/webpack-why": "11.1.6",
Expand Down
12 changes: 12 additions & 0 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@
],
"cache": true
},
"test-unit-cloudflare": {
"dependsOn": ["^test-unit-cloudflare"],
"inputs": [
"default",
"^public",
{
"externalDependencies": ["vitest"]
}
],
"cache": true
},

"docgen": {
"dependsOn": ["^docgen"],
"inputs": ["all", "^public"],
Expand Down
Loading

0 comments on commit bdf9e19

Please sign in to comment.