vitest-gwt 4.1.3 → 4.1.4-build.16

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/lib/index.cjs CHANGED
@@ -13,15 +13,49 @@ const withAspectBuilder = (beforeEach, afterEach) => (before, after) => {
13
13
  afterEach(async () => {
14
14
  if (after) await after.bind(gwt_runner.TestContext.context)();
15
15
  gwt_runner.TestContext.releaseContext();
16
- });
16
+ }, after?.timeout);
17
+ };
18
+ //#endregion
19
+ //#region src/withTestOptions.ts
20
+ const suiteOptions = /* @__PURE__ */ new WeakMap();
21
+ const getSuiteTask = (collector) => collector.suite;
22
+ const resolveFromSuite = (suite) => {
23
+ let current = suite;
24
+ while (current) {
25
+ const options = suiteOptions.get(current);
26
+ if (options) return options;
27
+ current = current.suite;
28
+ }
29
+ };
30
+ const resolveTestOptions = (collector) => {
31
+ const options = resolveFromSuite(getSuiteTask(collector));
32
+ if (options == null || Object.keys(options).length === 0) return;
33
+ return options;
34
+ };
35
+ const withTestOptionsBuilder = (getSuite) => (configure) => {
36
+ const collector = getSuite();
37
+ const suiteTask = getSuiteTask(collector);
38
+ const testOptions = { ...suiteTask?.suite ? resolveFromSuite(suiteTask.suite) : void 0 };
39
+ configure(testOptions);
40
+ if (suiteTask) suiteOptions.set(suiteTask, testOptions);
41
+ };
42
+ //#endregion
43
+ //#region src/createVitestTestFunction.ts
44
+ const createVitestTestFunction = (test, getSuite) => (name, callback) => {
45
+ const options = resolveTestOptions(getSuite());
46
+ if (options) return test(name, options, callback);
47
+ return test(name, callback);
17
48
  };
18
49
  //#endregion
19
50
  //#region src/index.ts
20
- const test = (0, gwt_runner.gwtRunner)(vitest.test);
51
+ const test = (0, gwt_runner.gwtRunner)(createVitestTestFunction(vitest.test, vitest.TestRunner.getCurrentSuite));
21
52
  const withAspect = withAspectBuilder(vitest.beforeEach, vitest.afterEach);
53
+ const withTestOptions = withTestOptionsBuilder(vitest.TestRunner.getCurrentSuite);
22
54
  //#endregion
23
55
  exports.TestContext = gwt_runner.TestContext;
24
56
  exports.default = test;
57
+ exports.test = test;
25
58
  exports.withAspect = withAspect;
59
+ exports.withTestOptions = withTestOptions;
26
60
 
27
61
  //# sourceMappingURL=index.cjs.map
