@nzila/sdk 0.1.6 → 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 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.
@@ -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<TestModule>, options: NzilaClientOptions, runStartedAt: Date): NzilaTestCase[];
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,EAAY,UAAU,EAAa,MAAM,aAAa,CAAC;AACnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAmB,MAAM,YAAY,CAAC;AAmBrF,wEAAwE;AACxE,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,aAAa,CAAC,UAAU,CAAC,EAClC,OAAO,EAAE,kBAAkB,EAC3B,YAAY,EAAE,IAAI,GACjB,aAAa,EAAE,CAuCjB"}
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
- while (parent.type === "suite") {
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
- for (const test of mod.children.allTests()) {
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,5 +1,4 @@
1
1
  import type { File } from "@vitest/runner";
2
- import type { Reporter, SerializedError, TestModule, TestRunEndReason } 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}.
@@ -11,16 +10,22 @@ export default class NzilaVitestReporter {
11
10
  private sent;
12
11
  private readonly runId;
13
12
  constructor(options: NzilaClientOptions);
14
- onTestRunEnd(testModules: ReadonlyArray<TestModule>, _unhandledErrors?: ReadonlyArray<SerializedError>, _reason?: TestRunEndReason): void;
13
+ onTestRunEnd(testModules: ReadonlyArray<unknown>, _unhandledErrors?: ReadonlyArray<unknown>, _reason?: string): void;
15
14
  /** @deprecated Vitest 2 — still invoked in some setups */
16
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
+ ];
21
26
  /**
22
- * Returns a reporter instance typed for your project's Vitest config (`reporters` array).
23
- * Prefer this over `new NzilaVitestReporter()` when TypeScript reports a Reporter mismatch.
27
+ * Returns `['@nzila/sdk/vitest', options]` for `defineConfig({ test: { reporters } })`.
28
+ * Do **not** use `new NzilaVitestReporter()` in config worker pools cannot serialize instances.
24
29
  */
25
- export declare function nzilaVitestReporter(options: NzilaClientOptions): Reporter;
30
+ export declare function nzilaVitestReporter(options: NzilaClientOptions): NzilaVitestReporterEntry;
26
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;AACjD,OAAO,KAAK,EACV,QAAQ,EACR,eAAe,EACf,UAAU,EACV,gBAAgB,EACjB,MAAM,aAAa,CAAC;AAKrB,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,UAAU,CAAC,EACtC,gBAAgB,CAAC,EAAE,aAAa,CAAC,eAAe,CAAC,EACjD,OAAO,CAAC,EAAE,gBAAgB;IAM5B,0DAA0D;IAC1D,UAAU,CAAC,KAAK,EAAE,I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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";
97
99
  /**
98
- * Returns a reporter instance typed for your project's Vitest config (`reporters` array).
99
- * Prefer this over `new NzilaVitestReporter()` when TypeScript reports a Reporter mismatch.
100
+ * Returns `['@nzila/sdk/vitest', options]` for `defineConfig({ test: { reporters } })`.
101
+ * Do **not** use `new NzilaVitestReporter()` in config worker pools cannot serialize instances.
100
102
  */
101
103
  export function nzilaVitestReporter(options) {
102
- return new NzilaVitestReporter(options);
104
+ return [NZILA_VITEST_REPORTER, options];
103
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 NzilaVitestReporter from "@nzila/sdk/vitest";
6
+ import { nzilaVitestReporter } from "@nzila/sdk/vitest";
7
7
 
8
8
  export default defineConfig({
9
9
  test: {
10
10
  reporters: [
11
11
  "default",
12
- new NzilaVitestReporter({
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nzila/sdk",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Send test runs to Nzila, trace live feature errors, and onboard via npx @nzila/sdk.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/vitest.d.ts CHANGED
@@ -1,15 +1,19 @@
1
1
  import type { NzilaClientOptions } from "./dist/types.js";
2
2
 
3
- /** @see {@link nzilaVitestReporter} for use in `defineConfig({ test: { reporters } })`. */
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). */
4
13
  declare class NzilaVitestReporter {
5
14
  constructor(options: NzilaClientOptions);
6
15
  }
7
16
 
8
17
  export default NzilaVitestReporter;
9
18
 
10
- /** Vitest-config-safe factory (avoids duplicate `Reporter` types across packages). */
11
- export function nzilaVitestReporter(
12
- options: NzilaClientOptions,
13
- ): import("vitest/node").Reporter;
14
-
15
19
  export * from "./dist/vitest-reporter.js";