@systemfsoftware/stryker-js-instrumenter 0.2.0 → 2.0.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,98 @@
1
1
  # @systemfsoftware/stryker-js-instrumenter
2
2
 
3
+ ## 2.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - Three packages are renamed. `plugin-api` is now `@systemfsoftware/stryker-js`, the
8
+ language every plugin is written against. `mutation-run` is now
9
+ `@systemfsoftware/stryker-js-platform-node`, the Node host that runs a mutation
10
+ test. `mutation-report` is now `@systemfsoftware/stryker-js-html-reporter`.
11
+ Install the new names and change your imports.
12
+
13
+ Options types moved. `StrykerOptions`, `PartialStrykerOptions` and `LogLevel` are
14
+ imported from the `Schema` export; `Mutant`, `MutantStatus`, `Position` and
15
+ `Location` from the `Mutant` export. Point a config's `extends` at the language
16
+ package's `Schema` export.
17
+
18
+ `MutantStatus` accepts one spelling per outcome: `Killed`, `Survived`,
19
+ `NoCoverage`, `Timeout`, `CompileError`, `RuntimeError`, `Ignored` and `Pending`.
20
+ The lowercase and abbreviated forms — `killed`, `timedOut`, `noCoverage` and the
21
+ rest — are gone. A comparison against a removed spelling never matched the value
22
+ the reporter actually produced, so check any status comparison you wrote.
23
+
24
+ Statuses, plugin kinds, exit classes and AST formats are string literal unions
25
+ rather than enums, so read them as their string values. Member access such as
26
+ `ExitClass.VerdictFail` no longer resolves.
27
+
28
+ A plugin no longer receives a logger, and the logger port is gone. Plugins log
29
+ through Effect, and the host decides where that output goes.
30
+
31
+ The bundled base preset is gone. A config inherits from the language package's
32
+ `Schema` export and states the thresholds, reporters and plugins it wants; you no
33
+ longer silently inherit a package manager, a plugin list or a break threshold.
34
+
35
+ ### Patch Changes
36
+
37
+ - Selecting `workflow-make-boundary` keeps mutants inside `Workflow.make` decision bodies.
38
+
39
+ Ignore plugins are asked about each mutant, not about the file root with a subtree latch. An inverted selector that answers "ignore" for everything outside a make body therefore no longer ignores the make body itself. Inner mutants of declaration-style ignore plugins (`effect-schema-declarations`, Angular signal option objects) are still ignored.
40
+
41
+ - Instrumenting a file that calls a method named after an `Object.prototype`
42
+ member - `toString`, `valueOf`, `constructor` and the rest - no longer fails
43
+ with `Property name expected type of string but got function`. The method
44
+ mutator's replacement table answered such a lookup with the inherited function
45
+ rather than reporting no replacement, and a single `.toString()` call was enough
46
+ to stop the run. Those methods are now left alone, as they always should have
47
+ been.
48
+
49
+ - Updated dependencies:
50
+ - @systemfsoftware/effect-cell-types@5.0.0
51
+
52
+ ## 1.0.0
53
+
54
+ ### Major Changes
55
+
56
+ - Parse, transform and mutant-placement failures now carry a message naming the
57
+ file and what went wrong, and their `cause` survives being written to JSON — so
58
+ a failure that crossed a process boundary no longer arrives blank.
59
+
60
+ Every error tag is now qualified, which is what makes two identically named
61
+ errors from different packages distinguishable.
62
+
63
+ `MutantPlacementFailed` is removed; it was a second name for `PlacementFailed`
64
+ and had no constructor anywhere. Match `PlacementFailed`.
65
+
66
+ - svelte is now an optional peer dependency. Install it to mutate .svelte components; without it, every other file type is unaffected. A copy of the Svelte compiler used to be bundled in, which pinned whichever version was present when the package was built and made the compiler version check read the wrong answer.
67
+
68
+ ### Patch Changes
69
+
70
+ - The instrumenter no longer depends on `weapon-regex`, a Scala library compiled to JavaScript that is no longer maintained. It is replaced by `@eslint-community/regexpp`, which has no dependencies of its own. Regular expression mutants are unchanged, so no action is required.
71
+
72
+ - The shared helpers package is gone. Nothing installs it any more, and the
73
+ handful of helpers worth sharing now live in the plugin contract next to the
74
+ types they serve:
75
+
76
+ - `strykerReportBugUrl`, `normalizeFileName`, `propertyPath`, `errorToString`
77
+ and `isErrnoException` from `@systemfsoftware/stryker-js-plugin-api/core`
78
+ - `noopLogger` from `@systemfsoftware/stryker-js-plugin-api/logging`
79
+ - `testFilesProvided` from `@systemfsoftware/stryker-js-plugin-api/test-runner`
80
+
81
+ If you imported any of those, change the specifier. Everything else it exported
82
+ had no consumer and is removed: use `Predicate.isNotNullish` from Effect in place
83
+ of `notEmpty`, and `RegExp.escape` in place of `escapeRegExp`.
84
+
85
+ - These packages no longer install dependencies they never imported, so installing them pulls less into your tree.
86
+
87
+ `tslib` is gone from all six. The mutation runner additionally stops installing `lodash.groupby`, `semver` and `source-map`, and the command line interface stops installing `@effect/platform-node-shared`. Nothing exported changes.
88
+
89
+ - When a mutant cannot be placed, the reported error now links to this project's issue tracker rather than the upstream StrykerJS one.
90
+
91
+ - Published packages no longer carry build artifacts left over from earlier builds. One package was shipping about a megabyte of bundled test-runner internals this way.
92
+
93
+ - Updated dependencies:
94
+ - @systemfsoftware/stryker-js-plugin-api@3.0.0
95
+
3
96
  ## 0.2.0
