twd-js 1.6.3 → 1.6.5
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/dist/bundled.es.js +301 -301
- package/dist/index.cjs.js +33 -33
- package/dist/index.d.ts +624 -0
- package/dist/index.es.js +1474 -1427
- package/dist/mock-sw.js +1 -1
- package/dist/runner-ci.d.ts +27 -0
- package/dist/runner.d.ts +62 -0
- package/dist/ui.d.ts +9 -0
- package/dist/vite-plugin.d.ts +66 -0
- package/package.json +2 -2
- /package/dist/{src/bundled.d.ts → bundled.d.ts} +0 -0
package/dist/mock-sw.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(){var d=t=>{try{return new RegExp(t),!0}catch{return!1}},f=new Set(["js","mjs","cjs","ts","tsx","jsx","mts","cts","css","scss","sass","less","styl","html","htm","xml","xhtml","vue","svelte","json","yaml","yml","toml","csv","txt","md","mdx","pdf","doc","docx","png","jpg","jpeg","gif","svg","webp","ico","bmp","avif","woff","woff2","ttf","eot","otf","mp3","mp4","webm","ogg","wav","zip","tar","gz","rar","map"]),c=t=>{const s=t.split("?")[0].match(/\.([a-zA-Z0-9]+)$/);return s?f.has(s[1].toLowerCase()):!1},h=(t,s)=>{const i=t.indexOf(s);if(i===-1)return!1;const e=i+s.length,a=t[e];if(a===void 0)return!0;const n=t.indexOf("?");return n!==-1&&e>n?!0:"?#&".includes(a)};function m(t,s,i){return i.find(e=>{const a=e.method.toLowerCase()===t.toLowerCase();if(e.urlRegex&&d(e.url)){const l=new RegExp(e.url);return a&&l.test(s)}if(c(e.url))return a&&s.includes(e.url);const n=e.url===s||h(s,e.url);return a&&n&&!c(s)})}function p(t,s,i,e){t.forEach(a=>a.postMessage({type:"EXECUTED",alias:s.alias,request:i,hitCount:e}))}var y=(t,s,i)=>{const e=![204,205,304].includes(s),a=e?JSON.stringify(t):null;return new Response(a,{status:s,headers:e?i||{"Content-Type":"application/json"}:i||{}})},u="1.6.
|
|
1
|
+
(function(){var d=t=>{try{return new RegExp(t),!0}catch{return!1}},f=new Set(["js","mjs","cjs","ts","tsx","jsx","mts","cts","css","scss","sass","less","styl","html","htm","xml","xhtml","vue","svelte","json","yaml","yml","toml","csv","txt","md","mdx","pdf","doc","docx","png","jpg","jpeg","gif","svg","webp","ico","bmp","avif","woff","woff2","ttf","eot","otf","mp3","mp4","webm","ogg","wav","zip","tar","gz","rar","map"]),c=t=>{const s=t.split("?")[0].match(/\.([a-zA-Z0-9]+)$/);return s?f.has(s[1].toLowerCase()):!1},h=(t,s)=>{const i=t.indexOf(s);if(i===-1)return!1;const e=i+s.length,a=t[e];if(a===void 0)return!0;const n=t.indexOf("?");return n!==-1&&e>n?!0:"?#&".includes(a)};function m(t,s,i){return i.find(e=>{const a=e.method.toLowerCase()===t.toLowerCase();if(e.urlRegex&&d(e.url)){const l=new RegExp(e.url);return a&&l.test(s)}if(c(e.url))return a&&s.includes(e.url);const n=e.url===s||h(s,e.url);return a&&n&&!c(s)})}function p(t,s,i,e){t.forEach(a=>a.postMessage({type:"EXECUTED",alias:s.alias,request:i,hitCount:e}))}var y=(t,s,i)=>{const e=![204,205,304].includes(s),a=e?JSON.stringify(t):null;return new Response(a,{status:s,headers:e?i||{"Content-Type":"application/json"}:i||{}})},u="1.6.5",r=[],o={},g=async t=>{const{method:s}=t.request,i=t.request.url,e=m(s,i,r);e&&(console.log("[TWD] Mock hit:",e.alias,s,i),t.respondWith((async()=>{let a=null;const n=t.request.headers.get("content-type")||"application/json";if(n.includes("application/json"))try{a=await t.request.clone().json()}catch{}else if(n.includes("form"))try{const l=await t.request.clone().formData();a={},l.forEach((x,E)=>{a[E]=x})}catch{}else if(n.includes("text"))try{a=await t.request.clone().text()}catch{}else if(n.includes("octet-stream"))try{a=await t.request.clone().arrayBuffer()}catch{}else if(n.includes("image"))try{a=await t.request.clone().blob()}catch{}else try{a=await t.request.clone().text()}catch{}return o[e.alias]||(o[e.alias]=0),o[e.alias]++,p(await self.clients.matchAll(),e,a,o[e.alias]),e.delay&&e.delay>0&&await new Promise(l=>setTimeout(l,e.delay)),y(e.response,e.status??200,e.responseHeaders)})()))},w=t=>{t!=="1.6.5"&&console.warn(`[TWD] ⚠️ Version mismatch detected:
|
|
2
2
|
Client version: ${t}
|
|
3
3
|
Service Worker version: ${u}
|
|
4
4
|
|
package/dist/runner-ci.d.ts
CHANGED
|
@@ -1 +1,28 @@
|
|
|
1
|
+
export declare const executeTests: () => Promise<{
|
|
2
|
+
handlers: Handler[];
|
|
3
|
+
testStatus: TestResult[];
|
|
4
|
+
}>;
|
|
5
|
+
|
|
6
|
+
declare interface Handler {
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
parent?: string;
|
|
10
|
+
handler: () => void | Promise<void>;
|
|
11
|
+
children?: string[];
|
|
12
|
+
type: 'suite' | 'test';
|
|
13
|
+
status?: 'idle' | 'pass' | 'fail' | 'skip' | 'running';
|
|
14
|
+
logs: string[];
|
|
15
|
+
depth: number;
|
|
16
|
+
only?: boolean;
|
|
17
|
+
skip?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export declare const reportResults: (handlers: Handler[], testResults: TestResult[]) => void;
|
|
21
|
+
|
|
22
|
+
declare interface TestResult {
|
|
23
|
+
id: string;
|
|
24
|
+
status: 'pass' | 'fail' | 'skip';
|
|
25
|
+
error?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
1
28
|
export { }
|
package/dist/runner.d.ts
CHANGED
|
@@ -1 +1,63 @@
|
|
|
1
|
+
export declare const afterEach: (fn: HookFn) => void;
|
|
2
|
+
|
|
3
|
+
export declare const beforeEach: (fn: HookFn) => void;
|
|
4
|
+
|
|
5
|
+
export declare const clearTests: () => void;
|
|
6
|
+
|
|
7
|
+
export declare const describe: {
|
|
8
|
+
(name: string, handler: () => void): void;
|
|
9
|
+
only(name: string, handler: () => void): void;
|
|
10
|
+
skip(name: string, handler: () => void): void;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export declare interface Handler {
|
|
14
|
+
id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
parent?: string;
|
|
17
|
+
handler: () => void | Promise<void>;
|
|
18
|
+
children?: string[];
|
|
19
|
+
type: 'suite' | 'test';
|
|
20
|
+
status?: 'idle' | 'pass' | 'fail' | 'skip' | 'running';
|
|
21
|
+
logs: string[];
|
|
22
|
+
depth: number;
|
|
23
|
+
only?: boolean;
|
|
24
|
+
skip?: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export declare const handlers: Map<string, Handler>;
|
|
28
|
+
|
|
29
|
+
declare type HookFn = () => void | Promise<void>;
|
|
30
|
+
|
|
31
|
+
export declare const it: {
|
|
32
|
+
(name: string, handler: () => void | Promise<void>): void;
|
|
33
|
+
only(name: string, handler: () => void | Promise<void>): void;
|
|
34
|
+
skip(name: string, handler?: () => void | Promise<void>): void;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export declare interface RunnerEvents {
|
|
38
|
+
onStart: (test: Handler) => void;
|
|
39
|
+
onPass: (test: Handler, retryAttempt?: number) => void;
|
|
40
|
+
onFail: (test: Handler, error: Error) => void;
|
|
41
|
+
onSkip: (test: Handler) => void;
|
|
42
|
+
onSuiteStart?: (suite: Handler) => void;
|
|
43
|
+
onSuiteEnd?: (suite: Handler) => void;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export declare class TestRunner {
|
|
47
|
+
private events;
|
|
48
|
+
private retryCount;
|
|
49
|
+
constructor(events: RunnerEvents, options?: TestRunnerOptions);
|
|
50
|
+
runAll(): Promise<Map<string, Handler>>;
|
|
51
|
+
runSingle(id: string): Promise<void>;
|
|
52
|
+
runByIds(ids: string[]): Promise<Map<string, Handler>>;
|
|
53
|
+
private runSuiteByIds;
|
|
54
|
+
private hasDescendantInSet;
|
|
55
|
+
private runSuite;
|
|
56
|
+
private runTest;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export declare interface TestRunnerOptions {
|
|
60
|
+
retryCount?: number;
|
|
61
|
+
}
|
|
62
|
+
|
|
1
63
|
export { }
|
package/dist/ui.d.ts
CHANGED
|
@@ -1 +1,10 @@
|
|
|
1
|
+
import { JSX } from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
export declare function MockedComponent<TProps extends Record<string, any>>({ name, children, }: MockedComponentProps<TProps>): JSX.Element;
|
|
4
|
+
|
|
5
|
+
declare interface MockedComponentProps<TProps = any> {
|
|
6
|
+
name: string;
|
|
7
|
+
children: React.ReactElement<TProps>;
|
|
8
|
+
}
|
|
9
|
+
|
|
1
10
|
export { }
|
package/dist/vite-plugin.d.ts
CHANGED
|
@@ -1 +1,67 @@
|
|
|
1
|
+
import { Plugin as Plugin_2 } from 'vite';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Vite plugin to remove the mock service worker file from the build output.
|
|
5
|
+
* This is useful for production builds where you don't want the mock service worker to be included.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { removeMockServiceWorker } from 'twd-js';
|
|
10
|
+
*
|
|
11
|
+
* export default defineConfig({
|
|
12
|
+
* plugins: [
|
|
13
|
+
* // ... other plugins
|
|
14
|
+
* removeMockServiceWorker()
|
|
15
|
+
* ]
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function removeMockServiceWorker(): Plugin_2;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Vite plugin to handle HMR for TWD test files.
|
|
23
|
+
* When a TWD test file is updated, it forces a full page reload to prevent
|
|
24
|
+
* duplicate test entries that occur when HMR reloads test modules.
|
|
25
|
+
*
|
|
26
|
+
* This plugin only runs in development mode (serve) and does not affect Vitest test runs.
|
|
27
|
+
*
|
|
28
|
+
* @param options - Configuration options for the plugin
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { twdHmr } from 'twd-js/vite-plugin';
|
|
32
|
+
*
|
|
33
|
+
* export default defineConfig({
|
|
34
|
+
* plugins: [
|
|
35
|
+
* // ... other plugins
|
|
36
|
+
* twdHmr() // Uses default pattern: .twd.test.ts
|
|
37
|
+
* ]
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* // Custom pattern
|
|
43
|
+
* twdHmr({ testFilePattern: '.twd.test.tsx' })
|
|
44
|
+
* ```
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* // Custom function
|
|
48
|
+
* twdHmr({
|
|
49
|
+
* testFilePattern: (file) => file.includes('.twd.test.')
|
|
50
|
+
* })
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function twdHmr(options?: TwdHmrOptions): Plugin_2;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Options for the TWD HMR plugin.
|
|
57
|
+
*/
|
|
58
|
+
export declare interface TwdHmrOptions {
|
|
59
|
+
/**
|
|
60
|
+
* Pattern to match test files. Defaults to `.twd.test.ts`.
|
|
61
|
+
* Can be a string (checked with `endsWith`) or a function that returns a boolean.
|
|
62
|
+
* @default ".twd.test.ts"
|
|
63
|
+
*/
|
|
64
|
+
testFilePattern?: string | ((file: string) => boolean);
|
|
65
|
+
}
|
|
66
|
+
|
|
1
67
|
export { }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "twd-js",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.5",
|
|
4
4
|
"description": "Test While Developing (TWD) - in-browser testing",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
"@vitest/coverage-v8": "^4.1.2",
|
|
89
89
|
"conventional-changelog": "^7.2.0",
|
|
90
90
|
"jsdom": "^29.0.1",
|
|
91
|
-
"typescript": "
|
|
91
|
+
"typescript": "~5.9.3",
|
|
92
92
|
"vite": "^8.0.3",
|
|
93
93
|
"vite-plugin-dts": "^4.5.4",
|
|
94
94
|
"vitepress": "^2.0.0-alpha.12",
|
|
File without changes
|