@sgohlke/stryker-log-ignorer 1.0.0 → 2.0.1

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
@@ -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 **logignore** 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 **logignore** 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,25 +1,21 @@
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
- constructor(log, options) {
10
- this.log = log;
11
- this.options = options;
12
- }
13
- static __initStatic() {this.inject = [_plugin.commonTokens.logger, _plugin.commonTokens.options]}
10
+ static __initStatic() {this.inject = [_plugin.commonTokens.options]}
14
11
 
12
+ constructor(options) {
13
+ this.options = _optionalChain([options, 'optionalAccess', _ => _.logignore]);
14
+ }
15
15
  shouldIgnore(path) {
16
- const loggerClass = _nullishCoalesce(_optionalChain([this, 'access', _ => _.options, 'optionalAccess', _2 => _2.loggerClass]), () => ( "console"));
17
- _optionalChain([this, 'access', _3 => _3.log, 'optionalAccess', _4 => _4.debug, 'call', _5 => _5(
18
- "LogIgnore Plugin. Path is: ",
19
- JSON.stringify(path.node)
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.`;
16
+ const loggerObjectNames = _nullishCoalesce(_optionalChain([this, 'access', _2 => _2.options, 'optionalAccess', _3 => _3.objectNames]), () => ( ["console"]));
17
+ 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)) {
18
+ return `We are not interested in testing ${loggerObjectNames} statements.`;
23
19
  }
24
20
  }
25
21
  }, _class.__initStatic(), _class);
@@ -30,14 +26,25 @@ function logIgnorerFactory(injector) {
30
26
  function createLogIgnorerFactory() {
31
27
  return logIgnorerFactory;
32
28
  }
33
- var createLogIgnorer = createLogIgnorerFactory();
34
29
  var strykerPlugins = [
35
- _plugin.declareFactoryPlugin.call(void 0, _plugin.PluginKind.Ignore, "log-ignore", createLogIgnorer)
30
+ _plugin.declareFactoryPlugin.call(void 0,
31
+ _plugin.PluginKind.Ignore,
32
+ "log-ignore",
33
+ createLogIgnorerFactory()
34
+ )
36
35
  ];
36
+ var strykerValidationSchema = JSON.parse(
37
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
38
+ _fs2.default.readFileSync(
39
+ new URL("../schema/log-ignorer-options.json", import.meta.url),
40
+ "utf8"
41
+ )
42
+ );
43
+
37
44
 
38
45
 
39
46
 
40
47
 
41
48
 
42
- exports.LogIgnorer = LogIgnorer; exports.createLogIgnorerFactory = createLogIgnorerFactory; exports.logIgnorerFactory = logIgnorerFactory; exports.strykerPlugins = strykerPlugins;
49
+ exports.LogIgnorer = LogIgnorer; exports.createLogIgnorerFactory = createLogIgnorerFactory; exports.logIgnorerFactory = logIgnorerFactory; exports.strykerPlugins = strykerPlugins; exports.strykerValidationSchema = strykerValidationSchema;
43
50
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";AAGA;AAAA,EACI;AAAA,EACA;AAAA,EAGA;AAAA,EACA;AAAA,OACG;AAsBA,IAAM,aAAN,MAAoC;AAAA,EAIvC,YAEqB,KACjB,SACF;AAFmB;AAGjB,SAAK,UAAU;AAAA,EACnB;AAAA,EATA,OAAc,SAAS,CAAC,aAAa,QAAQ,aAAa,OAAO;AAAA,EAChD;AAAA,EAUjB,aAAa,MAAoC;AAC7C,UAAM,cAAc,KAAK,SAAS,eAAe;AACjD,SAAK,KAAK;AAAA,MACN;AAAA,MACA,KAAK,UAAU,KAAK,IAAI;AAAA,IAC5B;AACA,QACI,KAAK,sBAAsB,KAC3B,KAAK,KAAK,WAAW,SAAS,oBAC9B,KAAK,KAAK,WAAW,OAAO,SAAS,sBACrC,KAAK,KAAK,WAAW,OAAO,OAAO,SAAS,gBAC5C,KAAK,KAAK,WAAW,OAAO,OAAO,SAAS,aAC9C;AACE,aAAO,oCAAoC,WAAW;AAAA,IAC1D;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;AAEA,IAAM,mBAAmB,wBAAwB;AAC1C,IAAM,iBAAiB;AAAA,EAC1B,qBAAqB,WAAW,QAAQ,cAAc,gBAAgB;AAC1E","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 loggerClass?: string\n}\n\nexport class LogIgnorer implements Ignorer {\n public static inject = [commonTokens.logger, commonTokens.options] as const\n private 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 loggerClass = this.options?.loggerClass ?? 'console'\n this.log?.debug(\n 'LogIgnore Plugin. Path is: ',\n JSON.stringify(path.node),\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 path.node.expression.callee.object.name === loggerClass\n ) {\n return `We are not interested in testing ${loggerClass} 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\nconst createLogIgnorer = createLogIgnorerFactory()\nexport const strykerPlugins = [\n declareFactoryPlugin(PluginKind.Ignore, 'log-ignore', createLogIgnorer),\n]\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";AAEA;AAAA,EACI;AAAA,EACA;AAAA,EAGA;AAAA,EACA;AAAA,OACG;AACP,OAAO,QAAQ;AAuCR,IAAM,aAAN,MAAoC;AAAA,EACvC,OAAc,SAAS,CAAC,aAAa,OAAO;AAAA,EACzB;AAAA,EAEnB,YAAY,SAAsC;AAC9C,SAAK,UAAU,SAAS;AAAA,EAC5B;AAAA,EAEA,aAAa,MAAoC;AAC7C,UAAM,oBAAoB,KAAK,SAAS,eAAe,CAAC,SAAS;AACjE,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 {\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 provided logger object names.\n */\nexport class LogIgnorer implements Ignorer {\n public static inject = [commonTokens.options] as const\n protected readonly options?: IgnorerOptions\n\n constructor(options?: Partial<LogIgnorerOptions>) {\n this.options = options?.logignore\n }\n\n shouldIgnore(path: NodePath): string | undefined {\n const loggerObjectNames = this.options?.objectNames ?? ['console']\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
@@ -2,8 +2,54 @@ import * as _stryker_mutator_api_plugin from '@stryker-mutator/api/plugin';
2
2
  import { Injector, PluginContext, PluginKind } from '@stryker-mutator/api/plugin';
3
3
  import { StrykerOptions } from '@stryker-mutator/api/core';
4
4
  import { Ignorer } from '@stryker-mutator/api/ignore';
5
- import { Logger } from '@stryker-mutator/api/logging';
6
5
 
6
+ var $schema = "http://json-schema.org/draft-07/schema";
7
+ var type = "object";
8
+ var title = "LogIgnorerOptions";
9
+ var additionalProperties = false;
10
+ var properties = {
11
+ logignore: {
12
+ description: "Configuration for @sgohlke/stryker-log-ignorer",
13
+ title: "IgnorerOptions",
14
+ additionalProperties: false,
15
+ type: "object",
16
+ "default": {
17
+ },
18
+ properties: {
19
+ objectNames: {
20
+ description: "Specify the object names of the logger objects to be ignored. Defaults to [\"console\"]",
21
+ type: "array",
22
+ items: {
23
+ type: "string"
24
+ },
25
+ "default": [
26
+ "console"
27
+ ]
28
+ }
29
+ }
30
+ }
31
+ };
32
+ var logIgnorerOptions = {
33
+ $schema: $schema,
34
+ type: type,
35
+ title: title,
36
+ additionalProperties: additionalProperties,
37
+ properties: properties
38
+ };
39
+
40
+ declare const ___schema_log_ignorer_options_json_$schema: typeof $schema;
41
+ declare const ___schema_log_ignorer_options_json_additionalProperties: typeof additionalProperties;
42
+ declare const ___schema_log_ignorer_options_json_properties: typeof properties;
43
+ declare const ___schema_log_ignorer_options_json_title: typeof title;
44
+ declare const ___schema_log_ignorer_options_json_type: typeof type;
45
+ declare namespace ___schema_log_ignorer_options_json {
46
+ 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 };
47
+ }
48
+
49
+ /**
50
+ * We define the necessary functions and fields for NodePath to be able to provide type safety
51
+ * in our code.
52
+ */
7
53
  interface NodePath {
8
54
  isExpressionStatement(): boolean;
9
55
  node: {
@@ -19,14 +65,22 @@ interface NodePath {
19
65
  };
20
66
  };
21
67
  }
68
+ /**
69
+ * Configuration for @sgohlke/stryker-log-ignorer
70
+ */
71
+ interface IgnorerOptions {
72
+ /**
73
+ * Specify the object names of the logger objects to be ignored. Defaults to ["console"]
74
+ */
75
+ objectNames?: string[];
76
+ }
22
77
  interface LogIgnorerOptions extends StrykerOptions {
23
- loggerClass?: string;
78
+ logignore?: IgnorerOptions;
24
79
  }
25
80
  declare class LogIgnorer implements Ignorer {
26
- private readonly log?;
27
- static inject: readonly ["logger", "options"];
28
- private readonly options;
29
- constructor(log?: Logger | undefined, options?: StrykerOptions);
81
+ static inject: readonly ["options"];
82
+ protected readonly options?: IgnorerOptions;
83
+ constructor(options?: Partial<LogIgnorerOptions>);
30
84
  shouldIgnore(path: NodePath): string | undefined;
31
85
  }
32
86
  declare function logIgnorerFactory(injector: Injector<PluginContext>): LogIgnorer;
@@ -38,5 +92,6 @@ declare function createLogIgnorerFactory(): {
38
92
  inject: ['$injector'];
39
93
  };
40
94
  declare const strykerPlugins: _stryker_mutator_api_plugin.FactoryPlugin<PluginKind.Ignore, ["$injector"]>[];
95
+ declare const strykerValidationSchema: typeof ___schema_log_ignorer_options_json;
41
96
 
42
- export { LogIgnorer, type LogIgnorerOptions, type NodePath, createLogIgnorerFactory, logIgnorerFactory, strykerPlugins };
97
+ export { type IgnorerOptions, LogIgnorer, type LogIgnorerOptions, type NodePath, createLogIgnorerFactory, logIgnorerFactory, strykerPlugins, strykerValidationSchema };
package/build/index.d.ts CHANGED
@@ -2,8 +2,54 @@ import * as _stryker_mutator_api_plugin from '@stryker-mutator/api/plugin';
2
2
  import { Injector, PluginContext, PluginKind } from '@stryker-mutator/api/plugin';
3
3
  import { StrykerOptions } from '@stryker-mutator/api/core';
4
4
  import { Ignorer } from '@stryker-mutator/api/ignore';
5
- import { Logger } from '@stryker-mutator/api/logging';
6
5
 
6
+ var $schema = "http://json-schema.org/draft-07/schema";
7
+ var type = "object";
8
+ var title = "LogIgnorerOptions";
9
+ var additionalProperties = false;
10
+ var properties = {
11
+ logignore: {
12
+ description: "Configuration for @sgohlke/stryker-log-ignorer",
13
+ title: "IgnorerOptions",
14
+ additionalProperties: false,
15
+ type: "object",
16
+ "default": {
17
+ },
18
+ properties: {
19
+ objectNames: {
20
+ description: "Specify the object names of the logger objects to be ignored. Defaults to [\"console\"]",
21
+ type: "array",
22
+ items: {
23
+ type: "string"
24
+ },
25
+ "default": [
26
+ "console"
27
+ ]
28
+ }
29
+ }
30
+ }
31
+ };
32
+ var logIgnorerOptions = {
33
+ $schema: $schema,
34
+ type: type,
35
+ title: title,
36
+ additionalProperties: additionalProperties,
37
+ properties: properties
38
+ };
39
+
40
+ declare const ___schema_log_ignorer_options_json_$schema: typeof $schema;
41
+ declare const ___schema_log_ignorer_options_json_additionalProperties: typeof additionalProperties;
42
+ declare const ___schema_log_ignorer_options_json_properties: typeof properties;
43
+ declare const ___schema_log_ignorer_options_json_title: typeof title;
44
+ declare const ___schema_log_ignorer_options_json_type: typeof type;
45
+ declare namespace ___schema_log_ignorer_options_json {
46
+ 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 };
47
+ }
48
+
49
+ /**
50
+ * We define the necessary functions and fields for NodePath to be able to provide type safety
51
+ * in our code.
52
+ */
7
53
  interface NodePath {
8
54
  isExpressionStatement(): boolean;
9
55
  node: {
@@ -19,14 +65,22 @@ interface NodePath {
19
65
  };
20
66
  };
21
67
  }
68
+ /**
69
+ * Configuration for @sgohlke/stryker-log-ignorer
70
+ */
71
+ interface IgnorerOptions {
72
+ /**
73
+ * Specify the object names of the logger objects to be ignored. Defaults to ["console"]
74
+ */
75
+ objectNames?: string[];
76
+ }
22
77
  interface LogIgnorerOptions extends StrykerOptions {
23
- loggerClass?: string;
78
+ logignore?: IgnorerOptions;
24
79
  }
25
80
  declare class LogIgnorer implements Ignorer {
26
- private readonly log?;
27
- static inject: readonly ["logger", "options"];
28
- private readonly options;
29
- constructor(log?: Logger | undefined, options?: StrykerOptions);
81
+ static inject: readonly ["options"];
82
+ protected readonly options?: IgnorerOptions;
83
+ constructor(options?: Partial<LogIgnorerOptions>);
30
84
  shouldIgnore(path: NodePath): string | undefined;
31
85
  }
32
86
  declare function logIgnorerFactory(injector: Injector<PluginContext>): LogIgnorer;
@@ -38,5 +92,6 @@ declare function createLogIgnorerFactory(): {
38
92
  inject: ['$injector'];
39
93
  };
40
94
  declare const strykerPlugins: _stryker_mutator_api_plugin.FactoryPlugin<PluginKind.Ignore, ["$injector"]>[];
95
+ declare const strykerValidationSchema: typeof ___schema_log_ignorer_options_json;
41
96
 
42
- export { LogIgnorer, type LogIgnorerOptions, type NodePath, createLogIgnorerFactory, logIgnorerFactory, strykerPlugins };
97
+ export { type IgnorerOptions, LogIgnorer, type LogIgnorerOptions, type NodePath, createLogIgnorerFactory, logIgnorerFactory, strykerPlugins, strykerValidationSchema };
package/build/index.js CHANGED
@@ -5,21 +5,17 @@ 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
- constructor(log, options) {
10
- this.log = log;
11
- this.options = options;
12
- }
13
- static inject = [commonTokens.logger, commonTokens.options];
10
+ static inject = [commonTokens.options];
14
11
  options;
12
+ constructor(options) {
13
+ this.options = options?.logignore;
14
+ }
15
15
  shouldIgnore(path) {
16
- const loggerClass = this.options?.loggerClass ?? "console";
17
- this.log?.debug(
18
- "LogIgnore Plugin. Path is: ",
19
- JSON.stringify(path.node)
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.`;
16
+ const loggerObjectNames = this.options?.objectNames ?? ["console"];
17
+ 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)) {
18
+ return `We are not interested in testing ${loggerObjectNames} statements.`;
23
19
  }
24
20
  }
25
21
  };
@@ -30,14 +26,25 @@ function logIgnorerFactory(injector) {
30
26
  function createLogIgnorerFactory() {
31
27
  return logIgnorerFactory;
32
28
  }
33
- var createLogIgnorer = createLogIgnorerFactory();
34
29
  var strykerPlugins = [
35
- declareFactoryPlugin(PluginKind.Ignore, "log-ignore", createLogIgnorer)
30
+ declareFactoryPlugin(
31
+ PluginKind.Ignore,
32
+ "log-ignore",
33
+ createLogIgnorerFactory()
34
+ )
36
35
  ];
36
+ var strykerValidationSchema = JSON.parse(
37
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
38
+ fs.readFileSync(
39
+ new URL("../schema/log-ignorer-options.json", import.meta.url),
40
+ "utf8"
41
+ )
42
+ );
37
43
  export {
38
44
  LogIgnorer,
39
45
  createLogIgnorerFactory,
40
46
  logIgnorerFactory,
41
- strykerPlugins
47
+ strykerPlugins,
48
+ strykerValidationSchema
42
49
  };
43
50
  //# sourceMappingURL=index.js.map
@@ -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 loggerClass?: string\n}\n\nexport class LogIgnorer implements Ignorer {\n public static inject = [commonTokens.logger, commonTokens.options] as const\n private 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 loggerClass = this.options?.loggerClass ?? 'console'\n this.log?.debug(\n 'LogIgnore Plugin. Path is: ',\n JSON.stringify(path.node),\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 path.node.expression.callee.object.name === loggerClass\n ) {\n return `We are not interested in testing ${loggerClass} 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\nconst createLogIgnorer = createLogIgnorerFactory()\nexport const strykerPlugins = [\n declareFactoryPlugin(PluginKind.Ignore, 'log-ignore', createLogIgnorer),\n]\n"],"mappings":";AAGA;AAAA,EACI;AAAA,EACA;AAAA,EAGA;AAAA,EACA;AAAA,OACG;AAsBA,IAAM,aAAN,MAAoC;AAAA,EAIvC,YAEqB,KACjB,SACF;AAFmB;AAGjB,SAAK,UAAU;AAAA,EACnB;AAAA,EATA,OAAc,SAAS,CAAC,aAAa,QAAQ,aAAa,OAAO;AAAA,EAChD;AAAA,EAUjB,aAAa,MAAoC;AAC7C,UAAM,cAAc,KAAK,SAAS,eAAe;AACjD,SAAK,KAAK;AAAA,MACN;AAAA,MACA,KAAK,UAAU,KAAK,IAAI;AAAA,IAC5B;AACA,QACI,KAAK,sBAAsB,KAC3B,KAAK,KAAK,WAAW,SAAS,oBAC9B,KAAK,KAAK,WAAW,OAAO,SAAS,sBACrC,KAAK,KAAK,WAAW,OAAO,OAAO,SAAS,gBAC5C,KAAK,KAAK,WAAW,OAAO,OAAO,SAAS,aAC9C;AACE,aAAO,oCAAoC,WAAW;AAAA,IAC1D;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;AAEA,IAAM,mBAAmB,wBAAwB;AAC1C,IAAM,iBAAiB;AAAA,EAC1B,qBAAqB,WAAW,QAAQ,cAAc,gBAAgB;AAC1E;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { StrykerOptions } from '@stryker-mutator/api/core'\nimport { Ignorer } from '@stryker-mutator/api/ignore'\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 provided logger object names.\n */\nexport class LogIgnorer implements Ignorer {\n public static inject = [commonTokens.options] as const\n protected readonly options?: IgnorerOptions\n\n constructor(options?: Partial<LogIgnorerOptions>) {\n this.options = options?.logignore\n }\n\n shouldIgnore(path: NodePath): string | undefined {\n const loggerObjectNames = this.options?.objectNames ?? ['console']\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":";AAEA;AAAA,EACI;AAAA,EACA;AAAA,EAGA;AAAA,EACA;AAAA,OACG;AACP,OAAO,QAAQ;AAuCR,IAAM,aAAN,MAAoC;AAAA,EACvC,OAAc,SAAS,CAAC,aAAa,OAAO;AAAA,EACzB;AAAA,EAEnB,YAAY,SAAsC;AAC9C,SAAK,UAAU,SAAS;AAAA,EAC5B;AAAA,EAEA,aAAa,MAAoC;AAC7C,UAAM,oBAAoB,KAAK,SAAS,eAAe,CAAC,SAAS;AACjE,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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sgohlke/stryker-log-ignorer",
3
- "version": "1.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Log Ignorer for Stryker",
5
5
  "scripts": {
6
6
  "build": "tsup-node",
@@ -42,7 +42,7 @@
42
42
  "homepage": "https://github.com/sgohlke/stryker-log-ignorer#readme",
43
43
  "devDependencies": {
44
44
  "@types/node": "20.12.7",
45
- "@vitest/coverage-v8": "1.5.0",
45
+ "@vitest/coverage-v8": "1.5.2",
46
46
  "eslint-plugin-deprecation": "2.0.0",
47
47
  "eslint-plugin-import": "2.29.1",
48
48
  "eslint-plugin-security": "3.0.0",
@@ -53,7 +53,7 @@
53
53
  "typescript": "5.4.5",
54
54
  "typescript-eslint": "7.7.1",
55
55
  "vite-tsconfig-paths": "4.3.2",
56
- "vitest": "1.5.0"
56
+ "vitest": "1.5.2"
57
57
  },
58
58
  "dependencies": {
59
59
  "@stryker-mutator/api": "8.2.6"
@@ -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
- }
@@ -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
- })