4
97
 
5
98
  ### Minor Changes
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @systemfsoftware/stryker-js-instrumenter
2
2
 
3
- A source-code fork of the upstream StrykerJS instrumenter package, pinned at 9.6.1.
3
+ Parses source files, applies their configured mutators, and produces the mutant set for a mutation run.
4
4
 
5
5
  ## Install
6
6
 
@@ -16,10 +16,6 @@ pnpm add @systemfsoftware/stryker-js-instrumenter
16
16
 
17
17
  The instrumenter is used internally by the Stryker mutation testing framework to instrument source files with mutant coverage and switching logic.
18
18
 
19
- ## API
20
-
21
- The public surface is generated from the source and versioned with the package: [`etc/stryker-js-instrumenter.api.md`](./etc/stryker-js-instrumenter.api.md).
22
-
23
19
  ## License
24
20
 
25
21
  Apache-2.0. Part of [systemfsoftware](https://github.com/systemfsoftware/systemfsoftware/tree/main/packages/testing/mutation/stryker-js/instrumenter#readme).
package/dist/index.d.mts CHANGED
@@ -1,246 +1,85 @@
1
- import { BaseContext, Injector, PluginKind } from "@systemfsoftware/stryker-js-plugin-api/plugin";
2
- import { FileDescription, Mutant, MutateDescription, Position } from "@systemfsoftware/stryker-js-plugin-api/core";
3
- import { types } from "@babel/core";
4
- import { I } from "@systemfsoftware/stryker-js-util";
5
- import { Ignorer } from "@systemfsoftware/stryker-js-plugin-api/ignore";
6
- import { Logger } from "@systemfsoftware/stryker-js-plugin-api/logging";
7
- //#region src/instrumenter-tokens.d.ts
8
- declare const instrumenterTokens: Readonly<{
9
- readonly createParser: 'instrumenterCreateParser';
10
- readonly print: 'instrumenterPrint';
11
- readonly transform: 'instrumenterTransform';
12
- }>;
13
- //#endregion
14
- //#region src/syntax/index.d.ts
15
- declare enum AstFormat {
16
- Html = "html",
17
- JS = "js",
18
- TS = "ts",
19
- Tsx = "tsx",
20
- Svelte = "svelte"
21
- }
22
- interface AstByFormat {
23
- [AstFormat.Html]: HtmlAst;
24
- [AstFormat.JS]: JSAst;
25
- [AstFormat.TS]: TSAst;
26
- [AstFormat.Tsx]: TsxAst;
27
- [AstFormat.Svelte]: SvelteAst;
28
- }
29
- type Ast = HtmlAst | JSAst | SvelteAst | TSAst | TsxAst;
30
- type ScriptAst = JSAst | TSAst | TsxAst;
31
- interface BaseAst {
32
- originFileName: string;
33
- rawContent: string;
34
- root: Ast['root'];
35
- offset?: Position;
36
- }
37
- /**
38
- * Represents an Html AST.
39
- */
40
- interface HtmlAst extends BaseAst {
41
- format: AstFormat.Html;
42
- root: HtmlRootNode;
43
- }
44
- /**
45
- * Represents a TS AST
46
- */
47
- interface JSAst extends BaseAst {
48
- format: AstFormat.JS;
49
- root: types.File;
50
- }
51
- /**
52
- * Represents a TS AST
53
- */
54
- interface TSAst extends BaseAst {
55
- format: AstFormat.TS;
56
- root: types.File;
57
- }
58
- /**
59
- * Represents a TS AST
60
- */
61
- interface TsxAst extends BaseAst {
62
- format: AstFormat.Tsx;
63
- root: types.File;
64
- }
65
- /**
66
- * Represents a Svelte AST
67
- */
68
- interface SvelteAst extends BaseAst {
69
- format: AstFormat.Svelte;
70
- root: SvelteRootNode;
71
- }
72
- /**
73
- * Represents the root node of an HTML AST
74
- * We've taken a shortcut here, instead of representing the entire AST, we're only representing the script tags.
75
- * We might need to expand this in the future if we would ever want to support mutating the actual HTML (rather than only the JS/TS)
76
- */
77
- interface HtmlRootNode {
78
- scripts: ScriptAst[];
79
- }
80
- interface SvelteRootNode {
81
- moduleScript?: TemplateScript;
82
- additionalScripts: TemplateScript[];
83
- }
84
- /**
85
- * Represents a svelte script or binding expression
86
- * We've taken a shortcut here, instead of representing the entire AST, we're only representing the script tags and expression bindings.
87
- */
88
- interface TemplateScript {
89
- ast: ScriptAst;
90
- range: Range;
91
- isExpression: boolean;
92
- }
93
- interface Range {
94
- start: number;
95
- end: number;
96
- }
97
- //#endregion
98
- //#region src/parsers/parser-options.d.ts
1
+ import babel, { File as File$1, types } from "@babel/core";
2
+ import { Wire, Workflow } from "@systemfsoftware/effect-cell-types";
3
+ import { FileDescription, Mutant } from "@systemfsoftware/stryker-js/Mutant";
4
+ import * as Effect from "effect/Effect";
5
+ import "effect/Result";
6
+ import * as S from "effect/Schema";
7
+ import { IgnorerService } from "@systemfsoftware/stryker-js/Ignorer";
8
+ import "effect/Option";
9
+ //#region src/Instrument.workflow.d.ts
10
+ declare const InstrumentError_base: S.Class<InstrumentError, S.TaggedStruct<"InstrumentError", {
11
+ readonly message: S.String;
12
+ readonly cause: S.Defect;
13
+ }>, import("effect/Cause").YieldableError>;
14
+ declare class InstrumentError extends InstrumentError_base {
15
+ get message(): string;
16
+ }
17
+ declare const InstrumenterOptionsSchema: S.Struct<{
18
+ plugins: S.NullOr<S.$Array<S.Unknown & Wire.Mark> & Wire.Mark> & Wire.Mark;
19
+ excludedMutations: S.$Array<S.String & Wire.Mark> & Wire.Mark;
20
+ ignorers: S.$Array<S.Unknown & Wire.Mark> & Wire.Mark;
21
+ noHeader: S.optional<S.Boolean & Wire.Mark> & Wire.Mark;
22
+ }> & Wire.Mark;
23
+ type InstrumenterOptions = typeof InstrumenterOptionsSchema.Type;
24
+ declare const InstrumentResult_base: S.Class<InstrumentResult$1, S.TaggedStruct<"InstrumentResult", {
25
+ readonly files: S.$Array<S.Struct<{
26
+ readonly name: S.String;
27
+ readonly content: S.String;
28
+ readonly mutate: S.Union<readonly [S.Boolean, S.$Array<S.Struct<{
29
+ readonly start: S.Struct<{
30
+ readonly line: S.Finite;
31
+ readonly column: S.Finite;
32
+ }>;
33
+ readonly end: S.Struct<{
34
+ readonly line: S.Finite;
35
+ readonly column: S.Finite;
36
+ }>;
37
+ }>>]>;
38
+ }>>;
39
+ readonly mutants: S.$Array<typeof Mutant>;
40
+ }>, {}>;
41
+ declare class InstrumentResult$1 extends InstrumentResult_base {}
42
+ //#endregion
43
+ //#region src/Parser.d.ts
99
44
  interface ParserOptions {
100
- plugins: unknown[] | null;
45
+ plugins: readonly unknown[] | null;
101
46
  }
102
47
  //#endregion
103
- //#region src/parsers/create-parser.d.ts
104
- declare function createParser(parserOptions: ParserOptions): {
105
- <T extends AstFormat>(code: string, fileName: string, formatOverride: T): Promise<AstByFormat[T]>;
106
- (code: string, fileName: string, formatOverride?: AstFormat): Promise<Ast>;
107
- };
108
- //#endregion
109
- //#region src/printers/index.d.ts
110
- declare function print(file: Ast): string;
111
- //#endregion
112
- //#region src/mutant.d.ts
113
- interface Mutable {
114
- mutatorName: string;
115
- ignoreReason?: string | undefined;
116
- replacement: types.Node;
117
- }
118
- declare class Mutant$1 implements Mutable {
119
- readonly id: string;
120
- readonly fileName: string;
121
- readonly original: types.Node;
122
- readonly offset: Position;
123
- readonly replacementCode: string;
124
- readonly replacement: types.Node;
125
- readonly mutatorName: string;
126
- readonly ignoreReason: string | undefined;
127
- constructor(id: string, fileName: string, original: types.Node, specs: Mutable, offset?: Position);
128
- toApiMutant(): Mutant;
129
- /**
130
- * Applies the mutant in (a copy of) the AST, without changing provided AST.
131
- * Can the tree itself (in which case the replacement is returned),
132
- * or can be nested in the given tree.
133
- *
134
- * Returns a plain node rather than the argument's own type: whether the
135
- * replacement fits a given position is the placer's claim, and the placer
136
- * checks it with a Babel predicate. A generic return would have to assert it
137
- * here, where nothing can check it.
138
- * @param originalTree The original node, which will be treated as readonly
139
- */
140
- applied(originalTree: types.Node): types.Node;
141
- }
142
- //#endregion
143
- //#region src/transformers/mutant-collector.d.ts
144
- declare class MutantCollector {
145
- private readonly _mutants;
146
- get mutants(): readonly Mutant$1[];
147
- /**
148
- * Adds mutants to the internal mutant list.
149
- * @param fileName file name that houses the mutant
150
- * @param original The node to mutate
151
- * @param mutables the named node mutation to be added
152
- * @param contextPath the context where these mutants are found and should be placed as close by as possible
153
- * @param offset offset of mutant nodes
154
- * @returns The mutant (for testability)
155
- */
156
- collect(fileName: string, original: types.Node, mutable: Mutable, offset?: Position): Mutant$1;
157
- hasPlacedMutants(fileName: string): boolean;
158
- }
159
- //#endregion
160
- //#region src/mutators/mutator-options.d.ts
161
- interface MutatorOptions {
162
- excludedMutations: string[];
163
- noHeader?: boolean;
164
- }
165
- //#endregion
166
- //#region src/transformers/transformer-options.d.ts
167
- interface TransformerOptions extends MutatorOptions {
168
- ignorers: Ignorer[];
169
- }
170
- //#endregion
171
- //#region src/transformers/transformer.d.ts
172
- /**
173
- * Transform the AST by generating mutants and placing them in the AST.
174
- * Supports all AST formats supported by Stryker.
175
- * @param ast The Abstract Syntax Tree
176
- * @param mutantCollector the mutant collector that will be used to register and administer mutants
177
- * @param transformerContext the options used during transforming
178
- */
179
- declare function transform(ast: Ast, mutantCollector: I<MutantCollector>, transformerContext: Omit<TransformerContext, 'transform'>): void;
180
- type AstTransformer<T extends AstFormat> = (ast: AstByFormat[T], mutantCollector: I<MutantCollector>, context: TransformerContext) => void;
181
- interface TransformerContext {
182
- transform: AstTransformer<AstFormat>;
183
- options: TransformerOptions;
184
- mutateDescription: MutateDescription;
185
- logger: Logger;
186
- }
187
- //#endregion
188
- //#region src/create-instrumenter.d.ts
189
- interface InstrumenterContext extends BaseContext {
190
- [instrumenterTokens.createParser]: typeof createParser;
191
- [instrumenterTokens.print]: typeof print;
192
- [instrumenterTokens.transform]: typeof transform;
193
- }
194
- declare function createInstrumenter(injector: Injector<BaseContext>): Instrumenter;
195
- declare namespace createInstrumenter {
196
- var inject: ["$injector"];
197
- }
198
- //#endregion
199
- //#region src/file.d.ts
48
+ //#region src/Instrument.d.ts
200
49
  interface File extends FileDescription {
201
50
  name: string;
202
51
  content: string;
203
52
  }
204
- //#endregion
205
- //#region src/disable-type-checks.d.ts
206
- /**
207
- * Disables TypeScript type checking for a single file by inserting `// @ts-nocheck` commands.
208
- * It also does this for *.js files, as they can be type checked by typescript as well.
209
- * Other file types are silently ignored
210
- *
211
- * @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#-ts-nocheck-in-typescript-files
212
- */
213
- declare function disableTypeChecks(file: File, options: ParserOptions): Promise<File>;
214
- //#endregion
215
- //#region src/frameworks/index.d.ts
216
- declare const strykerPlugins: import("@systemfsoftware/stryker-js-plugin-api/plugin").ClassPlugin<PluginKind.Ignore, []>[];
217
- declare const frameworkPluginsFileUrl: string;
218
- //#endregion
219
- //#region src/instrument-result.d.ts
220
53
  interface InstrumentResult {
221
54
  files: readonly File[];
222
55
  mutants: readonly Mutant[];
223
56
  }
57
+ declare function disableTypeChecks(file: File, options: ParserOptions): Promise<File>;
58
+ declare const instrument: (files: readonly File[], options: InstrumenterOptions) => Effect.Effect<InstrumentResult$1, InstrumentError>;
224
59
  //#endregion
225
- //#region src/instrumenter-options.d.ts
226
- interface InstrumenterOptions extends ParserOptions, TransformerOptions {}
227
- //#endregion
228
- //#region src/instrumenter.d.ts
60
+ //#region src/Transformer.d.ts
229
61
  /**
230
- * The instrumenter is responsible for
231
- * * Generating mutants based on source files
232
- * * Instrumenting the source code with the mutants placed in `mutant switches`.
233
- * * Adding mutant coverage expressions in the source code.
234
- * @see https://github.com/stryker-mutator/stryker-js/issues/1514
62
+ * `@babel/core` exports its `File` class at runtime, but `@types/babel__core`
63
+ * omits it. The declaration lives in this module rather than an ambient
64
+ * `.d.ts` so it travels with the sources: a consumer that compiles this
65
+ * package from source (the workspace's `@systemfsoftware/source` condition,
66
+ * and api-extractor with it) reaches the augmentation through the import
67
+ * graph, which an unreferenced ambient file never joins.
235
68
  */
236
- declare class Instrumenter {
237
- private readonly logger;
238
- private readonly _createParser;
239
- private readonly _print;
240
- private readonly _transform;
241
- static inject: ["logger", "instrumenterCreateParser", "instrumenterPrint", "instrumenterTransform"];
242
- constructor(logger: Logger, _createParser?: typeof createParser, _print?: typeof print, _transform?: typeof transform);
243
- instrument(files: readonly File[], options: InstrumenterOptions): Promise<InstrumentResult>;
244
- }
69
+ declare module '@babel/core' {
70
+ class File {
71
+ constructor(options: {
72
+ filename?: string;
73
+ }, input: {
74
+ code: string;
75
+ ast: types.File;
76
+ inputMap?: unknown;
77
+ });
78
+ ast: types.File;
79
+ }
80
+ }
81
+ declare const angularIgnorer: IgnorerService;
82
+ declare const strykerPlugins: readonly unknown[];
83
+ declare const frameworkPluginsFileUrl: string;
245
84
  //#endregion
246
- export { File, InstrumentResult, Instrumenter, InstrumenterContext, InstrumenterOptions, type ParserOptions, createInstrumenter, disableTypeChecks, frameworkPluginsFileUrl, strykerPlugins };
85
+ export { type File, type InstrumentResult, type InstrumenterOptions, type ParserOptions, angularIgnorer, disableTypeChecks, frameworkPluginsFileUrl, instrument, strykerPlugins };