package/lib/index.cjs.map CHANGED
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"index.cjs","names":["TestContext","gwtRunner","TestRunner","vitestBeforeEach","vitestAfterEach"],"sources":["../src/withAspect.ts","../src/withTestOptions.ts","../src/createVitestTestFunction.ts","../src/index.ts"],"sourcesContent":["import type {\n beforeEach as vitestBeforeEach,\n afterEach as vitestAfterEach,\n} from \"vitest\";\nimport { TestContext } from \"gwt-runner\";\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?: AspectFunction<T>) => void;\n\nconst withAspectBuilder: WithAspectBuilder =\n (beforeEach, afterEach) =>\n <T>(before: AspectFunction<T>, after?: AspectFunction<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 }, after?.timeout);\n };\n\nexport default withAspectBuilder;\n","import type {\n TestOptions,\n SuiteCollector,\n RunnerTestSuite,\n TestRunner,\n} from \"vitest\";\n\nconst suiteOptions = new WeakMap<object, TestOptions>();\n\nexport type WithTestOptions = (\n configure: (curr: TestOptions) => any,\n) => void;\n\nexport type GetCurrentSuite = typeof TestRunner.getCurrentSuite;\n\nexport type WithTestOptionsBuilder = (\n getSuite: GetCurrentSuite,\n) => WithTestOptions;\n\nconst getSuiteTask = (\n collector: SuiteCollector,\n): RunnerTestSuite | undefined => collector.suite;\n\nconst resolveFromSuite = (\n suite: RunnerTestSuite | undefined,\n): TestOptions | undefined => {\n let current: RunnerTestSuite | undefined = suite;\n\n while (current) {\n const options = suiteOptions.get(current);\n if (options) {\n return options;\n }\n current = current.suite;\n }\n\n return undefined;\n};\n\nexport const resolveTestOptions = (\n collector: SuiteCollector,\n): TestOptions | undefined => {\n const options = resolveFromSuite(getSuiteTask(collector));\n\n if (options == null || Object.keys(options).length === 0) {\n return undefined;\n }\n\n return options;\n};\n\nconst withTestOptionsBuilder: WithTestOptionsBuilder =\n (getSuite) =>\n (configure): void => {\n const collector = getSuite();\n const suiteTask = getSuiteTask(collector);\n const parentOptions = suiteTask?.suite\n ? resolveFromSuite(suiteTask.suite)\n : undefined;\n const testOptions: TestOptions = { ...parentOptions };\n\n configure(testOptions);\n\n if (suiteTask) {\n suiteOptions.set(suiteTask, testOptions);\n }\n };\n\nexport default withTestOptionsBuilder;\n","import type { test as vitestTest, SuiteCollector, TestOptions } from \"vitest\";\nimport type { TestFunction } from \"gwt-runner\";\nimport type { GetCurrentSuite } from \"./withTestOptions\";\nimport { resolveTestOptions } from \"./withTestOptions\";\n\nexport type CreateVitestTestFunction = (\n test: typeof vitestTest,\n getSuite: GetCurrentSuite,\n) => TestFunction;\n\nconst createVitestTestFunction: CreateVitestTestFunction =\n (test, getSuite) =>\n (name, callback) => {\n const options: TestOptions | undefined = resolveTestOptions(\n getSuite() as SuiteCollector,\n );\n\n if (options) {\n return test(name, options, callback);\n }\n\n return test(name, callback);\n };\n\nexport default createVitestTestFunction;\n","import {\n test as vitest,\n beforeEach as vitestBeforeEach,\n afterEach as vitestAfterEach,\n TestRunner,\n} from \"vitest\";\nimport { gwtRunner, TestContext } from \"gwt-runner\";\nimport withAspectBuilder, {\n type AspectFunction,\n type WithAspectBuilder,\n} from \"./withAspect\";\nimport withTestOptionsBuilder, {\n type WithTestOptions,\n type WithTestOptionsBuilder,\n} from \"./withTestOptions\";\nimport createVitestTestFunction from \"./createVitestTestFunction\";\n\nconst test: ReturnType<typeof gwtRunner> = gwtRunner(\n createVitestTestFunction(vitest, TestRunner.getCurrentSuite),\n);\n\nexport default test;\nexport { TestContext, test };\nexport type { AspectFunction, WithTestOptions };\n\nexport const withAspect: ReturnType<WithAspectBuilder> = withAspectBuilder(\n vitestBeforeEach,\n vitestAfterEach,\n);\n\nexport const withTestOptions: ReturnType<WithTestOptionsBuilder> =\n withTestOptionsBuilder(TestRunner.getCurrentSuite);\n"],"mappings":";;;;;;;AAgBA,MAAM,qBACH,YAAY,eACT,QAA2B,UAAoC;CACjE,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,GAAG,OAAO,OAAO;AACnB;;;ACzBF,MAAM,+BAAe,IAAI,QAA6B;AAYtD,MAAM,gBACJ,cACgC,UAAU;AAE5C,MAAM,oBACJ,UAC4B;CAC5B,IAAI,UAAuC;CAE3C,OAAO,SAAS;EACd,MAAM,UAAU,aAAa,IAAI,OAAO;EACxC,IAAI,SACF,OAAO;EAET,UAAU,QAAQ;CACpB;AAGF;AAEA,MAAa,sBACX,cAC4B;CAC5B,MAAM,UAAU,iBAAiB,aAAa,SAAS,CAAC;CAExD,IAAI,WAAW,QAAQ,OAAO,KAAK,OAAO,CAAC,CAAC,WAAW,GACrD;CAGF,OAAO;AACT;AAEA,MAAM,0BACH,cACA,cAAoB;CACnB,MAAM,YAAY,SAAS;CAC3B,MAAM,YAAY,aAAa,SAAS;CAIxC,MAAM,cAA2B,EAAE,GAHb,WAAW,QAC7B,iBAAiB,UAAU,KAAK,IAChC,KAAA,EACgD;CAEpD,UAAU,WAAW;CAErB,IAAI,WACF,aAAa,IAAI,WAAW,WAAW;AAE3C;;;ACxDF,MAAM,4BACH,MAAM,cACN,MAAM,aAAa;CAClB,MAAM,UAAmC,mBACvC,SAAS,CACX;CAEA,IAAI,SACF,OAAO,KAAK,MAAM,SAAS,QAAQ;CAGrC,OAAO,KAAK,MAAM,QAAQ;AAC5B;;;ACLF,MAAM,QAAA,GAAqCC,WAAAA,UAAAA,CACzC,yBAAyB,OAAA,MAAQC,OAAAA,WAAW,eAAe,CAC7D;AAMA,MAAa,aAA4C,kBACvDC,OAAAA,YACAC,OAAAA,SACF;AAEA,MAAa,kBACX,uBAAuBF,OAAAA,WAAW,eAAe"}
package/lib/index.d.cts CHANGED
@@ -1,16 +1,21 @@
1
1
  import { TestContext, gwtRunner } from "gwt-runner";
