@sgohlke/stryker-log-ignorer 1.0.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/README.md +61 -1
- package/build/index.cjs +21 -11
- package/build/index.cjs.map +1 -1
- package/build/index.d.cts +60 -3
- package/build/index.d.ts +60 -3
- package/build/index.js +20 -10
- package/build/index.js.map +1 -1
- package/package.json +1 -1
- package/schema/log-ignorer-options.json +25 -0
- package/.prettierrc.json +0 -16
- package/stryker.config.json +0 -12
- package/tsup.config.ts +0 -13
- package/vitest.config.ts +0 -14
package/README.md
CHANGED
|
@@ -1,3 +1,63 @@
|
|
|
1
1
|
# stryker-log-ignorer
|
|
2
2
|
|
|
3
|
-
Log ignorer plugin for Stryker
|
|
3
|
+
Log ignorer plugin for [Stryker][1] JS/TS. Provides functionality to ignore logger calls in Stryker if you do not want to mutation test these logger calls.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm i --save-dev @sgohlke/stryker-log-ignorer
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
TypeScript declarations are provided within the project.
|
|
12
|
+
|
|
13
|
+
## Configuring
|
|
14
|
+
|
|
15
|
+
In order to use the plugin you have to add it as **ignorer** and add both the **@stryker-mutator** and **@sgohlke/stryker-log-ignorer** plugins to the Stryker configuration file.
|
|
16
|
+
|
|
17
|
+
In the optional **loginore** option you can define the object names (i.e. the name of the variable/constant, NOT the name of a Logger class or interface) to be ignored. If no **loginore** option is provided **console** calls will be ignored.
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
"ignorers": ["log-ignore"],
|
|
22
|
+
"plugins": ["@stryker-mutator/*", "@sgohlke/stryker-log-ignorer"],
|
|
23
|
+
"logignore": {
|
|
24
|
+
"objectNames": ["console", "logger"]
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Example
|
|
30
|
+
|
|
31
|
+
Using the **logignore** options shown above we run Stryker. As both **console** and **logger** are defined in the **objectNames** option both lines in the code below will be ignored in the results of the stryker run.
|
|
32
|
+
|
|
33
|
+
Example code:
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { MyFavoriteLogger } from 'some-logger-module'
|
|
37
|
+
export function doSomething(): void {
|
|
38
|
+
const logger = new MyFavoriteLogger('loggername')
|
|
39
|
+
console.log('We do something here!')
|
|
40
|
+
// Some imaginary code here!
|
|
41
|
+
logger.info('We finished doing something!')
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
In the results you can identify these lines as **ignored**, for example
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
logger.info('We finished doing something!')
|
|
49
|
+
logger.info('')
|
|
50
|
+
// StringLiteral Ignored
|
|
51
|
+
// We are not interested in testing console,logger statements.
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Contact
|
|
55
|
+
|
|
56
|
+
If you have questions or issues please visit our [Issue page](https://github.com/sgohlke/stryker-log-ignorer/issues)
|
|
57
|
+
and open a new issue if there are no fitting issues for your topic yet.
|
|
58
|
+
|
|
59
|
+
## License
|
|
60
|
+
|
|
61
|
+
stryker-log-ignorer is under [CC0 1.0-License](./LICENSE).
|
|
62
|
+
|
|
63
|
+
[1]: https://stryker-mutator.io/
|
package/build/index.cjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;// src/index.ts
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;// src/index.ts
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
var _plugin = require('@stryker-mutator/api/plugin');
|
|
8
|
+
var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
|
|
8
9
|
var LogIgnorer = (_class = class {
|
|
9
10
|
constructor(log, options) {
|
|
10
11
|
this.log = log;
|
|
@@ -13,13 +14,11 @@ var LogIgnorer = (_class = class {
|
|
|
13
14
|
static __initStatic() {this.inject = [_plugin.commonTokens.logger, _plugin.commonTokens.options]}
|
|
14
15
|
|
|
15
16
|
shouldIgnore(path) {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (path.isExpressionStatement() && path.node.expression.type === "CallExpression" && path.node.expression.callee.type === "MemberExpression" && path.node.expression.callee.object.type === "Identifier" && path.node.expression.callee.object.name === loggerClass) {
|
|
22
|
-
return `We are not interested in testing ${loggerClass} statements.`;
|
|
17
|
+
const loggerObjectNames = _nullishCoalesce(_optionalChain([this, 'access', _ => _.options, 'optionalAccess', _2 => _2.logignore, 'optionalAccess', _3 => _3.objectNames]), () => ( [
|
|
18
|
+
"console"
|
|
19
|
+
]));
|
|
20
|
+
if (path.isExpressionStatement() && path.node.expression.type === "CallExpression" && path.node.expression.callee.type === "MemberExpression" && path.node.expression.callee.object.type === "Identifier" && loggerObjectNames.includes(path.node.expression.callee.object.name)) {
|
|
21
|
+
return `We are not interested in testing ${loggerObjectNames} statements.`;
|
|
23
22
|
}
|
|
24
23
|
}
|
|
25
24
|
}, _class.__initStatic(), _class);
|
|
@@ -30,14 +29,25 @@ function logIgnorerFactory(injector) {
|
|
|
30
29
|
function createLogIgnorerFactory() {
|
|
31
30
|
return logIgnorerFactory;
|
|
32
31
|
}
|
|
33
|
-
var createLogIgnorer = createLogIgnorerFactory();
|
|
34
32
|
var strykerPlugins = [
|
|
35
|
-
_plugin.declareFactoryPlugin.call(void 0,
|
|
33
|
+
_plugin.declareFactoryPlugin.call(void 0,
|
|
34
|
+
_plugin.PluginKind.Ignore,
|
|
35
|
+
"log-ignore",
|
|
36
|
+
createLogIgnorerFactory()
|
|
37
|
+
)
|
|
36
38
|
];
|
|
39
|
+
var strykerValidationSchema = JSON.parse(
|
|
40
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
41
|
+
_fs2.default.readFileSync(
|
|
42
|
+
new URL("../schema/log-ignorer-options.json", import.meta.url),
|
|
43
|
+
"utf8"
|
|
44
|
+
)
|
|
45
|
+
);
|
|
37
46
|
|
|
38
47
|
|
|
39
48
|
|
|
40
49
|
|
|
41
50
|
|
|
42
|
-
|
|
51
|
+
|
|
52
|
+
exports.LogIgnorer = LogIgnorer; exports.createLogIgnorerFactory = createLogIgnorerFactory; exports.logIgnorerFactory = logIgnorerFactory; exports.strykerPlugins = strykerPlugins; exports.strykerValidationSchema = strykerValidationSchema;
|
|
43
53
|
//# sourceMappingURL=index.cjs.map
|
package/build/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";AAGA;AAAA,EACI;AAAA,EACA;AAAA,EAGA;AAAA,EACA;AAAA,OACG;
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";AAGA;AAAA,EACI;AAAA,EACA;AAAA,EAGA;AAAA,EACA;AAAA,OACG;AACP,OAAO,QAAQ;AAuCR,IAAM,aAAN,MAAoC;AAAA,EAIvC,YAEqB,KACjB,SACF;AAFmB;AAGjB,SAAK,UAAU;AAAA,EACnB;AAAA,EATA,OAAc,SAAS,CAAC,aAAa,QAAQ,aAAa,OAAO;AAAA,EAC9C;AAAA,EAUnB,aAAa,MAAoC;AAC7C,UAAM,oBAAoB,KAAK,SAAS,WAAW,eAAe;AAAA,MAC9D;AAAA,IACJ;AACA,QACI,KAAK,sBAAsB,KAC3B,KAAK,KAAK,WAAW,SAAS,oBAC9B,KAAK,KAAK,WAAW,OAAO,SAAS,sBACrC,KAAK,KAAK,WAAW,OAAO,OAAO,SAAS,gBAC5C,kBAAkB,SAAS,KAAK,KAAK,WAAW,OAAO,OAAO,IAAI,GACpE;AACE,aAAO,oCAAoC,iBAAiB;AAAA,IAChE;AAAA,EACJ;AACJ;AAEA,kBAAkB,SAAS,OAAO,aAAa,QAAQ;AAEhD,SAAS,kBACZ,UACU;AACV,SAAO,SAAS,YAAY,UAAU;AAC1C;AAEO,SAAS,0BAGd;AACE,SAAO;AACX;AAEO,IAAM,iBAAiB;AAAA,EAC1B;AAAA,IACI,WAAW;AAAA,IACX;AAAA,IACA,wBAAwB;AAAA,EAC5B;AACJ;AAEO,IAAM,0BACT,KAAK;AAAA;AAAA,EAED,GAAG;AAAA,IACC,IAAI,IAAI,sCAAsC,YAAY,GAAG;AAAA,IAC7D;AAAA,EACJ;AACJ","sourcesContent":["import { StrykerOptions } from '@stryker-mutator/api/core'\nimport { Ignorer } from '@stryker-mutator/api/ignore'\nimport { Logger } from '@stryker-mutator/api/logging'\nimport {\n commonTokens,\n declareFactoryPlugin,\n Injector,\n PluginContext,\n PluginKind,\n tokens,\n} from '@stryker-mutator/api/plugin'\nimport fs from 'node:fs'\n\n/**\n * We define the necessary functions and fields for NodePath to be able to provide type safety\n * in our code.\n */\nexport interface NodePath {\n isExpressionStatement(): boolean\n node: {\n expression: {\n type: string\n callee: {\n type: string\n object: {\n type: string\n name: string\n }\n }\n }\n }\n}\n\n/**\n * Configuration for @sgohlke/stryker-log-ignorer\n */\nexport interface IgnorerOptions {\n /**\n * Specify the object names of the logger objects to be ignored. Defaults to [\"console\"]\n */\n objectNames?: string[]\n}\n\nexport interface LogIgnorerOptions extends StrykerOptions {\n logignore: IgnorerOptions\n}\n\n/*\n * LogIgnorer provides functionality to ignore log calls for provides logger object names.\n */\nexport class LogIgnorer implements Ignorer {\n public static inject = [commonTokens.logger, commonTokens.options] as const\n protected readonly options: LogIgnorerOptions\n\n constructor(\n // eslint-disable-next-line @typescript-eslint/parameter-properties\n private readonly log?: Logger,\n options?: StrykerOptions,\n ) {\n this.options = options as LogIgnorerOptions\n }\n\n shouldIgnore(path: NodePath): string | undefined {\n const loggerObjectNames = this.options?.logignore?.objectNames ?? [\n 'console',\n ]\n if (\n path.isExpressionStatement() &&\n path.node.expression.type === 'CallExpression' &&\n path.node.expression.callee.type === 'MemberExpression' &&\n path.node.expression.callee.object.type === 'Identifier' &&\n loggerObjectNames.includes(path.node.expression.callee.object.name)\n ) {\n return `We are not interested in testing ${loggerObjectNames} statements.`\n }\n }\n}\n\nlogIgnorerFactory.inject = tokens(commonTokens.injector)\n\nexport function logIgnorerFactory(\n injector: Injector<PluginContext>,\n): LogIgnorer {\n return injector.injectClass(LogIgnorer)\n}\n\nexport function createLogIgnorerFactory(): {\n (injector: Injector<PluginContext>): LogIgnorer\n inject: ['$injector']\n} {\n return logIgnorerFactory\n}\n\nexport const strykerPlugins = [\n declareFactoryPlugin(\n PluginKind.Ignore,\n 'log-ignore',\n createLogIgnorerFactory(),\n ),\n]\n\nexport const strykerValidationSchema: typeof import('../schema/log-ignorer-options.json') =\n JSON.parse(\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n fs.readFileSync(\n new URL('../schema/log-ignorer-options.json', import.meta.url),\n 'utf8',\n ),\n )\n"]}
|
package/build/index.d.cts
CHANGED
|
@@ -4,6 +4,53 @@ import { StrykerOptions } from '@stryker-mutator/api/core';
|
|
|
4
4
|
import { Ignorer } from '@stryker-mutator/api/ignore';
|
|
5
5
|
import { Logger } from '@stryker-mutator/api/logging';
|
|
6
6
|
|
|
7
|
+
var $schema = "http://json-schema.org/draft-07/schema";
|
|
8
|
+
var type = "object";
|
|
9
|
+
var title = "LogIgnorerOptions";
|
|
10
|
+
var additionalProperties = false;
|
|
11
|
+
var properties = {
|
|
12
|
+
logignore: {
|
|
13
|
+
description: "Configuration for @sgohlke/stryker-log-ignorer",
|
|
14
|
+
title: "IgnorerOptions",
|
|
15
|
+
additionalProperties: false,
|
|
16
|
+
type: "object",
|
|
17
|
+
"default": {
|
|
18
|
+
},
|
|
19
|
+
properties: {
|
|
20
|
+
objectNames: {
|
|
21
|
+
description: "Specify the object names of the logger objects to be ignored. Defaults to [\"console\"]",
|
|
22
|
+
type: "array",
|
|
23
|
+
items: {
|
|
24
|
+
type: "string"
|
|
25
|
+
},
|
|
26
|
+
"default": [
|
|
27
|
+
"console"
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var logIgnorerOptions = {
|
|
34
|
+
$schema: $schema,
|
|
35
|
+
type: type,
|
|
36
|
+
title: title,
|
|
37
|
+
additionalProperties: additionalProperties,
|
|
38
|
+
properties: properties
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
declare const ___schema_log_ignorer_options_json_$schema: typeof $schema;
|
|
42
|
+
declare const ___schema_log_ignorer_options_json_additionalProperties: typeof additionalProperties;
|
|
43
|
+
declare const ___schema_log_ignorer_options_json_properties: typeof properties;
|
|
44
|
+
declare const ___schema_log_ignorer_options_json_title: typeof title;
|
|
45
|
+
declare const ___schema_log_ignorer_options_json_type: typeof type;
|
|
46
|
+
declare namespace ___schema_log_ignorer_options_json {
|
|
47
|
+
export { ___schema_log_ignorer_options_json_$schema as $schema, ___schema_log_ignorer_options_json_additionalProperties as additionalProperties, logIgnorerOptions as default, ___schema_log_ignorer_options_json_properties as properties, ___schema_log_ignorer_options_json_title as title, ___schema_log_ignorer_options_json_type as type };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* We define the necessary functions and fields for NodePath to be able to provide type safety
|
|
52
|
+
* in our code.
|
|
53
|
+
*/
|
|
7
54
|
interface NodePath {
|
|
8
55
|
isExpressionStatement(): boolean;
|
|
9
56
|
node: {
|
|
@@ -19,13 +66,22 @@ interface NodePath {
|
|
|
19
66
|
};
|
|
20
67
|
};
|
|
21
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Configuration for @sgohlke/stryker-log-ignorer
|
|
71
|
+
*/
|
|
72
|
+
interface IgnorerOptions {
|
|
73
|
+
/**
|
|
74
|
+
* Specify the object names of the logger objects to be ignored. Defaults to ["console"]
|
|
75
|
+
*/
|
|
76
|
+
objectNames?: string[];
|
|
77
|
+
}
|
|
22
78
|
interface LogIgnorerOptions extends StrykerOptions {
|
|
23
|
-
|
|
79
|
+
logignore: IgnorerOptions;
|
|
24
80
|
}
|
|
25
81
|
declare class LogIgnorer implements Ignorer {
|
|
26
82
|
private readonly log?;
|
|
27
83
|
static inject: readonly ["logger", "options"];
|
|
28
|
-
|
|
84
|
+
protected readonly options: LogIgnorerOptions;
|
|
29
85
|
constructor(log?: Logger | undefined, options?: StrykerOptions);
|
|
30
86
|
shouldIgnore(path: NodePath): string | undefined;
|
|
31
87
|
}
|
|
@@ -38,5 +94,6 @@ declare function createLogIgnorerFactory(): {
|
|
|
38
94
|
inject: ['$injector'];
|
|
39
95
|
};
|
|
40
96
|
declare const strykerPlugins: _stryker_mutator_api_plugin.FactoryPlugin<PluginKind.Ignore, ["$injector"]>[];
|
|
97
|
+
declare const strykerValidationSchema: typeof ___schema_log_ignorer_options_json;
|
|
41
98
|
|
|
42
|
-
export { LogIgnorer, type LogIgnorerOptions, type NodePath, createLogIgnorerFactory, logIgnorerFactory, strykerPlugins };
|
|
99
|
+
export { type IgnorerOptions, LogIgnorer, type LogIgnorerOptions, type NodePath, createLogIgnorerFactory, logIgnorerFactory, strykerPlugins, strykerValidationSchema };
|
package/build/index.d.ts
CHANGED
|
@@ -4,6 +4,53 @@ import { StrykerOptions } from '@stryker-mutator/api/core';
|
|
|
4
4
|
import { Ignorer } from '@stryker-mutator/api/ignore';
|
|
5
5
|
import { Logger } from '@stryker-mutator/api/logging';
|
|
6
6
|
|
|
7
|
+
var $schema = "http://json-schema.org/draft-07/schema";
|
|
8
|
+
var type = "object";
|
|
9
|
+
var title = "LogIgnorerOptions";
|
|
10
|
+
var additionalProperties = false;
|
|
11
|
+
var properties = {
|
|
12
|
+
logignore: {
|
|
13
|
+
description: "Configuration for @sgohlke/stryker-log-ignorer",
|
|
14
|
+
title: "IgnorerOptions",
|
|
15
|
+
additionalProperties: false,
|
|
16
|
+
type: "object",
|
|
17
|
+
"default": {
|
|
18
|
+
},
|
|
19
|
+
properties: {
|
|
20
|
+
objectNames: {
|
|
21
|
+
description: "Specify the object names of the logger objects to be ignored. Defaults to [\"console\"]",
|
|
22
|
+
type: "array",
|
|
23
|
+
items: {
|
|
24
|
+
type: "string"
|
|
25
|
+
},
|
|
26
|
+
"default": [
|
|
27
|
+
"console"
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var logIgnorerOptions = {
|
|
34
|
+
$schema: $schema,
|
|
35
|
+
type: type,
|
|
36
|
+
title: title,
|
|
37
|
+
additionalProperties: additionalProperties,
|
|
38
|
+
properties: properties
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
declare const ___schema_log_ignorer_options_json_$schema: typeof $schema;
|
|
42
|
+
declare const ___schema_log_ignorer_options_json_additionalProperties: typeof additionalProperties;
|
|
43
|
+
declare const ___schema_log_ignorer_options_json_properties: typeof properties;
|
|
44
|
+
declare const ___schema_log_ignorer_options_json_title: typeof title;
|
|
45
|
+
declare const ___schema_log_ignorer_options_json_type: typeof type;
|
|
46
|
+
declare namespace ___schema_log_ignorer_options_json {
|
|
47
|
+
export { ___schema_log_ignorer_options_json_$schema as $schema, ___schema_log_ignorer_options_json_additionalProperties as additionalProperties, logIgnorerOptions as default, ___schema_log_ignorer_options_json_properties as properties, ___schema_log_ignorer_options_json_title as title, ___schema_log_ignorer_options_json_type as type };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* We define the necessary functions and fields for NodePath to be able to provide type safety
|
|
52
|
+
* in our code.
|
|
53
|
+
*/
|
|
7
54
|
interface NodePath {
|
|
8
55
|
isExpressionStatement(): boolean;
|
|
9
56
|
node: {
|
|
@@ -19,13 +66,22 @@ interface NodePath {
|
|
|
19
66
|
};
|
|
20
67
|
};
|
|
21
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Configuration for @sgohlke/stryker-log-ignorer
|
|
71
|
+
*/
|
|
72
|
+
interface IgnorerOptions {
|
|
73
|
+
/**
|
|
74
|
+
* Specify the object names of the logger objects to be ignored. Defaults to ["console"]
|
|
75
|
+
*/
|
|
76
|
+
objectNames?: string[];
|
|
77
|
+
}
|
|
22
78
|
interface LogIgnorerOptions extends StrykerOptions {
|
|
23
|
-
|
|
79
|
+
logignore: IgnorerOptions;
|
|
24
80
|
}
|
|
25
81
|
declare class LogIgnorer implements Ignorer {
|
|
26
82
|
private readonly log?;
|
|
27
83
|
static inject: readonly ["logger", "options"];
|
|
28
|
-
|
|
84
|
+
protected readonly options: LogIgnorerOptions;
|
|
29
85
|
constructor(log?: Logger | undefined, options?: StrykerOptions);
|
|
30
86
|
shouldIgnore(path: NodePath): string | undefined;
|
|
31
87
|
}
|
|
@@ -38,5 +94,6 @@ declare function createLogIgnorerFactory(): {
|
|
|
38
94
|
inject: ['$injector'];
|
|
39
95
|
};
|
|
40
96
|
declare const strykerPlugins: _stryker_mutator_api_plugin.FactoryPlugin<PluginKind.Ignore, ["$injector"]>[];
|
|
97
|
+
declare const strykerValidationSchema: typeof ___schema_log_ignorer_options_json;
|
|
41
98
|
|
|
42
|
-
export { LogIgnorer, type LogIgnorerOptions, type NodePath, createLogIgnorerFactory, logIgnorerFactory, strykerPlugins };
|
|
99
|
+
export { type IgnorerOptions, LogIgnorer, type LogIgnorerOptions, type NodePath, createLogIgnorerFactory, logIgnorerFactory, strykerPlugins, strykerValidationSchema };
|
package/build/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
PluginKind,
|
|
6
6
|
tokens
|
|
7
7
|
} from "@stryker-mutator/api/plugin";
|
|
8
|
+
import fs from "node:fs";
|
|
8
9
|
var LogIgnorer = class {
|
|
9
10
|
constructor(log, options) {
|
|
10
11
|
this.log = log;
|
|
@@ -13,13 +14,11 @@ var LogIgnorer = class {
|
|
|
13
14
|
static inject = [commonTokens.logger, commonTokens.options];
|
|
14
15
|
options;
|
|
15
16
|
shouldIgnore(path) {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (path.isExpressionStatement() && path.node.expression.type === "CallExpression" && path.node.expression.callee.type === "MemberExpression" && path.node.expression.callee.object.type === "Identifier" && path.node.expression.callee.object.name === loggerClass) {
|
|
22
|
-
return `We are not interested in testing ${loggerClass} statements.`;
|
|
17
|
+
const loggerObjectNames = this.options?.logignore?.objectNames ?? [
|
|
18
|
+
"console"
|
|
19
|
+
];
|
|
20
|
+
if (path.isExpressionStatement() && path.node.expression.type === "CallExpression" && path.node.expression.callee.type === "MemberExpression" && path.node.expression.callee.object.type === "Identifier" && loggerObjectNames.includes(path.node.expression.callee.object.name)) {
|
|
21
|
+
return `We are not interested in testing ${loggerObjectNames} statements.`;
|
|
23
22
|
}
|
|
24
23
|
}
|
|
25
24
|
};
|
|
@@ -30,14 +29,25 @@ function logIgnorerFactory(injector) {
|
|
|
30
29
|
function createLogIgnorerFactory() {
|
|
31
30
|
return logIgnorerFactory;
|
|
32
31
|
}
|
|
33
|
-
var createLogIgnorer = createLogIgnorerFactory();
|
|
34
32
|
var strykerPlugins = [
|
|
35
|
-
declareFactoryPlugin(
|
|
33
|
+
declareFactoryPlugin(
|
|
34
|
+
PluginKind.Ignore,
|
|
35
|
+
"log-ignore",
|
|
36
|
+
createLogIgnorerFactory()
|
|
37
|
+
)
|
|
36
38
|
];
|
|
39
|
+
var strykerValidationSchema = JSON.parse(
|
|
40
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
41
|
+
fs.readFileSync(
|
|
42
|
+
new URL("../schema/log-ignorer-options.json", import.meta.url),
|
|
43
|
+
"utf8"
|
|
44
|
+
)
|
|
45
|
+
);
|
|
37
46
|
export {
|
|
38
47
|
LogIgnorer,
|
|
39
48
|
createLogIgnorerFactory,
|
|
40
49
|
logIgnorerFactory,
|
|
41
|
-
strykerPlugins
|
|
50
|
+
strykerPlugins,
|
|
51
|
+
strykerValidationSchema
|
|
42
52
|
};
|
|
43
53
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { StrykerOptions } from '@stryker-mutator/api/core'\nimport { Ignorer } from '@stryker-mutator/api/ignore'\nimport { Logger } from '@stryker-mutator/api/logging'\nimport {\n commonTokens,\n declareFactoryPlugin,\n Injector,\n PluginContext,\n PluginKind,\n tokens,\n} from '@stryker-mutator/api/plugin'\n\nexport interface NodePath {\n isExpressionStatement(): boolean\n node: {\n expression: {\n type: string\n callee: {\n type: string\n object: {\n type: string\n name: string\n }\n }\n }\n }\n}\n\nexport interface LogIgnorerOptions extends StrykerOptions {\n
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { StrykerOptions } from '@stryker-mutator/api/core'\nimport { Ignorer } from '@stryker-mutator/api/ignore'\nimport { Logger } from '@stryker-mutator/api/logging'\nimport {\n commonTokens,\n declareFactoryPlugin,\n Injector,\n PluginContext,\n PluginKind,\n tokens,\n} from '@stryker-mutator/api/plugin'\nimport fs from 'node:fs'\n\n/**\n * We define the necessary functions and fields for NodePath to be able to provide type safety\n * in our code.\n */\nexport interface NodePath {\n isExpressionStatement(): boolean\n node: {\n expression: {\n type: string\n callee: {\n type: string\n object: {\n type: string\n name: string\n }\n }\n }\n }\n}\n\n/**\n * Configuration for @sgohlke/stryker-log-ignorer\n */\nexport interface IgnorerOptions {\n /**\n * Specify the object names of the logger objects to be ignored. Defaults to [\"console\"]\n */\n objectNames?: string[]\n}\n\nexport interface LogIgnorerOptions extends StrykerOptions {\n logignore: IgnorerOptions\n}\n\n/*\n * LogIgnorer provides functionality to ignore log calls for provides logger object names.\n */\nexport class LogIgnorer implements Ignorer {\n public static inject = [commonTokens.logger, commonTokens.options] as const\n protected readonly options: LogIgnorerOptions\n\n constructor(\n // eslint-disable-next-line @typescript-eslint/parameter-properties\n private readonly log?: Logger,\n options?: StrykerOptions,\n ) {\n this.options = options as LogIgnorerOptions\n }\n\n shouldIgnore(path: NodePath): string | undefined {\n const loggerObjectNames = this.options?.logignore?.objectNames ?? [\n 'console',\n ]\n if (\n path.isExpressionStatement() &&\n path.node.expression.type === 'CallExpression' &&\n path.node.expression.callee.type === 'MemberExpression' &&\n path.node.expression.callee.object.type === 'Identifier' &&\n loggerObjectNames.includes(path.node.expression.callee.object.name)\n ) {\n return `We are not interested in testing ${loggerObjectNames} statements.`\n }\n }\n}\n\nlogIgnorerFactory.inject = tokens(commonTokens.injector)\n\nexport function logIgnorerFactory(\n injector: Injector<PluginContext>,\n): LogIgnorer {\n return injector.injectClass(LogIgnorer)\n}\n\nexport function createLogIgnorerFactory(): {\n (injector: Injector<PluginContext>): LogIgnorer\n inject: ['$injector']\n} {\n return logIgnorerFactory\n}\n\nexport const strykerPlugins = [\n declareFactoryPlugin(\n PluginKind.Ignore,\n 'log-ignore',\n createLogIgnorerFactory(),\n ),\n]\n\nexport const strykerValidationSchema: typeof import('../schema/log-ignorer-options.json') =\n JSON.parse(\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n fs.readFileSync(\n new URL('../schema/log-ignorer-options.json', import.meta.url),\n 'utf8',\n ),\n )\n"],"mappings":";AAGA;AAAA,EACI;AAAA,EACA;AAAA,EAGA;AAAA,EACA;AAAA,OACG;AACP,OAAO,QAAQ;AAuCR,IAAM,aAAN,MAAoC;AAAA,EAIvC,YAEqB,KACjB,SACF;AAFmB;AAGjB,SAAK,UAAU;AAAA,EACnB;AAAA,EATA,OAAc,SAAS,CAAC,aAAa,QAAQ,aAAa,OAAO;AAAA,EAC9C;AAAA,EAUnB,aAAa,MAAoC;AAC7C,UAAM,oBAAoB,KAAK,SAAS,WAAW,eAAe;AAAA,MAC9D;AAAA,IACJ;AACA,QACI,KAAK,sBAAsB,KAC3B,KAAK,KAAK,WAAW,SAAS,oBAC9B,KAAK,KAAK,WAAW,OAAO,SAAS,sBACrC,KAAK,KAAK,WAAW,OAAO,OAAO,SAAS,gBAC5C,kBAAkB,SAAS,KAAK,KAAK,WAAW,OAAO,OAAO,IAAI,GACpE;AACE,aAAO,oCAAoC,iBAAiB;AAAA,IAChE;AAAA,EACJ;AACJ;AAEA,kBAAkB,SAAS,OAAO,aAAa,QAAQ;AAEhD,SAAS,kBACZ,UACU;AACV,SAAO,SAAS,YAAY,UAAU;AAC1C;AAEO,SAAS,0BAGd;AACE,SAAO;AACX;AAEO,IAAM,iBAAiB;AAAA,EAC1B;AAAA,IACI,WAAW;AAAA,IACX;AAAA,IACA,wBAAwB;AAAA,EAC5B;AACJ;AAEO,IAAM,0BACT,KAAK;AAAA;AAAA,EAED,GAAG;AAAA,IACC,IAAI,IAAI,sCAAsC,YAAY,GAAG;AAAA,IAC7D;AAAA,EACJ;AACJ;","names":[]}
|
package/package.json
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema",
|
|
3
|
+
"type": "object",
|
|
4
|
+
"title": "LogIgnorerOptions",
|
|
5
|
+
"additionalProperties": false,
|
|
6
|
+
"properties": {
|
|
7
|
+
"logignore": {
|
|
8
|
+
"description": "Configuration for @sgohlke/stryker-log-ignorer",
|
|
9
|
+
"title": "IgnorerOptions",
|
|
10
|
+
"additionalProperties": false,
|
|
11
|
+
"type": "object",
|
|
12
|
+
"default": {},
|
|
13
|
+
"properties": {
|
|
14
|
+
"objectNames": {
|
|
15
|
+
"description": "Specify the object names of the logger objects to be ignored. Defaults to [\"console\"]",
|
|
16
|
+
"type": "array",
|
|
17
|
+
"items": {
|
|
18
|
+
"type": "string"
|
|
19
|
+
},
|
|
20
|
+
"default": ["console"]
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
package/.prettierrc.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"plugins": ["prettier-plugin-organize-imports"],
|
|
3
|
-
"semi": false,
|
|
4
|
-
"singleQuote": true,
|
|
5
|
-
"tabWidth": 4,
|
|
6
|
-
"trailingComma": "all",
|
|
7
|
-
"overrides": [
|
|
8
|
-
{
|
|
9
|
-
"files": ["*.yml", "*.yaml"],
|
|
10
|
-
"options": {
|
|
11
|
-
"singleQuote": false,
|
|
12
|
-
"tabWidth": 2
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
]
|
|
16
|
-
}
|
package/stryker.config.json
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "./node_modules/@stryker-mutator/core/schema/stryker-schema.json",
|
|
3
|
-
"_comment": "This config was generated using 'stryker init'. Please take a look at: https://stryker-mutator.io/docs/stryker-js/configuration/ for more information.",
|
|
4
|
-
"packageManager": "npm",
|
|
5
|
-
"reporters": ["html", "clear-text", "progress"],
|
|
6
|
-
"testRunner": "vitest",
|
|
7
|
-
"testRunner_comment": "Take a look at https://stryker-mutator.io/docs/stryker-js/vitest-runner for information about the vitest plugin.",
|
|
8
|
-
"coverageAnalysis": "perTest",
|
|
9
|
-
"buildCommand": "npm run build",
|
|
10
|
-
"ignorers": ["log-ignore"],
|
|
11
|
-
"plugins": ["@stryker-mutator/*", "./build/index.js"]
|
|
12
|
-
}
|
package/tsup.config.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'tsup'
|
|
2
|
-
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
entry: ['src/index.ts'],
|
|
5
|
-
outDir: 'build',
|
|
6
|
-
clean: true,
|
|
7
|
-
target: ['es2022', 'node18'],
|
|
8
|
-
format: ['cjs', 'esm'],
|
|
9
|
-
dts: true,
|
|
10
|
-
minify: false,
|
|
11
|
-
sourcemap: true,
|
|
12
|
-
splitting: true,
|
|
13
|
-
})
|
package/vitest.config.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import tsconfigPaths from 'vite-tsconfig-paths'
|
|
2
|
-
import { defineConfig } from 'vitest/config'
|
|
3
|
-
|
|
4
|
-
export default defineConfig({
|
|
5
|
-
plugins: [tsconfigPaths()],
|
|
6
|
-
test: {
|
|
7
|
-
coverage: {
|
|
8
|
-
exclude: ['build', 'tests'],
|
|
9
|
-
provider: 'v8',
|
|
10
|
-
reporter: ['text'],
|
|
11
|
-
},
|
|
12
|
-
exclude: ['node_modules', 'build', '.idea', '.git', '.cache'],
|
|
13
|
-
},
|
|
14
|
-
})
|