@stardeck-customer-apps/testing 0.1.0
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/SKILL.md +118 -0
- package/dist/config.d.mts +16 -0
- package/dist/config.d.ts +16 -0
- package/dist/config.js +57 -0
- package/dist/config.mjs +32 -0
- package/dist/index.d.mts +143 -0
- package/dist/index.d.ts +143 -0
- package/dist/index.js +910 -0
- package/dist/index.mjs +865 -0
- package/dist/next/headers-shim.d.mts +38 -0
- package/dist/next/headers-shim.d.ts +38 -0
- package/dist/next/headers-shim.js +114 -0
- package/dist/next/headers-shim.mjs +86 -0
- package/dist/server-only-shim.d.mts +2 -0
- package/dist/server-only-shim.d.ts +2 -0
- package/dist/server-only-shim.js +18 -0
- package/dist/server-only-shim.mjs +0 -0
- package/dist/setup.d.mts +2 -0
- package/dist/setup.d.ts +2 -0
- package/dist/setup.js +645 -0
- package/dist/setup.mjs +621 -0
- package/package.json +91 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Test-time replacement for `next/headers`, aliased in via the vitest config
|
|
5
|
+
* from `defineStardeckTestConfig()`. Outside a real Next request scope,
|
|
6
|
+
* `headers()`/`cookies()` would throw — this shim backs them with an
|
|
7
|
+
* AsyncLocalStorage context that `callRoute()` populates from the request it
|
|
8
|
+
* dispatches, with a fallback to ambient harness state (the active `asUser`).
|
|
9
|
+
*/
|
|
10
|
+
interface RequestScope {
|
|
11
|
+
headers: Headers;
|
|
12
|
+
cookies: Map<string, string>;
|
|
13
|
+
}
|
|
14
|
+
declare const requestScopeStorage: AsyncLocalStorage<RequestScope>;
|
|
15
|
+
declare function headers(): Promise<Headers>;
|
|
16
|
+
interface ShimCookie {
|
|
17
|
+
name: string;
|
|
18
|
+
value: string;
|
|
19
|
+
}
|
|
20
|
+
declare function cookies(): Promise<{
|
|
21
|
+
get(name: string): ShimCookie | undefined;
|
|
22
|
+
getAll(): ShimCookie[];
|
|
23
|
+
has(name: string): boolean;
|
|
24
|
+
set(name: string | ShimCookie, value?: string): void;
|
|
25
|
+
delete(name: string): void;
|
|
26
|
+
[Symbol.iterator](): ArrayIterator<readonly [string, {
|
|
27
|
+
readonly name: string;
|
|
28
|
+
readonly value: string;
|
|
29
|
+
}]>;
|
|
30
|
+
readonly size: number;
|
|
31
|
+
}>;
|
|
32
|
+
declare function draftMode(): Promise<{
|
|
33
|
+
isEnabled: boolean;
|
|
34
|
+
enable(): void;
|
|
35
|
+
disable(): void;
|
|
36
|
+
}>;
|
|
37
|
+
|
|
38
|
+
export { type RequestScope, type ShimCookie, cookies, draftMode, headers, requestScopeStorage };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Test-time replacement for `next/headers`, aliased in via the vitest config
|
|
5
|
+
* from `defineStardeckTestConfig()`. Outside a real Next request scope,
|
|
6
|
+
* `headers()`/`cookies()` would throw — this shim backs them with an
|
|
7
|
+
* AsyncLocalStorage context that `callRoute()` populates from the request it
|
|
8
|
+
* dispatches, with a fallback to ambient harness state (the active `asUser`).
|
|
9
|
+
*/
|
|
10
|
+
interface RequestScope {
|
|
11
|
+
headers: Headers;
|
|
12
|
+
cookies: Map<string, string>;
|
|
13
|
+
}
|
|
14
|
+
declare const requestScopeStorage: AsyncLocalStorage<RequestScope>;
|
|
15
|
+
declare function headers(): Promise<Headers>;
|
|
16
|
+
interface ShimCookie {
|
|
17
|
+
name: string;
|
|
18
|
+
value: string;
|
|
19
|
+
}
|
|
20
|
+
declare function cookies(): Promise<{
|
|
21
|
+
get(name: string): ShimCookie | undefined;
|
|
22
|
+
getAll(): ShimCookie[];
|
|
23
|
+
has(name: string): boolean;
|
|
24
|
+
set(name: string | ShimCookie, value?: string): void;
|
|
25
|
+
delete(name: string): void;
|
|
26
|
+
[Symbol.iterator](): ArrayIterator<readonly [string, {
|
|
27
|
+
readonly name: string;
|
|
28
|
+
readonly value: string;
|
|
29
|
+
}]>;
|
|
30
|
+
readonly size: number;
|
|
31
|
+
}>;
|
|
32
|
+
declare function draftMode(): Promise<{
|
|
33
|
+
isEnabled: boolean;
|
|
34
|
+
enable(): void;
|
|
35
|
+
disable(): void;
|
|
36
|
+
}>;
|
|
37
|
+
|
|
38
|
+
export { type RequestScope, type ShimCookie, cookies, draftMode, headers, requestScopeStorage };
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/next/headers-shim.ts
|
|
21
|
+
var headers_shim_exports = {};
|
|
22
|
+
__export(headers_shim_exports, {
|
|
23
|
+
cookies: () => cookies,
|
|
24
|
+
draftMode: () => draftMode,
|
|
25
|
+
headers: () => headers,
|
|
26
|
+
requestScopeStorage: () => requestScopeStorage
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(headers_shim_exports);
|
|
29
|
+
var import_node_async_hooks = require("async_hooks");
|
|
30
|
+
|
|
31
|
+
// src/global-singleton.ts
|
|
32
|
+
function globalSingleton(key, create) {
|
|
33
|
+
const symbol = /* @__PURE__ */ Symbol.for(`stardeck-testing.${key}`);
|
|
34
|
+
const holder = globalThis;
|
|
35
|
+
holder[symbol] ??= create();
|
|
36
|
+
return holder[symbol];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// src/state.ts
|
|
40
|
+
var state = globalSingleton("state", () => ({
|
|
41
|
+
db: null,
|
|
42
|
+
currentUser: null,
|
|
43
|
+
sessions: /* @__PURE__ */ new Map(),
|
|
44
|
+
refreshSessions: /* @__PURE__ */ new Map(),
|
|
45
|
+
emails: [],
|
|
46
|
+
emailCounter: 0,
|
|
47
|
+
allowNetwork: false
|
|
48
|
+
}));
|
|
49
|
+
|
|
50
|
+
// src/next/headers-shim.ts
|
|
51
|
+
var requestScopeStorage = globalSingleton(
|
|
52
|
+
"request-scope",
|
|
53
|
+
() => new import_node_async_hooks.AsyncLocalStorage()
|
|
54
|
+
);
|
|
55
|
+
function ambientScope() {
|
|
56
|
+
const headers2 = new Headers();
|
|
57
|
+
if (state.currentUser) {
|
|
58
|
+
headers2.set("x-stardeck-user", JSON.stringify(state.currentUser));
|
|
59
|
+
}
|
|
60
|
+
return { headers: headers2, cookies: /* @__PURE__ */ new Map() };
|
|
61
|
+
}
|
|
62
|
+
function currentScope() {
|
|
63
|
+
return requestScopeStorage.getStore() ?? ambientScope();
|
|
64
|
+
}
|
|
65
|
+
async function headers() {
|
|
66
|
+
return currentScope().headers;
|
|
67
|
+
}
|
|
68
|
+
async function cookies() {
|
|
69
|
+
const scope = currentScope();
|
|
70
|
+
return {
|
|
71
|
+
get(name) {
|
|
72
|
+
const value = scope.cookies.get(name);
|
|
73
|
+
return value === void 0 ? void 0 : { name, value };
|
|
74
|
+
},
|
|
75
|
+
getAll() {
|
|
76
|
+
return Array.from(scope.cookies, ([name, value]) => ({ name, value }));
|
|
77
|
+
},
|
|
78
|
+
has(name) {
|
|
79
|
+
return scope.cookies.has(name);
|
|
80
|
+
},
|
|
81
|
+
set(name, value) {
|
|
82
|
+
if (typeof name === "object") {
|
|
83
|
+
scope.cookies.set(name.name, name.value);
|
|
84
|
+
} else {
|
|
85
|
+
scope.cookies.set(name, value ?? "");
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
delete(name) {
|
|
89
|
+
scope.cookies.delete(name);
|
|
90
|
+
},
|
|
91
|
+
[Symbol.iterator]() {
|
|
92
|
+
return Array.from(scope.cookies, ([name, value]) => [name, { name, value }])[Symbol.iterator]();
|
|
93
|
+
},
|
|
94
|
+
get size() {
|
|
95
|
+
return scope.cookies.size;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
async function draftMode() {
|
|
100
|
+
return {
|
|
101
|
+
isEnabled: false,
|
|
102
|
+
enable() {
|
|
103
|
+
},
|
|
104
|
+
disable() {
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
109
|
+
0 && (module.exports = {
|
|
110
|
+
cookies,
|
|
111
|
+
draftMode,
|
|
112
|
+
headers,
|
|
113
|
+
requestScopeStorage
|
|
114
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// src/next/headers-shim.ts
|
|
2
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
3
|
+
|
|
4
|
+
// src/global-singleton.ts
|
|
5
|
+
function globalSingleton(key, create) {
|
|
6
|
+
const symbol = /* @__PURE__ */ Symbol.for(`stardeck-testing.${key}`);
|
|
7
|
+
const holder = globalThis;
|
|
8
|
+
holder[symbol] ??= create();
|
|
9
|
+
return holder[symbol];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// src/state.ts
|
|
13
|
+
var state = globalSingleton("state", () => ({
|
|
14
|
+
db: null,
|
|
15
|
+
currentUser: null,
|
|
16
|
+
sessions: /* @__PURE__ */ new Map(),
|
|
17
|
+
refreshSessions: /* @__PURE__ */ new Map(),
|
|
18
|
+
emails: [],
|
|
19
|
+
emailCounter: 0,
|
|
20
|
+
allowNetwork: false
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
// src/next/headers-shim.ts
|
|
24
|
+
var requestScopeStorage = globalSingleton(
|
|
25
|
+
"request-scope",
|
|
26
|
+
() => new AsyncLocalStorage()
|
|
27
|
+
);
|
|
28
|
+
function ambientScope() {
|
|
29
|
+
const headers2 = new Headers();
|
|
30
|
+
if (state.currentUser) {
|
|
31
|
+
headers2.set("x-stardeck-user", JSON.stringify(state.currentUser));
|
|
32
|
+
}
|
|
33
|
+
return { headers: headers2, cookies: /* @__PURE__ */ new Map() };
|
|
34
|
+
}
|
|
35
|
+
function currentScope() {
|
|
36
|
+
return requestScopeStorage.getStore() ?? ambientScope();
|
|
37
|
+
}
|
|
38
|
+
async function headers() {
|
|
39
|
+
return currentScope().headers;
|
|
40
|
+
}
|
|
41
|
+
async function cookies() {
|
|
42
|
+
const scope = currentScope();
|
|
43
|
+
return {
|
|
44
|
+
get(name) {
|
|
45
|
+
const value = scope.cookies.get(name);
|
|
46
|
+
return value === void 0 ? void 0 : { name, value };
|
|
47
|
+
},
|
|
48
|
+
getAll() {
|
|
49
|
+
return Array.from(scope.cookies, ([name, value]) => ({ name, value }));
|
|
50
|
+
},
|
|
51
|
+
has(name) {
|
|
52
|
+
return scope.cookies.has(name);
|
|
53
|
+
},
|
|
54
|
+
set(name, value) {
|
|
55
|
+
if (typeof name === "object") {
|
|
56
|
+
scope.cookies.set(name.name, name.value);
|
|
57
|
+
} else {
|
|
58
|
+
scope.cookies.set(name, value ?? "");
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
delete(name) {
|
|
62
|
+
scope.cookies.delete(name);
|
|
63
|
+
},
|
|
64
|
+
[Symbol.iterator]() {
|
|
65
|
+
return Array.from(scope.cookies, ([name, value]) => [name, { name, value }])[Symbol.iterator]();
|
|
66
|
+
},
|
|
67
|
+
get size() {
|
|
68
|
+
return scope.cookies.size;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
async function draftMode() {
|
|
73
|
+
return {
|
|
74
|
+
isEnabled: false,
|
|
75
|
+
enable() {
|
|
76
|
+
},
|
|
77
|
+
disable() {
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export {
|
|
82
|
+
cookies,
|
|
83
|
+
draftMode,
|
|
84
|
+
headers,
|
|
85
|
+
requestScopeStorage
|
|
86
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/server-only-shim.ts
|
|
17
|
+
var server_only_shim_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(server_only_shim_exports);
|
|
File without changes
|
package/dist/setup.d.mts
ADDED
package/dist/setup.d.ts
ADDED