2
- import { afterEach, beforeEach } from "vitest";
2
+ import { TestOptions, TestRunner, afterEach, beforeEach } from "vitest";
3
3
  //#region src/withAspect.d.ts
4
- type AfterCallback<T> = (this: T) => unknown;
5
4
  type AspectFunction<T = unknown> = {
6
5
  (this: T): unknown;
7
6
  timeout?: number;
8
7
  };
9
- type WithAspectBuilder = (beforeEach: typeof beforeEach, afterEach: typeof afterEach) => <T>(before: AspectFunction<T>, after?: AfterCallback<T>) => void;
8
+ type WithAspectBuilder = (beforeEach: typeof beforeEach, afterEach: typeof afterEach) => <T>(before: AspectFunction<T>, after?: AspectFunction<T>) => void;
9
+ //#endregion
10
+ //#region src/withTestOptions.d.ts
11
+ type WithTestOptions = (configure: (curr: TestOptions) => any) => void;
12
+ type GetCurrentSuite = typeof TestRunner.getCurrentSuite;
13
+ type WithTestOptionsBuilder = (getSuite: GetCurrentSuite) => WithTestOptions;
10
14
  //#endregion
11
15
  //#region src/index.d.ts
12
16
  declare const test: ReturnType<typeof gwtRunner>;
13
17
  declare const withAspect: ReturnType<WithAspectBuilder>;
18
+ declare const withTestOptions: ReturnType<WithTestOptionsBuilder>;
14
19
  //#endregion
15
- export { type AspectFunction, TestContext, test as default, withAspect };
20
+ export { type AspectFunction, TestContext, type WithTestOptions, test as default, test, withAspect, withTestOptions };
16
21
  //# sourceMappingURL=index.d.cts.map
package/lib/index.d.mts CHANGED
@@ -1,16 +1,21 @@
1
- import { afterEach, beforeEach } from "vitest";
1
+ import { TestOptions, TestRunner, afterEach, beforeEach } from "vitest";
2
2
  import { TestContext, gwtRunner } from "gwt-runner";
3
3
  //#region src/withAspect.d.ts
4
- type AfterCallback<T> = (this: T) => unknown;
5
4
  type AspectFunction<T = unknown> = {
6
5
  (this: T): unknown;
7
6
  timeout?: number;
8
7
  };
9
- type WithAspectBuilder = (beforeEach: typeof beforeEach, afterEach: typeof afterEach) => <T>(before: AspectFunction<T>, after?: AfterCallback<T>) => void;
8
+ type WithAspectBuilder = (beforeEach: typeof beforeEach, afterEach: typeof afterEach) => <T>(before: AspectFunction<T>, after?: AspectFunction<T>) => void;
9
+ //#endregion
10
+ //#region src/withTestOptions.d.ts
11
+ type WithTestOptions = (configure: (curr: TestOptions) => any) => void;
12
+ type GetCurrentSuite = typeof TestRunner.getCurrentSuite;
13
+ type WithTestOptionsBuilder = (getSuite: GetCurrentSuite) => WithTestOptions;
10
14
  //#endregion
