vitest-gwt 4.1.0 → 4.1.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 +13 -0
- package/lib/index.cjs +1 -1
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +7 -4
- package/lib/index.d.mts +7 -4
- package/lib/index.mjs +1 -1
- package/lib/index.mjs.map +1 -1
- package/package.json +12 -10
- package/src/index.ts +5 -1
- package/src/withAspect.ts +9 -4
package/README.md
CHANGED
|
@@ -103,6 +103,19 @@ The `afterEach` has access to whatever values you put on the Context in the
|
|
|
103
103
|
`beforeEach`. It does NOT have access to the values put on the Context during
|
|
104
104
|
the specific test.
|
|
105
105
|
|
|
106
|
+
To raise the Vitest hook timeout for slow setup, type the before callback as
|
|
107
|
+
`AspectFunction` and set `timeout` (ms):
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
import { withAspect, type AspectFunction } from "vitest-gwt";
|
|
111
|
+
|
|
112
|
+
const setup: AspectFunction<Context> = function () {
|
|
113
|
+
// slow prep
|
|
114
|
+
};
|
|
115
|
+
setup.timeout = 100_000;
|
|
116
|
+
withAspect(setup);
|
|
117
|
+
```
|
|
118
|
+
|
|
106
119
|
## Detailed Usage
|
|
107
120
|
|
|
108
121
|
Full guides live in [`docs/`](./docs) — writing tests, expecting errors,
|
package/lib/index.cjs
CHANGED
|
@@ -9,7 +9,7 @@ const withAspectBuilder = (beforeEach, afterEach) => (before, after) => {
|
|
|
9
9
|
beforeEach(async () => {
|
|
10
10
|
gwt_runner.TestContext.createContext();
|
|
11
11
|
await before.bind(gwt_runner.TestContext.context)();
|
|
12
|
-
});
|
|
12
|
+
}, before.timeout);
|
|
13
13
|
afterEach(async () => {
|
|
14
14
|
if (after) await after.bind(gwt_runner.TestContext.context)();
|
|
15
15
|
gwt_runner.TestContext.releaseContext();
|
package/lib/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["TestContext","vitestBeforeEach","vitestAfterEach"],"sources":["../src/withAspect.ts","../src/index.ts"],"sourcesContent":["import type { beforeEach as vitestBeforeEach, afterEach as vitestAfterEach } from \"vitest\";\nimport { TestContext } from \"gwt-runner\";\n\ntype
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["TestContext","gwtRunner","vitestBeforeEach","vitestAfterEach"],"sources":["../src/withAspect.ts","../src/index.ts"],"sourcesContent":["import type { beforeEach as vitestBeforeEach, afterEach as vitestAfterEach } from \"vitest\";\nimport { TestContext } from \"gwt-runner\";\n\ntype AfterCallback<T> = (this: T) => unknown;\n\nexport type AspectFunction<T = unknown> = {\n (this: T): unknown;\n timeout?: number;\n};\n\nexport type WithAspectBuilder = (\n beforeEach: typeof vitestBeforeEach,\n afterEach: typeof vitestAfterEach,\n) => <T>(before: AspectFunction<T>, after?: AfterCallback<T>) => void;\n\nconst withAspectBuilder: WithAspectBuilder =\n (beforeEach, afterEach) =>\n <T>(before: AspectFunction<T>, after?: AfterCallback<T>): void => {\n beforeEach(async () => {\n TestContext.createContext();\n\n await (before.bind(TestContext.context as T) as any)();\n }, before.timeout);\n\n afterEach(async () => {\n if (after) {\n await (after.bind(TestContext.context as T) as any)();\n }\n\n TestContext.releaseContext();\n });\n };\n\nexport default withAspectBuilder;\n","import {\n test as vitest,\n beforeEach as vitestBeforeEach,\n afterEach as vitestAfterEach,\n} from \"vitest\";\nimport { gwtRunner, TestContext } from \"gwt-runner\";\nimport withAspectBuilder, {\n type AspectFunction,\n type WithAspectBuilder,\n} from \"./withAspect\";\n\nconst test: ReturnType<typeof gwtRunner> = gwtRunner(vitest);\n\nexport default test;\nexport { TestContext };\nexport type { AspectFunction };\n\nexport const withAspect: ReturnType<WithAspectBuilder> = withAspectBuilder(\n vitestBeforeEach,\n vitestAfterEach,\n);\n"],"mappings":";;;;;;;AAeA,MAAM,qBACH,YAAY,eACT,QAA2B,UAAmC;CAChE,WAAW,YAAY;EACrB,WAAA,YAAY,cAAc;EAE1B,MAAO,OAAO,KAAKA,WAAAA,YAAY,OAAY,CAAC,CAAS;CACvD,GAAG,OAAO,OAAO;CAEjB,UAAU,YAAY;EACpB,IAAI,OACF,MAAO,MAAM,KAAKA,WAAAA,YAAY,OAAY,CAAC,CAAS;EAGtD,WAAA,YAAY,eAAe;CAC7B,CAAC;AACH;;;ACpBF,MAAM,QAAA,GAAqCC,WAAAA,UAAAA,CAAU,OAAA,IAAM;AAM3D,MAAa,aAA4C,kBACvDC,OAAAA,YACAC,OAAAA,SACF"}
|
package/lib/index.d.cts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { TestContext, gwtRunner } from "gwt-runner";
|
|
2
2
|
import { afterEach, beforeEach } from "vitest";
|
|
3
|
-
|
|
4
3
|
//#region src/withAspect.d.ts
|
|
5
|
-
type
|
|
6
|
-
type
|
|
4
|
+
type AfterCallback<T> = (this: T) => unknown;
|
|
5
|
+
type AspectFunction<T = unknown> = {
|
|
6
|
+
(this: T): unknown;
|
|
7
|
+
timeout?: number;
|
|
8
|
+
};
|
|
9
|
+
type WithAspectBuilder = (beforeEach: typeof beforeEach, afterEach: typeof afterEach) => <T>(before: AspectFunction<T>, after?: AfterCallback<T>) => void;
|
|
7
10
|
//#endregion
|
|
8
11
|
//#region src/index.d.ts
|
|
9
12
|
declare const test: ReturnType<typeof gwtRunner>;
|
|
10
13
|
declare const withAspect: ReturnType<WithAspectBuilder>;
|
|
11
14
|
//#endregion
|
|
12
|
-
export { TestContext, test as default, withAspect };
|
|
15
|
+
export { type AspectFunction, TestContext, test as default, withAspect };
|
|
13
16
|
//# sourceMappingURL=index.d.cts.map
|
package/lib/index.d.mts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { afterEach, beforeEach } from "vitest";
|
|
2
2
|
import { TestContext, gwtRunner } from "gwt-runner";
|
|
3
|
-
|
|
4
3
|
//#region src/withAspect.d.ts
|
|
5
|
-
type
|
|
6
|
-
type
|
|
4
|
+
type AfterCallback<T> = (this: T) => unknown;
|
|
5
|
+
type AspectFunction<T = unknown> = {
|
|
6
|
+
(this: T): unknown;
|
|
7
|
+
timeout?: number;
|
|
8
|
+
};
|
|
9
|
+
type WithAspectBuilder = (beforeEach: typeof beforeEach, afterEach: typeof afterEach) => <T>(before: AspectFunction<T>, after?: AfterCallback<T>) => void;
|
|
7
10
|
//#endregion
|
|
8
11
|
//#region src/index.d.ts
|
|
9
12
|
declare const test: ReturnType<typeof gwtRunner>;
|
|
10
13
|
declare const withAspect: ReturnType<WithAspectBuilder>;
|
|
11
14
|
//#endregion
|
|
12
|
-
export { TestContext, test as default, withAspect };
|
|
15
|
+
export { type AspectFunction, TestContext, test as default, withAspect };
|
|
13
16
|
//# sourceMappingURL=index.d.mts.map
|
package/lib/index.mjs
CHANGED
|
@@ -5,7 +5,7 @@ const withAspectBuilder = (beforeEach, afterEach) => (before, after) => {
|
|
|
5
5
|
beforeEach(async () => {
|
|
6
6
|
TestContext$1.createContext();
|
|
7
7
|
await before.bind(TestContext$1.context)();
|
|
8
|
-
});
|
|
8
|
+
}, before.timeout);
|
|
9
9
|
afterEach(async () => {
|
|
10
10
|
if (after) await after.bind(TestContext$1.context)();
|
|
11
11
|
TestContext$1.releaseContext();
|
package/lib/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["TestContext","vitest","vitestBeforeEach","vitestAfterEach"],"sources":["../src/withAspect.ts","../src/index.ts"],"sourcesContent":["import type { beforeEach as vitestBeforeEach, afterEach as vitestAfterEach } from \"vitest\";\nimport { TestContext } from \"gwt-runner\";\n\ntype
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["TestContext","vitest","vitestBeforeEach","vitestAfterEach"],"sources":["../src/withAspect.ts","../src/index.ts"],"sourcesContent":["import type { beforeEach as vitestBeforeEach, afterEach as vitestAfterEach } from \"vitest\";\nimport { TestContext } from \"gwt-runner\";\n\ntype AfterCallback<T> = (this: T) => unknown;\n\nexport type AspectFunction<T = unknown> = {\n (this: T): unknown;\n timeout?: number;\n};\n\nexport type WithAspectBuilder = (\n beforeEach: typeof vitestBeforeEach,\n afterEach: typeof vitestAfterEach,\n) => <T>(before: AspectFunction<T>, after?: AfterCallback<T>) => void;\n\nconst withAspectBuilder: WithAspectBuilder =\n (beforeEach, afterEach) =>\n <T>(before: AspectFunction<T>, after?: AfterCallback<T>): void => {\n beforeEach(async () => {\n TestContext.createContext();\n\n await (before.bind(TestContext.context as T) as any)();\n }, before.timeout);\n\n afterEach(async () => {\n if (after) {\n await (after.bind(TestContext.context as T) as any)();\n }\n\n TestContext.releaseContext();\n });\n };\n\nexport default withAspectBuilder;\n","import {\n test as vitest,\n beforeEach as vitestBeforeEach,\n afterEach as vitestAfterEach,\n} from \"vitest\";\nimport { gwtRunner, TestContext } from \"gwt-runner\";\nimport withAspectBuilder, {\n type AspectFunction,\n type WithAspectBuilder,\n} from \"./withAspect\";\n\nconst test: ReturnType<typeof gwtRunner> = gwtRunner(vitest);\n\nexport default test;\nexport { TestContext };\nexport type { AspectFunction };\n\nexport const withAspect: ReturnType<WithAspectBuilder> = withAspectBuilder(\n vitestBeforeEach,\n vitestAfterEach,\n);\n"],"mappings":";;;AAeA,MAAM,qBACH,YAAY,eACT,QAA2B,UAAmC;CAChE,WAAW,YAAY;EACrB,cAAY,cAAc;EAE1B,MAAO,OAAO,KAAKA,cAAY,OAAY,CAAC,CAAS;CACvD,GAAG,OAAO,OAAO;CAEjB,UAAU,YAAY;EACpB,IAAI,OACF,MAAO,MAAM,KAAKA,cAAY,OAAY,CAAC,CAAS;EAGtD,cAAY,eAAe;CAC7B,CAAC;AACH;;;ACpBF,MAAM,OAAqC,UAAUC,MAAM;AAM3D,MAAa,aAA4C,kBACvDC,YACAC,SACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest-gwt",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.1",
|
|
4
4
|
"description": "A small library to help Vitest support given-when-then style testing without a bunch of overhead",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"given",
|
|
@@ -26,6 +26,9 @@
|
|
|
26
26
|
"src",
|
|
27
27
|
"!**/*.spec.ts"
|
|
28
28
|
],
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
29
32
|
"type": "module",
|
|
30
33
|
"main": "./lib/index.cjs",
|
|
31
34
|
"module": "./lib/index.mjs",
|
|
@@ -43,13 +46,6 @@
|
|
|
43
46
|
},
|
|
44
47
|
"./package.json": "./package.json"
|
|
45
48
|
},
|
|
46
|
-
"scripts": {
|
|
47
|
-
"build": "wireit",
|
|
48
|
-
"test": "wireit",
|
|
49
|
-
"lint": "wireit",
|
|
50
|
-
"test:coverage": "wireit",
|
|
51
|
-
"prepublishOnly": "wireit"
|
|
52
|
-
},
|
|
53
49
|
"dependencies": {
|
|
54
50
|
"gwt-runner": "^3.0.0"
|
|
55
51
|
},
|
|
@@ -58,13 +54,13 @@
|
|
|
58
54
|
"@vitest/coverage-v8": "^4.1.9",
|
|
59
55
|
"axios": "^1.18.0",
|
|
60
56
|
"typescript": "^6.0.3",
|
|
57
|
+
"vite-plus": "^0.2.9",
|
|
61
58
|
"vitest": "^4.1.9",
|
|
62
59
|
"wireit": "^0.14.12"
|
|
63
60
|
},
|
|
64
61
|
"peerDependencies": {
|
|
65
62
|
"vitest": ">=4.0.0"
|
|
66
63
|
},
|
|
67
|
-
"packageManager": "npm@11.12.1",
|
|
68
64
|
"wireit": {
|
|
69
65
|
"build": {
|
|
70
66
|
"command": "vp pack",
|
|
@@ -110,5 +106,11 @@
|
|
|
110
106
|
"build"
|
|
111
107
|
]
|
|
112
108
|
}
|
|
109
|
+
},
|
|
110
|
+
"scripts": {
|
|
111
|
+
"build": "wireit",
|
|
112
|
+
"test": "wireit",
|
|
113
|
+
"lint": "wireit",
|
|
114
|
+
"test:coverage": "wireit"
|
|
113
115
|
}
|
|
114
|
-
}
|
|
116
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -4,12 +4,16 @@ import {
|
|
|
4
4
|
afterEach as vitestAfterEach,
|
|
5
5
|
} from "vitest";
|
|
6
6
|
import { gwtRunner, TestContext } from "gwt-runner";
|
|
7
|
-
import withAspectBuilder, {
|
|
7
|
+
import withAspectBuilder, {
|
|
8
|
+
type AspectFunction,
|
|
9
|
+
type WithAspectBuilder,
|
|
10
|
+
} from "./withAspect";
|
|
8
11
|
|
|
9
12
|
const test: ReturnType<typeof gwtRunner> = gwtRunner(vitest);
|
|
10
13
|
|
|
11
14
|
export default test;
|
|
12
15
|
export { TestContext };
|
|
16
|
+
export type { AspectFunction };
|
|
13
17
|
|
|
14
18
|
export const withAspect: ReturnType<WithAspectBuilder> = withAspectBuilder(
|
|
15
19
|
vitestBeforeEach,
|
package/src/withAspect.ts
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
import type { beforeEach as vitestBeforeEach, afterEach as vitestAfterEach } from "vitest";
|
|
2
2
|
import { TestContext } from "gwt-runner";
|
|
3
3
|
|
|
4
|
-
type
|
|
4
|
+
type AfterCallback<T> = (this: T) => unknown;
|
|
5
|
+
|
|
6
|
+
export type AspectFunction<T = unknown> = {
|
|
7
|
+
(this: T): unknown;
|
|
8
|
+
timeout?: number;
|
|
9
|
+
};
|
|
5
10
|
|
|
6
11
|
export type WithAspectBuilder = (
|
|
7
12
|
beforeEach: typeof vitestBeforeEach,
|
|
8
13
|
afterEach: typeof vitestAfterEach,
|
|
9
|
-
) => <T>(before:
|
|
14
|
+
) => <T>(before: AspectFunction<T>, after?: AfterCallback<T>) => void;
|
|
10
15
|
|
|
11
16
|
const withAspectBuilder: WithAspectBuilder =
|
|
12
17
|
(beforeEach, afterEach) =>
|
|
13
|
-
<T>(before:
|
|
18
|
+
<T>(before: AspectFunction<T>, after?: AfterCallback<T>): void => {
|
|
14
19
|
beforeEach(async () => {
|
|
15
20
|
TestContext.createContext();
|
|
16
21
|
|
|
17
22
|
await (before.bind(TestContext.context as T) as any)();
|
|
18
|
-
});
|
|
23
|
+
}, before.timeout);
|
|
19
24
|
|
|
20
25
|
afterEach(async () => {
|
|
21
26
|
if (after) {
|