@nzila/sdk 0.1.5 → 0.1.7
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 +12 -2
- package/dist/collect-vitest-tests.d.ts +26 -2
- package/dist/collect-vitest-tests.d.ts.map +1 -1
- package/dist/collect-vitest-tests.js +9 -2
- package/dist/vitest-reporter.d.ts +14 -4
- package/dist/vitest-reporter.d.ts.map +1 -1
- package/dist/vitest-reporter.js +11 -2
- package/examples/vitest.config.example.ts +2 -2
- package/package.json +1 -1
- package/vitest.d.ts +18 -1
package/README.md
CHANGED
|
@@ -25,6 +25,16 @@ Subpaths such as `@nzila/sdk/vitest` need **`moduleResolution`** set to **`bundl
|
|
|
25
25
|
|
|
26
26
|
`@nzila/sdk@0.1.4+` also ships root `.d.ts` shims and `typesVersions` for broader editor support.
|
|
27
27
|
|
|
28
|
+
### Vitest: tests hang or never start?
|
|
29
|
+
|
|
30
|
+
Use the **tuple** from `nzilaVitestReporter()` — do **not** put `new NzilaVitestReporter()` in `vitest.config.ts`. Worker pools cannot serialize class instances.
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
reporters: ["default", nzilaVitestReporter({ webhookUrl, apiKey, appName })],
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Equivalent: `reporters: ["default", ["@nzila/sdk/vitest", { … }]]`.
|
|
37
|
+
|
|
28
38
|
### Reporters not sending?
|
|
29
39
|
|
|
30
40
|
1. Set **`NZILA_WEBHOOK_URL`**, **`NZILA_API_KEY`**, and **`NZILA_APP_NAME`** (must match the project app name in the dashboard), or pass them in the reporter constructor.
|
|
@@ -63,13 +73,13 @@ After you sign in on [nzila-kappa.vercel.app](https://nzila-kappa.vercel.app), t
|
|
|
63
73
|
**Tests (CI):**
|
|
64
74
|
|
|
65
75
|
```ts
|
|
66
|
-
import
|
|
76
|
+
import { nzilaVitestReporter } from "@nzila/sdk/vitest";
|
|
67
77
|
|
|
68
78
|
export default defineConfig({
|
|
69
79
|
test: {
|
|
70
80
|
reporters: [
|
|
71
81
|
"default",
|
|
72
|
-
|
|
82
|
+
nzilaVitestReporter({
|
|
73
83
|
webhookUrl: process.env.NZILA_WEBHOOK_URL!,
|
|
74
84
|
apiKey: process.env.NZILA_API_KEY!,
|
|
75
85
|
appName: "my-app",
|
|
@@ -1,5 +1,29 @@
|
|
|
1
|
-
import type { TestModule } from "vitest/node";
|
|
2
1
|
import type { NzilaClientOptions, NzilaTestCase } from "./types.js";
|
|
2
|
+
/** Duck-typed Vitest 3 test tree (no `vitest/node` import — safe for worker load). */
|
|
3
|
+
type VitestTestNode = {
|
|
4
|
+
name: string;
|
|
5
|
+
parent: {
|
|
6
|
+
type: string;
|
|
7
|
+
name: string;
|
|
8
|
+
parent: VitestTestNode["parent"];
|
|
9
|
+
};
|
|
10
|
+
result(): {
|
|
11
|
+
state: string;
|
|
12
|
+
errors?: {
|
|
13
|
+
message?: string;
|
|
14
|
+
stack?: string;
|
|
15
|
+
}[];
|
|
16
|
+
};
|
|
17
|
+
diagnostic(): {
|
|
18
|
+
duration?: number;
|
|
19
|
+
} | undefined;
|
|
20
|
+
};
|
|
21
|
+
type VitestTestModule = {
|
|
22
|
+
children?: {
|
|
23
|
+
allTests(): Iterable<VitestTestNode>;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
3
26
|
/** Collect finished tests from Vitest 3+ `TestModule` reporters API. */
|
|
4
|
-
export declare function collectTestsFromVitestModules(modules: ReadonlyArray<
|
|
27
|
+
export declare function collectTestsFromVitestModules(modules: ReadonlyArray<VitestTestModule>, options: NzilaClientOptions, runStartedAt: Date): NzilaTestCase[];
|
|
28
|
+
export {};
|
|
5
29
|
//# sourceMappingURL=collect-vitest-tests.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collect-vitest-tests.d.ts","sourceRoot":"","sources":["../src/collect-vitest-tests.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"collect-vitest-tests.d.ts","sourceRoot":"","sources":["../src/collect-vitest-tests.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAmB,MAAM,YAAY,CAAC;AAErF,sFAAsF;AACtF,KAAK,cAAc,GAAG;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAA;KAAE,CAAC;IACzE,MAAM,IAAI;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE;YAAE,OAAO,CAAC,EAAE,MAAM,CAAC;YAAC,KAAK,CAAC,EAAE,MAAM,CAAA;SAAE,EAAE,CAAA;KAAE,CAAC;IAC7E,UAAU,IAAI;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;CACjD,CAAC;AAEF,KAAK,gBAAgB,GAAG;IACtB,QAAQ,CAAC,EAAE;QACT,QAAQ,IAAI,QAAQ,CAAC,cAAc,CAAC,CAAC;KACtC,CAAC;CACH,CAAC;AAsBF,wEAAwE;AACxE,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,aAAa,CAAC,gBAAgB,CAAC,EACxC,OAAO,EAAE,kBAAkB,EAC3B,YAAY,EAAE,IAAI,GACjB,aAAa,EAAE,CAyCjB"}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
function describePathFor(test) {
|
|
2
2
|
const path = [];
|
|
3
3
|
let parent = test.parent;
|
|
4
|
-
|
|
4
|
+
const seen = new Set();
|
|
5
|
+
while (parent?.type === "suite") {
|
|
6
|
+
if (seen.has(parent))
|
|
7
|
+
break;
|
|
8
|
+
seen.add(parent);
|
|
5
9
|
path.unshift(parent.name);
|
|
6
10
|
parent = parent.parent;
|
|
7
11
|
}
|
|
@@ -22,7 +26,10 @@ export function collectTestsFromVitestModules(modules, options, runStartedAt) {
|
|
|
22
26
|
const tests = [];
|
|
23
27
|
const now = new Date().toISOString();
|
|
24
28
|
for (const mod of modules) {
|
|
25
|
-
|
|
29
|
+
const allTests = mod.children?.allTests?.();
|
|
30
|
+
if (!allTests)
|
|
31
|
+
continue;
|
|
32
|
+
for (const test of allTests) {
|
|
26
33
|
const result = test.result();
|
|
27
34
|
if (result.state === "pending")
|
|
28
35
|
continue;
|
|
@@ -1,21 +1,31 @@
|
|
|
1
1
|
import type { File } from "@vitest/runner";
|
|
2
|
-
import type { Reporter, TestModule } from "vitest/node";
|
|
3
2
|
import type { NzilaClientOptions } from "./types.js";
|
|
4
3
|
/**
|
|
5
4
|
* Vitest reporter that POSTs one webhook per finished run via {@link sendNzilaRun}.
|
|
6
5
|
* Supports Vitest 3+ (`onTestRunEnd`) and legacy `onFinished` file tasks.
|
|
7
6
|
*/
|
|
8
|
-
export default class NzilaVitestReporter
|
|
7
|
+
export default class NzilaVitestReporter {
|
|
9
8
|
private readonly options;
|
|
10
9
|
private startedAt;
|
|
11
10
|
private sent;
|
|
12
11
|
private readonly runId;
|
|
13
12
|
constructor(options: NzilaClientOptions);
|
|
14
|
-
onTestRunEnd(testModules: ReadonlyArray<
|
|
13
|
+
onTestRunEnd(testModules: ReadonlyArray<unknown>, _unhandledErrors?: ReadonlyArray<unknown>, _reason?: string): void;
|
|
15
14
|
/** @deprecated Vitest 2 — still invoked in some setups */
|
|
16
|
-
onFinished(files
|
|
15
|
+
onFinished(files: File[], _errors: unknown[], _coverage?: unknown): void;
|
|
17
16
|
private sendPayload;
|
|
18
17
|
private walkTasks;
|
|
19
18
|
private mapStatus;
|
|
20
19
|
}
|
|
20
|
+
/** Vitest `reporters` entry — load by package name (works with `pool: forks` / `threads`). */
|
|
21
|
+
export declare const NZILA_VITEST_REPORTER: "@nzila/sdk/vitest";
|
|
22
|
+
export type NzilaVitestReporterEntry = [
|
|
23
|
+
typeof NZILA_VITEST_REPORTER,
|
|
24
|
+
NzilaClientOptions
|
|
25
|
+
];
|
|
26
|
+
/**
|
|
27
|
+
* Returns `['@nzila/sdk/vitest', options]` for `defineConfig({ test: { reporters } })`.
|
|
28
|
+
* Do **not** use `new NzilaVitestReporter()` in config — worker pools cannot serialize instances.
|
|
29
|
+
*/
|
|
30
|
+
export declare function nzilaVitestReporter(options: NzilaClientOptions): NzilaVitestReporterEntry;
|
|
21
31
|
//# sourceMappingURL=vitest-reporter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vitest-reporter.d.ts","sourceRoot":"","sources":["../src/vitest-reporter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAQ,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"vitest-reporter.d.ts","sourceRoot":"","sources":["../src/vitest-reporter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAQ,MAAM,gBAAgB,CAAC;AAKjD,OAAO,KAAK,EAAE,kBAAkB,EAAmD,MAAM,YAAY,CAAC;AAEtG;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,mBAAmB;IACtC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA0C;IAClE,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;gBAEnB,OAAO,EAAE,kBAAkB;IAKvC,YAAY,CACV,WAAW,EAAE,aAAa,CAAC,OAAO,CAAC,EACnC,gBAAgB,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,EACzC,OAAO,CAAC,EAAE,MAAM;IAUlB,0DAA0D;IAC1D,UAAU,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,SAAS,CAAC,EAAE,OAAO;YAQnD,WAAW;IA2BzB,OAAO,CAAC,SAAS;IAyCjB,OAAO,CAAC,SAAS;CAMlB;AAED,8FAA8F;AAC9F,eAAO,MAAM,qBAAqB,EAAG,mBAA4B,CAAC;AAElE,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,qBAAqB;IAC5B,kBAAkB;CACnB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,kBAAkB,GAC1B,wBAAwB,CAE1B"}
|
package/dist/vitest-reporter.js
CHANGED
|
@@ -13,12 +13,12 @@ export default class NzilaVitestReporter {
|
|
|
13
13
|
this.options = resolveClientOptions(options);
|
|
14
14
|
this.runId = this.options.runId ?? randomUUID();
|
|
15
15
|
}
|
|
16
|
-
onTestRunEnd(testModules) {
|
|
16
|
+
onTestRunEnd(testModules, _unhandledErrors, _reason) {
|
|
17
17
|
const tests = collectTestsFromVitestModules(testModules, this.options, this.startedAt);
|
|
18
18
|
void this.sendPayload(tests);
|
|
19
19
|
}
|
|
20
20
|
/** @deprecated Vitest 2 — still invoked in some setups */
|
|
21
|
-
onFinished(files, _errors) {
|
|
21
|
+
onFinished(files, _errors, _coverage) {
|
|
22
22
|
const tests = [];
|
|
23
23
|
for (const file of files ?? []) {
|
|
24
24
|
this.walkTasks(file.tasks, file.name.split("/").slice(0, -1), tests);
|
|
@@ -94,3 +94,12 @@ export default class NzilaVitestReporter {
|
|
|
94
94
|
return "pending";
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
+
/** Vitest `reporters` entry — load by package name (works with `pool: forks` / `threads`). */
|
|
98
|
+
export const NZILA_VITEST_REPORTER = "@nzila/sdk/vitest";
|
|
99
|
+
/**
|
|
100
|
+
* Returns `['@nzila/sdk/vitest', options]` for `defineConfig({ test: { reporters } })`.
|
|
101
|
+
* Do **not** use `new NzilaVitestReporter()` in config — worker pools cannot serialize instances.
|
|
102
|
+
*/
|
|
103
|
+
export function nzilaVitestReporter(options) {
|
|
104
|
+
return [NZILA_VITEST_REPORTER, options];
|
|
105
|
+
}
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
* Nzila repo uses examples/vitest.config.ts (and backend/frontend-specific configs).
|
|
4
4
|
*/
|
|
5
5
|
import { defineConfig } from "vitest/config";
|
|
6
|
-
import
|
|
6
|
+
import { nzilaVitestReporter } from "@nzila/sdk/vitest";
|
|
7
7
|
|
|
8
8
|
export default defineConfig({
|
|
9
9
|
test: {
|
|
10
10
|
reporters: [
|
|
11
11
|
"default",
|
|
12
|
-
|
|
12
|
+
nzilaVitestReporter({
|
|
13
13
|
webhookUrl: process.env.NZILA_WEBHOOK_URL ?? "http://localhost:3000/api/webhooks/tests",
|
|
14
14
|
apiKey: process.env.NZILA_API_KEY!,
|
|
15
15
|
appName: process.env.NZILA_APP_NAME ?? "my-app",
|
package/package.json
CHANGED
package/vitest.d.ts
CHANGED
|
@@ -1,2 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
import type { NzilaClientOptions } from "./dist/types.js";
|
|
2
|
+
|
|
3
|
+
export const NZILA_VITEST_REPORTER: "@nzila/sdk/vitest";
|
|
4
|
+
|
|
5
|
+
export type NzilaVitestReporterEntry = [typeof NZILA_VITEST_REPORTER, NzilaClientOptions];
|
|
6
|
+
|
|
7
|
+
/** Use in `reporters: ["default", nzilaVitestReporter({ ... })]` — not `new NzilaVitestReporter()`. */
|
|
8
|
+
export function nzilaVitestReporter(
|
|
9
|
+
options: NzilaClientOptions,
|
|
10
|
+
): NzilaVitestReporterEntry;
|
|
11
|
+
|
|
12
|
+
/** @see nzilaVitestReporter — default export is the reporter class (loaded by Vitest from the tuple). */
|
|
13
|
+
declare class NzilaVitestReporter {
|
|
14
|
+
constructor(options: NzilaClientOptions);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default NzilaVitestReporter;
|
|
18
|
+
|
|
2
19
|
export * from "./dist/vitest-reporter.js";
|