11
15
  //#region src/index.d.ts
12
16
  declare const test: ReturnType<typeof gwtRunner>;
13
17
  declare const withAspect: ReturnType<WithAspectBuilder>;
18
+ declare const withTestOptions: ReturnType<WithTestOptionsBuilder>;
14
19
  //#endregion
15
- export { type AspectFunction, TestContext, test as default, withAspect };
20
+ export { type AspectFunction, TestContext, type WithTestOptions, test as default, test, withAspect, withTestOptions };
16
21
  //# sourceMappingURL=index.d.mts.map
package/lib/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { afterEach, beforeEach, test as test$1 } from "vitest";
1
+ import { TestRunner, afterEach, beforeEach, test as test$1 } from "vitest";
2
2
  import { TestContext, TestContext as TestContext$1, gwtRunner } from "gwt-runner";
3
3
  //#region src/withAspect.ts
4
4
  const withAspectBuilder = (beforeEach, afterEach) => (before, after) => {
@@ -9,13 +9,45 @@ const withAspectBuilder = (beforeEach, afterEach) => (before, after) => {
9
9
  afterEach(async () => {
10
10
  if (after) await after.bind(TestContext$1.context)();
11
11
  TestContext$1.releaseContext();
12
- });
12
+ }, after?.timeout);
13
+ };
14
+ //#endregion
15
+ //#region src/withTestOptions.ts
16
+ const suiteOptions = /* @__PURE__ */ new WeakMap();
17
+ const getSuiteTask = (collector) => collector.suite;
18
+ const resolveFromSuite = (suite) => {
19
+ let current = suite;
20
+ while (current) {
21
+ const options = suiteOptions.get(current);
22
+ if (options) return options;
23
+ current = current.suite;
24
+ }
25
+ };
26
+ const resolveTestOptions = (collector) => {
27
+ const options = resolveFromSuite(getSuiteTask(collector));
28
+ if (options == null || Object.keys(options).length === 0) return;
29
+ return options;
30
+ };
31
+ const withTestOptionsBuilder = (getSuite) => (configure) => {
32
+ const collector = getSuite();
33
+ const suiteTask = getSuiteTask(collector);
34
+ const testOptions = { ...suiteTask?.suite ? resolveFromSuite(suiteTask.suite) : void 0 };
35
+ configure(testOptions);
36
+ if (suiteTask) suiteOptions.set(suiteTask, testOptions);
37
+ };
38
+ //#endregion
39
+ //#region src/createVitestTestFunction.ts
40
+ const createVitestTestFunction = (test, getSuite) => (name, callback) => {
41
+ const options = resolveTestOptions(getSuite());
42
+ if (options) return test(name, options, callback);
43
+ return test(name, callback);
13
44
  };
14
45
  //#endregion
15
46
  //#region src/index.ts
16
- const test = gwtRunner(test$1);
47
+ const test = gwtRunner(createVitestTestFunction(test$1, TestRunner.getCurrentSuite));
17
48
  const withAspect = withAspectBuilder(beforeEach, afterEach);
49
+ const withTestOptions = withTestOptionsBuilder(TestRunner.getCurrentSuite);
18
50
  //#endregion
19
- export { TestContext, test as default, withAspect };
51
+ export { TestContext, test as default, test, withAspect, withTestOptions };
20
52
 
