-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Ignorer plugin): support ignorer plugins (#4487)
Add a new plugin type: "Ignorer". Ignorer plugins can ignore mutants based on arbitrary heuristics. You can configure it like this: ```json { "ignorers": ["ConsoleIgnorer"], "plugins": [ "@stryker-mutator/*", "./stryker-plugins/console-ignorer.js" ] } ``` The console-ignorer.js file might look like this: ```js import { PluginKind, declareClassPlugin } from '@stryker-mutator/api/plugin'; class ConsoleIgnorer { shouldIgnore(path) { 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 === 'console' && path.node.expression.callee.property.type === 'Identifier' && path.node.expression.callee.property.name === 'log' ) { return "We're not interested in console.log statements for now"; } return undefined; } } export const strykerPlugins = [declareClassPlugin(PluginKind.Ignorer, 'ConsoleIgnorer', ConsoleIgnorer)]; ``` --------- Co-authored-by: Nico Jansen <jansennico@gmail.com>
- Loading branch information
1 parent
68ed32a
commit 4fe1000
Showing
35 changed files
with
440 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
'printWidth': 150, | ||
'singleQuote': true, | ||
'endOfLine': 'auto', | ||
"printWidth": 150, | ||
"singleQuote": true, | ||
"endOfLine": "auto" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,45 @@ | ||
module.exports.add = function (num1, num2) { | ||
export function add (num1, num2) { | ||
console.log('Add' + 'called'); | ||
return num1 + num2; | ||
}; | ||
} | ||
|
||
module.exports.addOne = function (number) { | ||
export function addOne (number) { | ||
number++; | ||
console.log('add one called'); | ||
return number; | ||
}; | ||
} | ||
|
||
module.exports.negate = function (number) { | ||
export function negate (number) { | ||
console.log('negate called'); | ||
return -number; | ||
}; | ||
} | ||
|
||
module.exports.notCovered = function (number) { | ||
export function notCovered (number) { | ||
console.warn('not covered!'); | ||
return number > 10; | ||
}; | ||
} | ||
|
||
module.exports.userNextLineIgnored = function (number) { | ||
export function userNextLineIgnored (number) { | ||
// Stryker disable next-line all: Ignoring this on purpose | ||
return number > 10; | ||
}; | ||
} | ||
|
||
// Stryker disable all | ||
module.exports.blockUserIgnored = function (number) { | ||
export function blockUserIgnored (number) { | ||
return number > 10; | ||
}; | ||
} | ||
// Stryker restore all | ||
|
||
module.exports.userNextLineSpecificMutator = function (number) { | ||
export function userNextLineSpecificMutator (number) { | ||
// Stryker disable next-line BooleanLiteral, ConditionalExpression: Ignore boolean and conditions | ||
return true && number > 10; | ||
}; | ||
} | ||
|
||
|
||
module.exports.isNegativeNumber = function (number) { | ||
export function isNegativeNumber (number) { | ||
var isNegative = false; | ||
if (number < 0) { | ||
isNegative = true; | ||
} | ||
return isNegative; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
module.exports.getCircumference = function(radius) { | ||
export function getCircumference(radius) { | ||
//Function to test multiple math mutations in a single function. | ||
return 2 * Math.PI * radius; | ||
}; | ||
} | ||
|
||
module.exports.untestedFunction = function() { | ||
export function untestedFunction() { | ||
var i = 5 / 2 * 3; | ||
}; | ||
} |
23 changes: 23 additions & 0 deletions
23
e2e/test/ignore-project/stryker-plugins/ignorers/console-ignorer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// @ts-check | ||
import { PluginKind, declareClassPlugin } from '@stryker-mutator/api/plugin'; | ||
|
||
export class ConsoleIgnorer { | ||
/** | ||
* @param {import('@stryker-mutator/api/ignorer').NodePath} path | ||
*/ | ||
shouldIgnore(path) { | ||
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 === 'console' && | ||
path.node.expression.callee.property.type === 'Identifier' && | ||
path.node.expression.callee.property.name === 'log' | ||
) { | ||
return "We're not interested in console.log statements for now"; | ||
} | ||
return undefined; | ||
} | ||
} | ||
export const strykerPlugins = [declareClassPlugin(PluginKind.Ignorer, 'ConsoleIgnorer', ConsoleIgnorer)]; |
6 changes: 6 additions & 0 deletions
6
e2e/test/ignore-project/stryker-plugins/ignorers/global.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import type babel from '@babel/core'; | ||
|
||
declare module '@stryker-mutator/api/ignorer' { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
interface NodePath extends babel.NodePath {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
exports.mochaHooks = { | ||
import { expect } from 'chai'; | ||
export const mochaHooks = { | ||
beforeAll() { | ||
global.expect = require('chai').expect; | ||
global.expect = expect; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface NodePath { | ||
// Left empty so the declaration can be merged | ||
} | ||
|
||
export interface Ignorer { | ||
shouldIgnore(path: NodePath): string | undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './ignorer.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.