@webpresso/agent-config 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -0
- package/dist/esm/deploy/index.d.ts +1 -0
- package/dist/esm/deploy/index.js +3 -0
- package/dist/esm/dev/index.d.ts +1 -0
- package/dist/esm/dev/index.js +3 -0
- package/dist/esm/e2e/index.d.ts +1 -0
- package/dist/esm/e2e/index.js +3 -0
- package/dist/esm/package.json +2 -1
- package/dist/esm/process/index.d.ts +1 -0
- package/dist/esm/process/index.js +3 -0
- package/dist/esm/repo-root/index.d.ts +1 -0
- package/dist/esm/repo-root/index.js +3 -0
- package/dist/esm/stryker/index.js +47 -47
- package/dist/esm/tsconfig/base.json +3 -13
- package/dist/esm/vitest/bun-sqlite-shim.d.ts +1 -1
- package/dist/esm/vitest/bun-sqlite-shim.js +1 -1
- package/dist/esm/vitest/consumer-package.js +9 -9
- package/dist/esm/vitest/flakiness-reporter.d.ts +1 -1
- package/dist/esm/vitest/flakiness-reporter.js +5 -5
- package/dist/esm/vitest/node.d.ts +1 -1
- package/dist/esm/vitest/node.js +45 -45
- package/dist/esm/vitest/pool-defaults.js +5 -5
- package/dist/esm/vitest/react-router.d.ts +1 -1
- package/dist/esm/vitest/react-router.js +32 -32
- package/dist/esm/vitest/react-setup.js +0 -1
- package/dist/esm/vitest/react.d.ts +1 -1
- package/dist/esm/vitest/react.js +28 -28
- package/dist/esm/vitest/source-conditions.js +4 -4
- package/dist/esm/vitest/version-guard.js +9 -9
- package/dist/esm/vitest/workers.js +14 -14
- package/dist/esm/workers-test/durable-objects.d.ts +3 -3
- package/dist/esm/workers-test/durable-objects.js +5 -5
- package/dist/esm/workers-test/env.d.ts +1 -1
- package/dist/esm/workers-test/env.js +9 -9
- package/dist/esm/workers-test/execution-context.d.ts +2 -2
- package/dist/esm/workers-test/execution-context.js +1 -1
- package/dist/esm/workers-test/index.d.ts +8 -8
- package/dist/esm/workers-test/index.js +5 -5
- package/dist/esm/workers-test/requests.js +4 -4
- package/dist/esm/workers-test/setup.d.ts +5 -5
- package/dist/esm/workers-test/setup.js +8 -8
- package/package.json +70 -34
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
* }))
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
|
-
import react from
|
|
20
|
-
import { defineConfig } from
|
|
21
|
-
import { createFlakinessReporter } from
|
|
22
|
-
import { generatedRuntimeAliases, generatedRuntimeDedupe } from
|
|
23
|
-
import { resolvedExecArgv, resolvedMaxWorkers, resolvedMinWorkers, resolvedPool, } from
|
|
24
|
-
import { assertNonWorkersVitest4 } from
|
|
25
|
-
assertNonWorkersVitest4({ caller:
|
|
19
|
+
import react from "@vitejs/plugin-react";
|
|
20
|
+
import { defineConfig } from "vite-plus/test/config";
|
|
21
|
+
import { createFlakinessReporter } from "./flakiness-reporter.js";
|
|
22
|
+
import { generatedRuntimeAliases, generatedRuntimeDedupe } from "./generated-runtime-aliases.js";
|
|
23
|
+
import { resolvedExecArgv, resolvedMaxWorkers, resolvedMinWorkers, resolvedPool, } from "./pool-defaults.js";
|
|
24
|
+
import { assertNonWorkersVitest4 } from "./version-guard.js";
|
|
25
|
+
assertNonWorkersVitest4({ caller: "reactRouterConfig" });
|
|
26
26
|
export const reactRouterConfig = defineConfig({
|
|
27
27
|
plugins: [react()],
|
|
28
28
|
resolve: {
|
|
@@ -33,39 +33,39 @@ export const reactRouterConfig = defineConfig({
|
|
|
33
33
|
test: {
|
|
34
34
|
globals: true,
|
|
35
35
|
// happy-dom is ~40% faster than jsdom
|
|
36
|
-
environment:
|
|
36
|
+
environment: "happy-dom",
|
|
37
37
|
pool: resolvedPool,
|
|
38
38
|
maxWorkers: resolvedMaxWorkers,
|
|
39
39
|
minWorkers: resolvedMinWorkers,
|
|
40
40
|
execArgv: resolvedExecArgv,
|
|
41
41
|
// React Router apps use app/ directory
|
|
42
|
-
include: [
|
|
43
|
-
exclude: [
|
|
44
|
-
reporters: [
|
|
42
|
+
include: ["app/**/*.test.{ts,tsx}"],
|
|
43
|
+
exclude: ["**/.stryker-tmp/**", "node_modules/**"],
|
|
44
|
+
reporters: ["default", createFlakinessReporter()],
|
|
45
45
|
retry: process.env.CI ? 2 : 0,
|
|
46
46
|
coverage: {
|
|
47
|
-
provider:
|
|
48
|
-
reporter: [
|
|
49
|
-
include: [
|
|
47
|
+
provider: "v8",
|
|
48
|
+
reporter: ["text", "json", "html", "lcov"],
|
|
49
|
+
include: ["app/**/*.{ts,tsx}"],
|
|
50
50
|
exclude: [
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
51
|
+
"node_modules/",
|
|
52
|
+
"test/",
|
|
53
|
+
"**/*.d.ts",
|
|
54
|
+
"**/*.config.*",
|
|
55
|
+
"**/mockData",
|
|
56
|
+
"build/",
|
|
57
|
+
"dist/",
|
|
58
|
+
".react-router/",
|
|
59
|
+
"**/*.test.{ts,tsx}",
|
|
60
|
+
"**/*.spec.{ts,tsx}",
|
|
61
|
+
"**/index.{ts,tsx}",
|
|
62
|
+
"**/types.ts",
|
|
63
|
+
"**/types.tsx",
|
|
64
|
+
"**/types/**",
|
|
65
65
|
// React Router specific
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
"app/routes.ts",
|
|
67
|
+
"app/entry.*.tsx",
|
|
68
|
+
"app/root.tsx",
|
|
69
69
|
],
|
|
70
70
|
thresholds: {
|
|
71
71
|
lines: 95,
|
|
@@ -76,7 +76,7 @@ export const reactRouterConfig = defineConfig({
|
|
|
76
76
|
},
|
|
77
77
|
},
|
|
78
78
|
optimizeDeps: {
|
|
79
|
-
include: [
|
|
79
|
+
include: ["react", "react-dom", "react/jsx-runtime", "react/jsx-dev-runtime"],
|
|
80
80
|
},
|
|
81
81
|
});
|
|
82
82
|
export default reactRouterConfig;
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
*/
|
|
12
12
|
// Set IS_REACT_ACT_ENVIRONMENT to true for test environment
|
|
13
13
|
// This tells React 18+ that we're in a test environment and act() warnings should work correctly
|
|
14
|
-
;
|
|
15
14
|
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
|
|
16
15
|
/**
|
|
17
16
|
* Suppress console output globally for clean test output
|
package/dist/esm/vitest/react.js
CHANGED
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
* }))
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
|
-
import react from
|
|
20
|
-
import { defineConfig } from
|
|
21
|
-
import { createFlakinessReporter } from
|
|
22
|
-
import { generatedRuntimeAliases, generatedRuntimeDedupe } from
|
|
23
|
-
import { resolvedExecArgv, resolvedMaxWorkers, resolvedMinWorkers, resolvedPool, } from
|
|
24
|
-
import { assertNonWorkersVitest4 } from
|
|
25
|
-
assertNonWorkersVitest4({ caller:
|
|
19
|
+
import react from "@vitejs/plugin-react";
|
|
20
|
+
import { defineConfig } from "vite-plus/test/config";
|
|
21
|
+
import { createFlakinessReporter } from "./flakiness-reporter.js";
|
|
22
|
+
import { generatedRuntimeAliases, generatedRuntimeDedupe } from "./generated-runtime-aliases.js";
|
|
23
|
+
import { resolvedExecArgv, resolvedMaxWorkers, resolvedMinWorkers, resolvedPool, } from "./pool-defaults.js";
|
|
24
|
+
import { assertNonWorkersVitest4 } from "./version-guard.js";
|
|
25
|
+
assertNonWorkersVitest4({ caller: "reactConfig" });
|
|
26
26
|
export const reactConfig = defineConfig({
|
|
27
27
|
plugins: [react()],
|
|
28
28
|
resolve: {
|
|
@@ -33,7 +33,7 @@ export const reactConfig = defineConfig({
|
|
|
33
33
|
test: {
|
|
34
34
|
globals: true,
|
|
35
35
|
restoreAllMocks: true,
|
|
36
|
-
environment:
|
|
36
|
+
environment: "happy-dom",
|
|
37
37
|
setupFiles: [],
|
|
38
38
|
onConsoleLog: () => false, // Suppress all console output
|
|
39
39
|
pool: resolvedPool,
|
|
@@ -41,28 +41,28 @@ export const reactConfig = defineConfig({
|
|
|
41
41
|
minWorkers: resolvedMinWorkers,
|
|
42
42
|
// Cap each fork worker's V8 heap to 2GB (Node 24 default is 4.2GB).
|
|
43
43
|
execArgv: resolvedExecArgv,
|
|
44
|
-
include: [
|
|
45
|
-
exclude: [
|
|
46
|
-
reporters: [
|
|
44
|
+
include: ["src/**/*.test.{ts,tsx}", "src/**/__tests__/**/*.{ts,tsx}"],
|
|
45
|
+
exclude: ["**/.stryker-tmp/**", "node_modules/**"],
|
|
46
|
+
reporters: ["default", createFlakinessReporter()],
|
|
47
47
|
retry: process.env.CI ? 2 : 0,
|
|
48
48
|
coverage: {
|
|
49
|
-
provider:
|
|
50
|
-
reporter: [
|
|
51
|
-
include: [
|
|
49
|
+
provider: "v8",
|
|
50
|
+
reporter: ["text", "json", "html", "lcov"],
|
|
51
|
+
include: ["src/**/*.{ts,tsx}"],
|
|
52
52
|
exclude: [
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
53
|
+
"node_modules/",
|
|
54
|
+
"test/",
|
|
55
|
+
"**/*.d.ts",
|
|
56
|
+
"**/*.config.*",
|
|
57
|
+
"**/mockData",
|
|
58
|
+
"build/",
|
|
59
|
+
"dist/",
|
|
60
|
+
"**/*.test.{ts,tsx}",
|
|
61
|
+
"**/*.spec.{ts,tsx}",
|
|
62
|
+
"**/index.{ts,tsx}", // Common exclusion for barrel exports
|
|
63
|
+
"**/types.ts",
|
|
64
|
+
"**/types.tsx",
|
|
65
|
+
"**/types/**",
|
|
66
66
|
],
|
|
67
67
|
// Industry-standard 80% coverage thresholds (Atlassian recommendation)
|
|
68
68
|
// 80% catches critical gaps without excessive build failures
|
|
@@ -78,7 +78,7 @@ export const reactConfig = defineConfig({
|
|
|
78
78
|
// Pre-optimize React dependencies to prevent first-run failures
|
|
79
79
|
// See: https://github.com/storybookjs/storybook/issues/32049
|
|
80
80
|
optimizeDeps: {
|
|
81
|
-
include: [
|
|
81
|
+
include: ["react", "react-dom", "react/jsx-runtime", "react/jsx-dev-runtime"],
|
|
82
82
|
},
|
|
83
83
|
});
|
|
84
84
|
export default reactConfig;
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* export default mergeConfig(nodeConfig, createWebpressoSourceResolveConfig({ tsconfigPaths: true }))
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
|
-
export const webpressoSourceCondition =
|
|
19
|
+
export const webpressoSourceCondition = "@webpresso/source";
|
|
20
20
|
/**
|
|
21
21
|
* Vite client environments use top-level resolve conditions. Keep this list
|
|
22
22
|
* deliberately narrow: Vite still applies the built-in import/default matches
|
|
@@ -30,9 +30,9 @@ export const webpressoSourceResolveConditions = [webpressoSourceCondition];
|
|
|
30
30
|
*/
|
|
31
31
|
export const webpressoSourceSsrResolveConditions = [
|
|
32
32
|
webpressoSourceCondition,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
"module",
|
|
34
|
+
"node",
|
|
35
|
+
"development|production",
|
|
36
36
|
];
|
|
37
37
|
export function createWebpressoSourceResolveConfig(options = {}) {
|
|
38
38
|
return {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { readConsumerPackageJson, requireFromConsumer } from
|
|
1
|
+
import { readConsumerPackageJson, requireFromConsumer } from "./consumer-package.js";
|
|
2
2
|
const getVitestVersion = () => {
|
|
3
3
|
try {
|
|
4
|
-
return requireFromConsumer(
|
|
4
|
+
return requireFromConsumer("vitest/package.json").version;
|
|
5
5
|
}
|
|
6
6
|
catch (error) {
|
|
7
7
|
const wrapped = new Error(`[vitest] Unable to resolve local vitest version. ` +
|
|
@@ -13,17 +13,17 @@ const getVitestVersion = () => {
|
|
|
13
13
|
};
|
|
14
14
|
const getVitestMajor = () => {
|
|
15
15
|
const version = getVitestVersion();
|
|
16
|
-
const major = Number.parseInt(version.split(
|
|
16
|
+
const major = Number.parseInt(version.split(".")[0] ?? "0", 10);
|
|
17
17
|
return Number.isNaN(major) ? 0 : major;
|
|
18
18
|
};
|
|
19
19
|
const hasWorkersPool = () => {
|
|
20
20
|
const pkg = readConsumerPackageJson();
|
|
21
21
|
return (!!pkg &&
|
|
22
|
-
(
|
|
23
|
-
|
|
22
|
+
("@cloudflare/vitest-pool-workers" in (pkg.devDependencies ?? {}) ||
|
|
23
|
+
"@cloudflare/vitest-pool-workers" in (pkg.dependencies ?? {})));
|
|
24
24
|
};
|
|
25
25
|
const getPackageName = () => {
|
|
26
|
-
return readConsumerPackageJson()?.name ??
|
|
26
|
+
return readConsumerPackageJson()?.name ?? "this package";
|
|
27
27
|
};
|
|
28
28
|
export const assertVitest4 = ({ caller } = {}) => {
|
|
29
29
|
const major = getVitestMajor();
|
|
@@ -31,11 +31,11 @@ export const assertVitest4 = ({ caller } = {}) => {
|
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
33
|
const packageName = getPackageName();
|
|
34
|
-
const catalogHint = hasWorkersPool() ?
|
|
35
|
-
throw new Error(`[vitest] ${caller ??
|
|
34
|
+
const catalogHint = hasWorkersPool() ? "catalog:workers" : "catalog:";
|
|
35
|
+
throw new Error(`[vitest] ${caller ?? "Vitest config"} requires vitest 4.x. ` +
|
|
36
36
|
`${packageName} appears to be using vitest ${getVitestVersion()}. ` +
|
|
37
37
|
`Use the Vitest 4.1 line from ${catalogHint}.`);
|
|
38
38
|
};
|
|
39
39
|
export const assertNonWorkersVitest4 = ({ caller } = {}) => {
|
|
40
|
-
assertVitest4({ caller: caller ??
|
|
40
|
+
assertVitest4({ caller: caller ?? "Non-workers config" });
|
|
41
41
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { defineConfig } from
|
|
2
|
-
import { createFlakinessReporter } from
|
|
3
|
-
import { assertVitest4 } from
|
|
4
|
-
assertVitest4({ caller:
|
|
1
|
+
import { defineConfig } from "vite-plus/test/config";
|
|
2
|
+
import { createFlakinessReporter } from "./flakiness-reporter.js";
|
|
3
|
+
import { assertVitest4 } from "./version-guard.js";
|
|
4
|
+
assertVitest4({ caller: "workersConfig" });
|
|
5
5
|
/**
|
|
6
6
|
* Shared Vitest configuration for Cloudflare Workers
|
|
7
7
|
*/
|
|
@@ -12,21 +12,21 @@ export const workersConfig = defineConfig({
|
|
|
12
12
|
test: {
|
|
13
13
|
globals: true,
|
|
14
14
|
restoreMocks: true,
|
|
15
|
-
reporters: [
|
|
15
|
+
reporters: ["default", createFlakinessReporter()],
|
|
16
16
|
retry: process.env.CI ? 2 : 0,
|
|
17
17
|
coverage: {
|
|
18
18
|
// Use istanbul provider for Edge Runtime compatibility
|
|
19
19
|
// v8 provider requires node:inspector which is not available in Edge Runtime
|
|
20
|
-
provider:
|
|
21
|
-
reporter: [
|
|
22
|
-
include: [
|
|
20
|
+
provider: "istanbul",
|
|
21
|
+
reporter: ["text", "json", "html", "lcov"],
|
|
22
|
+
include: ["src/**/*.ts"],
|
|
23
23
|
exclude: [
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
"node_modules/**",
|
|
25
|
+
"dist/**",
|
|
26
|
+
"**/.stryker-tmp/**",
|
|
27
|
+
"**/*.test.ts",
|
|
28
|
+
"**/*.spec.ts",
|
|
29
|
+
"**/*.d.ts",
|
|
30
30
|
],
|
|
31
31
|
// Industry-standard 80% coverage thresholds (Atlassian recommendation)
|
|
32
32
|
// 80% catches critical gaps without excessive build failures
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { vi } from
|
|
1
|
+
import { vi } from "vitest";
|
|
2
2
|
/**
|
|
3
3
|
* Mock DurableObject class for unit tests.
|
|
4
4
|
* Use this when you need to mock a DurableObject class in your test setup.
|
|
@@ -52,10 +52,10 @@ export declare class MockContainer {
|
|
|
52
52
|
* ```
|
|
53
53
|
*/
|
|
54
54
|
export declare function createCloudflareRuntimeMocks(): {
|
|
55
|
-
|
|
55
|
+
"cloudflare:workers": {
|
|
56
56
|
DurableObject: typeof MockDurableObject;
|
|
57
57
|
};
|
|
58
|
-
|
|
58
|
+
"@cloudflare/containers": {
|
|
59
59
|
Container: typeof MockContainer;
|
|
60
60
|
};
|
|
61
61
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { vi } from
|
|
1
|
+
import { vi } from "vitest";
|
|
2
2
|
// ============================================================================
|
|
3
3
|
// Mock Classes
|
|
4
4
|
// ============================================================================
|
|
@@ -34,13 +34,13 @@ export class MockDurableObject {
|
|
|
34
34
|
*/
|
|
35
35
|
export class MockContainer {
|
|
36
36
|
defaultPort = 8080;
|
|
37
|
-
sleepAfter =
|
|
37
|
+
sleepAfter = "1m";
|
|
38
38
|
envVars = {};
|
|
39
39
|
enableInternet = false;
|
|
40
40
|
fetch = vi.fn();
|
|
41
41
|
destroy = vi.fn();
|
|
42
42
|
startAndWaitForPorts = vi.fn();
|
|
43
|
-
getState = vi.fn().mockResolvedValue({ status:
|
|
43
|
+
getState = vi.fn().mockResolvedValue({ status: "running" });
|
|
44
44
|
}
|
|
45
45
|
// ============================================================================
|
|
46
46
|
// Mock Factories
|
|
@@ -60,10 +60,10 @@ export class MockContainer {
|
|
|
60
60
|
*/
|
|
61
61
|
export function createCloudflareRuntimeMocks() {
|
|
62
62
|
return {
|
|
63
|
-
|
|
63
|
+
"cloudflare:workers": {
|
|
64
64
|
DurableObject: MockDurableObject,
|
|
65
65
|
},
|
|
66
|
-
|
|
66
|
+
"@cloudflare/containers": {
|
|
67
67
|
Container: MockContainer,
|
|
68
68
|
},
|
|
69
69
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { vi } from
|
|
1
|
+
import { vi } from "vitest";
|
|
2
2
|
// ============================================================================
|
|
3
3
|
// Mock Factories
|
|
4
4
|
// ============================================================================
|
|
@@ -8,7 +8,7 @@ import { vi } from 'vitest';
|
|
|
8
8
|
export function createMockDurableObjectNamespace() {
|
|
9
9
|
return {
|
|
10
10
|
newUniqueId: vi.fn(() => ({
|
|
11
|
-
toString: () =>
|
|
11
|
+
toString: () => "test-do-id",
|
|
12
12
|
equals: () => false,
|
|
13
13
|
name: undefined,
|
|
14
14
|
})),
|
|
@@ -38,13 +38,13 @@ export function createMockDurableObjectNamespace() {
|
|
|
38
38
|
*/
|
|
39
39
|
export function createMockHyperdrive(overrides) {
|
|
40
40
|
return {
|
|
41
|
-
connectionString:
|
|
41
|
+
connectionString: "postgresql://localhost/test",
|
|
42
42
|
connect: vi.fn(() => ({})),
|
|
43
|
-
host:
|
|
43
|
+
host: "localhost",
|
|
44
44
|
port: 5432,
|
|
45
|
-
user:
|
|
46
|
-
password:
|
|
47
|
-
database:
|
|
45
|
+
user: "test",
|
|
46
|
+
password: "test",
|
|
47
|
+
database: "test",
|
|
48
48
|
...overrides,
|
|
49
49
|
};
|
|
50
50
|
}
|
|
@@ -62,8 +62,8 @@ export function createMockHyperdrive(overrides) {
|
|
|
62
62
|
*/
|
|
63
63
|
export function createMockEnv(overrides = {}) {
|
|
64
64
|
const defaultEnv = {
|
|
65
|
-
ENVIRONMENT:
|
|
66
|
-
DATABASE_URL:
|
|
65
|
+
ENVIRONMENT: "test",
|
|
66
|
+
DATABASE_URL: "postgresql://localhost/test",
|
|
67
67
|
HYPERDRIVE: createMockHyperdrive(),
|
|
68
68
|
};
|
|
69
69
|
return {
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
* Drop in BaseWorkerEnv, ExecutionContext, Hyperdrive, and Durable Object mocks
|
|
6
6
|
* for any Cloudflare Workers project without recreating them per-app.
|
|
7
7
|
*/
|
|
8
|
-
export type { BaseWorkerEnv } from
|
|
9
|
-
export { createMockEnv, createMockHyperdrive, createMockDurableObjectNamespace } from
|
|
10
|
-
export type { MockExecutionContext } from
|
|
11
|
-
export { createMockExecutionContext } from
|
|
12
|
-
export { MockDurableObject, MockContainer, createCloudflareRuntimeMocks, } from
|
|
13
|
-
export { createAuthenticatedRequest, createUnauthenticatedRequest, createCorsRequest, } from
|
|
14
|
-
export type { WorkerTestOptions } from
|
|
15
|
-
export { setupWorkerTest, suppressConsole } from
|
|
8
|
+
export type { BaseWorkerEnv } from "./env.js";
|
|
9
|
+
export { createMockEnv, createMockHyperdrive, createMockDurableObjectNamespace } from "./env.js";
|
|
10
|
+
export type { MockExecutionContext } from "./execution-context.js";
|
|
11
|
+
export { createMockExecutionContext } from "./execution-context.js";
|
|
12
|
+
export { MockDurableObject, MockContainer, createCloudflareRuntimeMocks, } from "./durable-objects.js";
|
|
13
|
+
export { createAuthenticatedRequest, createUnauthenticatedRequest, createCorsRequest, } from "./requests.js";
|
|
14
|
+
export type { WorkerTestOptions } from "./setup.js";
|
|
15
|
+
export { setupWorkerTest, suppressConsole } from "./setup.js";
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
* Drop in BaseWorkerEnv, ExecutionContext, Hyperdrive, and Durable Object mocks
|
|
6
6
|
* for any Cloudflare Workers project without recreating them per-app.
|
|
7
7
|
*/
|
|
8
|
-
export { createMockEnv, createMockHyperdrive, createMockDurableObjectNamespace } from
|
|
9
|
-
export { createMockExecutionContext } from
|
|
8
|
+
export { createMockEnv, createMockHyperdrive, createMockDurableObjectNamespace } from "./env.js";
|
|
9
|
+
export { createMockExecutionContext } from "./execution-context.js";
|
|
10
10
|
// Durable Objects and Containers
|
|
11
|
-
export { MockDurableObject, MockContainer, createCloudflareRuntimeMocks, } from
|
|
11
|
+
export { MockDurableObject, MockContainer, createCloudflareRuntimeMocks, } from "./durable-objects.js";
|
|
12
12
|
// Request helpers
|
|
13
|
-
export { createAuthenticatedRequest, createUnauthenticatedRequest, createCorsRequest, } from
|
|
14
|
-
export { setupWorkerTest, suppressConsole } from
|
|
13
|
+
export { createAuthenticatedRequest, createUnauthenticatedRequest, createCorsRequest, } from "./requests.js";
|
|
14
|
+
export { setupWorkerTest, suppressConsole } from "./setup.js";
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
* const request = createAuthenticatedRequest('/api/users', { method: 'POST', body: JSON.stringify(data) })
|
|
15
15
|
* ```
|
|
16
16
|
*/
|
|
17
|
-
export function createAuthenticatedRequest(path, options = {}, baseUrl =
|
|
17
|
+
export function createAuthenticatedRequest(path, options = {}, baseUrl = "https://api.test") {
|
|
18
18
|
const { headers: optionHeaders, ...restOptions } = options;
|
|
19
19
|
return new Request(`${baseUrl}${path}`, {
|
|
20
20
|
...restOptions,
|
|
21
21
|
headers: {
|
|
22
|
-
Cookie:
|
|
22
|
+
Cookie: "session=mock-session-token",
|
|
23
23
|
...optionHeaders,
|
|
24
24
|
},
|
|
25
25
|
});
|
|
@@ -37,7 +37,7 @@ export function createAuthenticatedRequest(path, options = {}, baseUrl = 'https:
|
|
|
37
37
|
* const request = createUnauthenticatedRequest('/health')
|
|
38
38
|
* ```
|
|
39
39
|
*/
|
|
40
|
-
export function createUnauthenticatedRequest(path, options = {}, baseUrl =
|
|
40
|
+
export function createUnauthenticatedRequest(path, options = {}, baseUrl = "https://api.test") {
|
|
41
41
|
return new Request(`${baseUrl}${path}`, {
|
|
42
42
|
headers: {
|
|
43
43
|
...options.headers,
|
|
@@ -59,7 +59,7 @@ export function createUnauthenticatedRequest(path, options = {}, baseUrl = 'http
|
|
|
59
59
|
* const request = createCorsRequest('/api/data', 'https://example.com')
|
|
60
60
|
* ```
|
|
61
61
|
*/
|
|
62
|
-
export function createCorsRequest(path, origin, options = {}, baseUrl =
|
|
62
|
+
export function createCorsRequest(path, origin, options = {}, baseUrl = "https://api.test") {
|
|
63
63
|
return new Request(`${baseUrl}${path}`, {
|
|
64
64
|
headers: {
|
|
65
65
|
Origin: origin,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { BaseWorkerEnv } from
|
|
2
|
-
import type { MockExecutionContext } from
|
|
3
|
-
import { createMockExecutionContext } from
|
|
4
|
-
import { createCloudflareRuntimeMocks } from
|
|
5
|
-
import { createAuthenticatedRequest, createUnauthenticatedRequest, createCorsRequest } from
|
|
1
|
+
import type { BaseWorkerEnv } from "./env.js";
|
|
2
|
+
import type { MockExecutionContext } from "./execution-context.js";
|
|
3
|
+
import { createMockExecutionContext } from "./execution-context.js";
|
|
4
|
+
import { createCloudflareRuntimeMocks } from "./durable-objects.js";
|
|
5
|
+
import { createAuthenticatedRequest, createUnauthenticatedRequest, createCorsRequest } from "./requests.js";
|
|
6
6
|
/**
|
|
7
7
|
* Options for configuring the worker test environment
|
|
8
8
|
*/
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { vi } from
|
|
2
|
-
import { createMockEnv } from
|
|
3
|
-
import { createMockExecutionContext } from
|
|
4
|
-
import { createCloudflareRuntimeMocks } from
|
|
5
|
-
import { createAuthenticatedRequest, createUnauthenticatedRequest, createCorsRequest, } from
|
|
1
|
+
import { vi } from "vitest";
|
|
2
|
+
import { createMockEnv } from "./env.js";
|
|
3
|
+
import { createMockExecutionContext } from "./execution-context.js";
|
|
4
|
+
import { createCloudflareRuntimeMocks } from "./durable-objects.js";
|
|
5
|
+
import { createAuthenticatedRequest, createUnauthenticatedRequest, createCorsRequest, } from "./requests.js";
|
|
6
6
|
// ============================================================================
|
|
7
7
|
// Test Setup Function
|
|
8
8
|
// ============================================================================
|
|
@@ -66,13 +66,13 @@ export function suppressConsole() {
|
|
|
66
66
|
const originalLog = console.log;
|
|
67
67
|
const originalError = console.error;
|
|
68
68
|
const originalWarn = console.warn;
|
|
69
|
-
vi.spyOn(console,
|
|
69
|
+
vi.spyOn(console, "log").mockImplementation(() => {
|
|
70
70
|
// Intentionally empty - suppressing console output
|
|
71
71
|
});
|
|
72
|
-
vi.spyOn(console,
|
|
72
|
+
vi.spyOn(console, "error").mockImplementation(() => {
|
|
73
73
|
// Intentionally empty - suppressing console output
|
|
74
74
|
});
|
|
75
|
-
vi.spyOn(console,
|
|
75
|
+
vi.spyOn(console, "warn").mockImplementation(() => {
|
|
76
76
|
// Intentionally empty - suppressing console output
|
|
77
77
|
});
|
|
78
78
|
return {
|