21
53
  //# sourceMappingURL=index.mjs.map
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 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"}
1
+ {"version":3,"file":"index.mjs","names":["TestContext","vitest","vitestBeforeEach","vitestAfterEach"],"sources":["../src/withAspect.ts","../src/withTestOptions.ts","../src/createVitestTestFunction.ts","../src/index.ts"],"sourcesContent":["import type {\n beforeEach as vitestBeforeEach,\n afterEach as vitestAfterEach,\n} from \"vitest\";\nimport { TestContext } from \"gwt-runner\";\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?: AspectFunction<T>) => void;\n\nconst withAspectBuilder: WithAspectBuilder =\n (beforeEach, afterEach) =>\n <T>(before: AspectFunction<T>, after?: AspectFunction<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 }, after?.timeout);\n };\n\nexport default withAspectBuilder;\n","import type {\n TestOptions,\n SuiteCollector,\n RunnerTestSuite,\n TestRunner,\n} from \"vitest\";\n\nconst suiteOptions = new WeakMap<object, TestOptions>();\n\nexport type WithTestOptions = (\n configure: (curr: TestOptions) => any,\n) => void;\n\nexport type GetCurrentSuite = typeof TestRunner.getCurrentSuite;\n\nexport type WithTestOptionsBuilder = (\n getSuite: GetCurrentSuite,\n) => WithTestOptions;\n\nconst getSuiteTask = (\n collector: SuiteCollector,\n): RunnerTestSuite | undefined => collector.suite;\n\nconst resolveFromSuite = (\n suite: RunnerTestSuite | undefined,\n): TestOptions | undefined => {\n let current: RunnerTestSuite | undefined = suite;\n\n while (current) {\n const options = suiteOptions.get(current);\n if (options) {\n return options;\n }\n current = current.suite;\n }\n\n return undefined;\n};\n\nexport const resolveTestOptions = (\n collector: SuiteCollector,\n): TestOptions | undefined => {\n const options = resolveFromSuite(getSuiteTask(collector));\n\n if (options == null || Object.keys(options).length === 0) {\n return undefined;\n }\n\n return options;\n};\n\nconst withTestOptionsBuilder: WithTestOptionsBuilder =\n (getSuite) =>\n (configure): void => {\n const collector = getSuite();\n const suiteTask = getSuiteTask(collector);\n const parentOptions = suiteTask?.suite\n ? resolveFromSuite(suiteTask.suite)\n : undefined;\n const testOptions: TestOptions = { ...parentOptions };\n\n configure(testOptions);\n\n if (suiteTask) {\n suiteOptions.set(suiteTask, testOptions);\n }\n };\n\nexport default withTestOptionsBuilder;\n","import type { test as vitestTest, SuiteCollector, TestOptions } from \"vitest\";\nimport type { TestFunction } from \"gwt-runner\";\nimport type { GetCurrentSuite } from \"./withTestOptions\";\nimport { resolveTestOptions } from \"./withTestOptions\";\n\nexport type CreateVitestTestFunction = (\n test: typeof vitestTest,\n getSuite: GetCurrentSuite,\n) => TestFunction;\n\nconst createVitestTestFunction: CreateVitestTestFunction =\n (test, getSuite) =>\n (name, callback) => {\n const options: TestOptions | undefined = resolveTestOptions(\n getSuite() as SuiteCollector,\n );\n\n if (options) {\n return test(name, options, callback);\n }\n\n return test(name, callback);\n };\n\nexport default createVitestTestFunction;\n","import {\n test as vitest,\n beforeEach as vitestBeforeEach,\n afterEach as vitestAfterEach,\n TestRunner,\n} from \"vitest\";\nimport { gwtRunner, TestContext } from \"gwt-runner\";\nimport withAspectBuilder, {\n type AspectFunction,\n type WithAspectBuilder,\n} from \"./withAspect\";\nimport withTestOptionsBuilder, {\n type WithTestOptions,\n type WithTestOptionsBuilder,\n} from \"./withTestOptions\";\nimport createVitestTestFunction from \"./createVitestTestFunction\";\n\nconst test: ReturnType<typeof gwtRunner> = gwtRunner(\n createVitestTestFunction(vitest, TestRunner.getCurrentSuite),\n);\n\nexport default test;\nexport { TestContext, test };\nexport type { AspectFunction, WithTestOptions };\n\nexport const withAspect: ReturnType<WithAspectBuilder> = withAspectBuilder(\n vitestBeforeEach,\n vitestAfterEach,\n);\n\nexport const withTestOptions: ReturnType<WithTestOptionsBuilder> =\n withTestOptionsBuilder(TestRunner.getCurrentSuite);\n"],"mappings":";;;AAgBA,MAAM,qBACH,YAAY,eACT,QAA2B,UAAoC;CACjE,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,GAAG,OAAO,OAAO;AACnB;;;ACzBF,MAAM,+BAAe,IAAI,QAA6B;AAYtD,MAAM,gBACJ,cACgC,UAAU;AAE5C,MAAM,oBACJ,UAC4B;CAC5B,IAAI,UAAuC;CAE3C,OAAO,SAAS;EACd,MAAM,UAAU,aAAa,IAAI,OAAO;EACxC,IAAI,SACF,OAAO;EAET,UAAU,QAAQ;CACpB;AAGF;AAEA,MAAa,sBACX,cAC4B;CAC5B,MAAM,UAAU,iBAAiB,aAAa,SAAS,CAAC;CAExD,IAAI,WAAW,QAAQ,OAAO,KAAK,OAAO,CAAC,CAAC,WAAW,GACrD;CAGF,OAAO;AACT;AAEA,MAAM,0BACH,cACA,cAAoB;CACnB,MAAM,YAAY,SAAS;CAC3B,MAAM,YAAY,aAAa,SAAS;CAIxC,MAAM,cAA2B,EAAE,GAHb,WAAW,QAC7B,iBAAiB,UAAU,KAAK,IAChC,KAAA,EACgD;CAEpD,UAAU,WAAW;CAErB,IAAI,WACF,aAAa,IAAI,WAAW,WAAW;AAE3C;;;ACxDF,MAAM,4BACH,MAAM,cACN,MAAM,aAAa;CAClB,MAAM,UAAmC,mBACvC,SAAS,CACX;CAEA,IAAI,SACF,OAAO,KAAK,MAAM,SAAS,QAAQ;CAGrC,OAAO,KAAK,MAAM,QAAQ;AAC5B;;;ACLF,MAAM,OAAqC,UACzC,yBAAyBC,QAAQ,WAAW,eAAe,CAC7D;AAMA,MAAa,aAA4C,kBACvDC,YACAC,SACF;AAEA,MAAa,kBACX,uBAAuB,WAAW,eAAe"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest-gwt",
3
- "version": "4.1.3",
3
+ "version": "4.1.4-build.16",
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",
@@ -0,0 +1,25 @@
1
+ import type { test as vitestTest, SuiteCollector, TestOptions } from "vitest";
2
+ import type { TestFunction } from "gwt-runner";
3
+ import type { GetCurrentSuite } from "./withTestOptions";
4
+ import { resolveTestOptions } from "./withTestOptions";
5
+
6
+ export type CreateVitestTestFunction = (
7
+ test: typeof vitestTest,
8
+ getSuite: GetCurrentSuite,
9
+ ) => TestFunction;
10
+
11
+ const createVitestTestFunction: CreateVitestTestFunction =
12
+ (test, getSuite) =>
13
+ (name, callback) => {
14
+ const options: TestOptions | undefined = resolveTestOptions(
15
+ getSuite() as SuiteCollector,
16
+ );
17
+
18
+ if (options) {
19
+ return test(name, options, callback);
20
+ }
21
+
22
+ return test(name, callback);
23
+ };
24
+
25
+ export default createVitestTestFunction;
package/src/index.ts CHANGED
@@ -2,20 +2,31 @@ import {
2
2
  test as vitest,
3
3
  beforeEach as vitestBeforeEach,
4
4
  afterEach as vitestAfterEach,
5
+ TestRunner,
5
6
  } from "vitest";
6
7
  import { gwtRunner, TestContext } from "gwt-runner";
7
8
  import withAspectBuilder, {
8
9
  type AspectFunction,
9
10
  type WithAspectBuilder,
10
11
  } from "./withAspect";
12
+ import withTestOptionsBuilder, {
13
+ type WithTestOptions,
14
+ type WithTestOptionsBuilder,
15
+ } from "./withTestOptions";
16
+ import createVitestTestFunction from "./createVitestTestFunction";
11
17
 
12
- const test: ReturnType<typeof gwtRunner> = gwtRunner(vitest);
18
+ const test: ReturnType<typeof gwtRunner> = gwtRunner(
19
+ createVitestTestFunction(vitest, TestRunner.getCurrentSuite),
20
+ );
13
21
 
14
22
  export default test;
15
- export { TestContext };
16
- export type { AspectFunction };
23
+ export { TestContext, test };
24
+ export type { AspectFunction, WithTestOptions };
17
25
 
18
26
  export const withAspect: ReturnType<WithAspectBuilder> = withAspectBuilder(
19
27
  vitestBeforeEach,
20
28
  vitestAfterEach,
21
29
  );
30
+
31
+ export const withTestOptions: ReturnType<WithTestOptionsBuilder> =
32
+ withTestOptionsBuilder(TestRunner.getCurrentSuite);
package/src/withAspect.ts CHANGED
@@ -1,8 +1,9 @@
1
- import type { beforeEach as vitestBeforeEach, afterEach as vitestAfterEach } from "vitest";
1
+ import type {
2
+ beforeEach as vitestBeforeEach,
3
+ afterEach as vitestAfterEach,
4
+ } from "vitest";
2
5
  import { TestContext } from "gwt-runner";
3
6
 
4
- type AfterCallback<T> = (this: T) => unknown;
5
-
6
7
  export type AspectFunction<T = unknown> = {
7
8
  (this: T): unknown;
8
9
  timeout?: number;
@@ -11,11 +12,11 @@ export type AspectFunction<T = unknown> = {
11
12
  export type WithAspectBuilder = (
12
13
  beforeEach: typeof vitestBeforeEach,
13
14
  afterEach: typeof vitestAfterEach,
14
- ) => <T>(before: AspectFunction<T>, after?: AfterCallback<T>) => void;
15
+ ) => <T>(before: AspectFunction<T>, after?: AspectFunction<T>) => void;
15
16
 
16
17
  const withAspectBuilder: WithAspectBuilder =
17
18
  (beforeEach, afterEach) =>
18
- <T>(before: AspectFunction<T>, after?: AfterCallback<T>): void => {
19
+ <T>(before: AspectFunction<T>, after?: AspectFunction<T>): void => {
19
20
  beforeEach(async () => {
20
21
  TestContext.createContext();
21
22
 
@@ -28,7 +29,7 @@ const withAspectBuilder: WithAspectBuilder =
28
29
  }
29
30
 
30
31
  TestContext.releaseContext();
31
- });
32
+ }, after?.timeout);
32
33
  };
