@cosyte/vitest-config 0.1.3 → 0.1.4

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/package.json CHANGED
@@ -1,14 +1,16 @@
1
1
  {
2
2
  "name": "@cosyte/vitest-config",
3
- "version": "0.1.3",
4
- "description": "Shared Vitest config (v8 coverage, per-directory >=90 gates) for @cosyte/* packages.",
3
+ "version": "0.1.4",
4
+ "description": "Shared Vitest config (v8 coverage, per-directory >=90 gates) and StrykerJS mutation testing config for @cosyte/* packages.",
5
5
  "keywords": [
6
6
  "vitest",
7
7
  "coverage",
8
8
  "test",
9
9
  "doctest",
10
10
  "documentation",
11
- "cosyte"
11
+ "cosyte",
12
+ "stryker",
13
+ "mutation-testing"
12
14
  ],
13
15
  "homepage": "https://github.com/cosyte/config/tree/main/packages/vitest-config#readme",
14
16
  "repository": {
@@ -21,6 +23,9 @@
21
23
  "type": "module",
22
24
  "main": "index.js",
23
25
  "types": "index.d.ts",
26
+ "bin": {
27
+ "cosyte-mutate": "bin/cosyte-mutate.js"
28
+ },
24
29
  "exports": {
25
30
  ".": {
26
31
  "types": "./index.d.ts",
@@ -29,6 +34,14 @@
29
34
  "./snippets": {
30
35
  "types": "./snippets.d.ts",
31
36
  "default": "./snippets.js"
37
+ },
38
+ "./stryker": {
39
+ "types": "./stryker.d.ts",
40
+ "default": "./stryker.js"
41
+ },
42
+ "./mutate": {
43
+ "types": "./mutate.d.ts",
44
+ "default": "./mutate.js"
32
45
  }
33
46
  },
34
47
  "files": [
@@ -36,6 +49,11 @@
36
49
  "index.d.ts",
37
50
  "snippets.js",
38
51
  "snippets.d.ts",
52
+ "stryker.js",
53
+ "stryker.d.ts",
54
+ "mutate.js",
55
+ "mutate.d.ts",
56
+ "bin",
39
57
  "README.md",
40
58
  "CHANGELOG.md"
41
59
  ],
@@ -43,8 +61,38 @@
43
61
  "access": "public"
44
62
  },
45
63
  "peerDependencies": {
64
+ "@stryker-mutator/core": "^10.0.0",
65
+ "@stryker-mutator/vitest-runner": "^10.0.0",
46
66
  "@vitest/coverage-v8": "^4.0.0 || ^5.0.0",
47
67
  "vite": "^6.0.0 || ^7.0.0 || ^8.0.0",
48
- "vitest": "^4.0.0 || ^5.0.0"
68
+ "vitest": "^4.0.0 || ^5.0.0",
69
+ "typescript": ">=5.0.0",
70
+ "@cosyte/script-utils": "^0.1.9"
71
+ },
72
+ "peerDependenciesMeta": {
73
+ "@cosyte/script-utils": {
74
+ "optional": true
75
+ },
76
+ "@stryker-mutator/core": {
77
+ "optional": true
78
+ },
79
+ "@stryker-mutator/vitest-runner": {
80
+ "optional": true
81
+ },
82
+ "typescript": {
83
+ "optional": true
84
+ }
85
+ },
86
+ "devDependencies": {
87
+ "@stryker-mutator/core": "10.1.1",
88
+ "@stryker-mutator/vitest-runner": "10.1.1",
89
+ "@vitest/coverage-v8": "5.1.0",
90
+ "vite": "8.3.6",
91
+ "vitest": "5.1.0",
92
+ "typescript": "5.9.3",
93
+ "@cosyte/script-utils": "^0.1.9"
94
+ },
95
+ "scripts": {
96
+ "test": "vitest run --coverage"
49
97
  }
50
98
  }
package/snippets.d.ts CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  /** One extracted runnable snippet, in document order. */
11
11
  export interface RunnableSnippet {
12
- /** The fence language (`ts` / `typescript` / `tsx`). */
12
+ /** The fence language (`ts` / `typescript` / `tsx`; a sample may also be `js` / `javascript` / `mjs`). */
13
13
  lang: string;
14
14
  /** Fence info-string tokens after the language (e.g. `["runnable", "throws"]`). */
15
15
  meta: string[];
@@ -19,6 +19,79 @@ export interface RunnableSnippet {
19
19
  line: number;
20
20
  /** Whether the block is tagged `throws` (expected to throw rather than run clean). */
21
21
  throws: boolean;
22
+ /**
23
+ * The extension of the module {@link runSnippet} writes the snippet to. Absent, it is `.ts`, which
24
+ * is what every snippet {@link extractRunnableSnippets} returns runs as.
25
+ */
26
+ extension?: string;
27
+ }
28
+
29
+ /** One extracted code sample, in document order: a TypeScript or JavaScript block, tagged or not. */
30
+ export interface Sample extends RunnableSnippet {
31
+ /**
32
+ * The reason the block is not run: the words after its `no-run` tag (empty when the tag has no
33
+ * reason, which the suite reports as an error), or `null` for a block that runs.
34
+ */
35
+ skip: string | null;
36
+ /**
37
+ * The reason the sample is run but not type-checked: the words after its `no-typecheck` tag
38
+ * (empty when the tag has no reason, which the suite reports as an error), or `null` otherwise.
39
+ * Of `no-run` and `no-typecheck`, the first in the fence counts, and what follows it is its reason.
40
+ */
41
+ noTypecheck: string | null;
42
+ /** The module it runs as: `.mjs` for a `js`, `javascript` or `mjs` sample, `.tsx` for `tsx`, else `.ts`. */
43
+ extension: ".ts" | ".tsx" | ".mjs";
44
+ }
45
+
46
+ /** One type error in a sample. */
47
+ export interface SampleTypeError {
48
+ /** The markdown line it is on. */
49
+ line: number;
50
+ /** TypeScript's error code, as in `TS2322`. */
51
+ code: number;
52
+ /** TypeScript's message, on one line. */
53
+ message: string;
54
+ }
55
+
56
+ /** Options for {@link typecheckSamples}. */
57
+ export interface TypecheckSamplesOptions {
58
+ /** The `tsconfig.json` to compile under. Default: the one in the working directory, if any. */
59
+ tsconfig?: string;
60
+ /**
61
+ * Where each sample is written to be compiled; it must sit inside the project, so the package's
62
+ * name resolves. Default `.cosyte-doc-snippets/typecheck` in the working directory.
63
+ */
64
+ dir?: string;
65
+ }
66
+
67
+ /** The fence languages that make a block a code sample: TypeScript and JavaScript. */
68
+ export declare const SAMPLE_LANGS: ReadonlySet<string>;
69
+
70
+ /** What a suite does with one sample. */
71
+ export interface SamplePlanStep {
72
+ /** The test name: the file, relative to the root, and the sample's first code line. */
73
+ label: string;
74
+ /** Run it, skip it with its reason, or report a `no-run` or `no-typecheck` that gives no reason. */
75
+ kind: "run" | "skip" | "invalid";
76
+ /**
77
+ * Why it is skipped or invalid; for a run, why it is not type-checked, or `null` when nothing is
78
+ * left out.
79
+ */
80
+ reason: string | null;
81
+ /** Whether the sample is type-checked before it runs: a TypeScript sample, in every-sample mode. */
82
+ typecheck: boolean;
83
+ /** The sample. */
84
+ snippet: Sample;
85
+ }
86
+
87
+ /** Options for {@link planSamples}. */
88
+ export interface PlanSamplesOptions {
89
+ /** Take every sample rather than only the `runnable` ones. Default `false`. */
90
+ every?: boolean;
91
+ /** What labels are relative to. Default: the working directory. */
92
+ root?: string;
93
+ /** Fence opt-in tag when `every` is off. Default `"runnable"`. */
94
+ runnableTag?: string;
22
95
  }
23
96
 
24
97
  /** Options for {@link extractRunnableSnippets}. */
@@ -35,6 +108,8 @@ export interface RunSnippetOptions {
35
108
  tmpDir?: string;
36
109
  /** Force the expected-to-throw expectation even for a raw-string snippet. */
37
110
  throws?: boolean;
111
+ /** The snippet's type errors, from {@link typecheckSamples}: when any, it fails before it runs. */
112
+ typeErrors?: SampleTypeError[];
38
113
  }
39
114
 
40
115
  /** Options for {@link docSnippetSuite}. */
@@ -55,8 +130,55 @@ export interface DocSnippetSuiteOptions {
55
130
  requireSnippet?: boolean;
56
131
  /** Where temp modules are written (must be inside the project root). */
57
132
  tmpDir?: string;
133
+ /**
134
+ * Run every TypeScript and JavaScript sample, not only the `runnable` ones; a `no-run <reason>`
135
+ * sample is listed as skipped with its reason, and a `no-run` with no reason fails. Each
136
+ * TypeScript sample is type-checked before it runs, unless it carries `no-typecheck <reason>`.
137
+ * Walking `docsDir`, the generated `api/` folder is left out. Default `false`.
138
+ */
139
+ every?: boolean;
140
+ /** In every-sample mode, walk the generated `api/` folder of `docsDir` too. Default `false`. */
141
+ includeGenerated?: boolean;
142
+ /** The `tsconfig.json` samples are type-checked under. Default: the one in the working directory. */
143
+ tsconfig?: string;
58
144
  }
59
145
 
146
+ /**
147
+ * Extract every code sample from a markdown string: each `ts`, `typescript`, `tsx`, `js`,
148
+ * `javascript` or `mjs` block, tagged or not, in document order.
149
+ *
150
+ * @param markdown - The markdown source.
151
+ * @returns One entry per sample.
152
+ */
153
+ export declare function extractSamples(markdown: string): Sample[];
154
+
155
+ /**
156
+ * Decide what a suite does with each sample in a set of markdown files.
157
+ *
158
+ * @param files - Markdown file paths.
159
+ * @param options - Options.
160
+ * @returns One step per sample, in file and document order.
161
+ */
162
+ export declare function planSamples(
163
+ files: string[],
164
+ options?: PlanSamplesOptions,
165
+ ): SamplePlanStep[];
166
+
167
+ /**
168
+ * Type-check TypeScript samples against the package's types, each as its own module, under the
169
+ * project's `tsconfig.json` with emit and the unused-name checks off. Needs `typescript`.
170
+ *
171
+ * @param samples - The samples: their code, the markdown line of their first code line, and the
172
+ * extension they compile as (`.ts` when absent).
173
+ * @param options - Options.
174
+ * @returns For each sample, in order, its errors; empty for one that compiles.
175
+ * @throws When the config cannot be read or the program as a whole has an error.
176
+ */
177
+ export declare function typecheckSamples(
178
+ samples: Array<Pick<RunnableSnippet, "code" | "line" | "extension">>,
179
+ options?: TypecheckSamplesOptions,
180
+ ): Promise<SampleTypeError[][]>;
181
+
60
182
  /**
61
183
  * Extract the opt-in runnable snippets from a markdown string, in document order.
62
184
  *