33
34
 
34
35
  export default withAspectBuilder;
@@ -0,0 +1,69 @@
1
+ import type {
2
+ TestOptions,
3
+ SuiteCollector,
4
+ RunnerTestSuite,
5
+ TestRunner,
6
+ } from "vitest";
7
+
8
+ const suiteOptions = new WeakMap<object, TestOptions>();
9
+
10
+ export type WithTestOptions = (
11
+ configure: (curr: TestOptions) => any,
12
+ ) => void;
13
+
14
+ export type GetCurrentSuite = typeof TestRunner.getCurrentSuite;
15
+
16
+ export type WithTestOptionsBuilder = (
17
+ getSuite: GetCurrentSuite,
18
+ ) => WithTestOptions;
19
+
20
+ const getSuiteTask = (
21
+ collector: SuiteCollector,
22
+ ): RunnerTestSuite | undefined => collector.suite;
23
+
24
+ const resolveFromSuite = (
25
+ suite: RunnerTestSuite | undefined,
26
+ ): TestOptions | undefined => {
27
+ let current: RunnerTestSuite | undefined = suite;
28
+
29
+ while (current) {
30
+ const options = suiteOptions.get(current);
31
+ if (options) {
32
+ return options;
33
+ }
34
+ current = current.suite;
35
+ }
36
+
37
+ return undefined;
38
+ };
39
+
40
+ export const resolveTestOptions = (
41
+ collector: SuiteCollector,
42
+ ): TestOptions | undefined => {
43
+ const options = resolveFromSuite(getSuiteTask(collector));
44
+
45
+ if (options == null || Object.keys(options).length === 0) {
46
+ return undefined;
47
+ }
48
+
49
+ return options;
50
+ };
51
+
52
+ const withTestOptionsBuilder: WithTestOptionsBuilder =
53
+ (getSuite) =>
54
+ (configure): void => {
55
+ const collector = getSuite();
56
+ const suiteTask = getSuiteTask(collector);
57
+ const parentOptions = suiteTask?.suite
58
+ ? resolveFromSuite(suiteTask.suite)
59
+ : undefined;
60
+ const testOptions: TestOptions = { ...parentOptions };
61
+
62
+ configure(testOptions);
63
+
64
+ if (suiteTask) {
65
+ suiteOptions.set(suiteTask, testOptions);
66
+ }
67
+ };
68
+
69
+ export default withTestOptionsBuilder;