hermione-test-filter
Advanced tools
Comparing version 0.4.0 to 0.5.0
@@ -28,2 +28,10 @@ 'use strict'; | ||
} | ||
}), | ||
filterTestsByCode: option({ | ||
defaultValue: null, | ||
validate: (v) => { | ||
if (!_.isRegExp(v) && !_.isString(v) && !_.isFunction(v) && !_.isNull(v)) { | ||
throw new Error(`"filterTestsByCode" option must be string, regexp or function, but got ${typeof v}`); | ||
} | ||
} | ||
}) | ||
@@ -30,0 +38,0 @@ }), {envPrefix: ENV_PREFIX, cliPrefix: CLI_PREFIX}); |
@@ -6,11 +6,17 @@ 'use strict'; | ||
const utils = require('./utils'); | ||
const TestCodeCollection = require('./test-code-collection'); | ||
module.exports = (hermione, opts) => { | ||
const pluginConfig = parseConfig(opts); | ||
let cliTool; | ||
if (!pluginConfig.enabled) { | ||
return; | ||
} | ||
hermione.on(hermione.events.CLI, (cli) => { | ||
cliTool = cli; | ||
cli.option( | ||
'--filter-tests-by-code <string>', | ||
'enable hermione-test-filter plugin and run with filtering tests by their code' | ||
); | ||
}); | ||
if (hermione.isWorker()) { | ||
if (!pluginConfig.enabled || hermione.isWorker()) { | ||
return; | ||
@@ -20,16 +26,58 @@ } | ||
let input; | ||
let testCodeCollection; | ||
hermione.on(hermione.events.INIT, async () => { | ||
input = await utils.readFile(pluginConfig.inputFile); | ||
}); | ||
const filterTestsByCode = cliTool && cliTool.filterTestsByCode || pluginConfig.filterTestsByCode; | ||
hermione.on(hermione.events.AFTER_TESTS_READ, (testCollection) => { | ||
if (_.isEmpty(input)) { | ||
if (pluginConfig.inputFile) { | ||
input = await utils.readFile(pluginConfig.inputFile); | ||
} | ||
if (!input && !filterTestsByCode) { | ||
return; | ||
} | ||
testCollection.disableAll(); | ||
hermione.on(hermione.events.BEFORE_FILE_READ, ({testParser}) => { | ||
if (!filterTestsByCode) { | ||
return; | ||
} | ||
input.forEach(({fullTitle, browserId}) => testCollection.enableTest(fullTitle, browserId)); | ||
testCodeCollection = new TestCodeCollection(); | ||
testParser.on(testParser.events.HOOK, (hook) => { | ||
testCodeCollection.add(hook); | ||
}); | ||
testParser.on(testParser.events.TEST, (test) => { | ||
testCodeCollection.add(test); | ||
}); | ||
}); | ||
hermione.on(hermione.events.AFTER_TESTS_READ, (testCollection) => { | ||
if (pluginConfig.inputFile && input && input.length) { | ||
testCollection.disableAll(); | ||
input.forEach(({fullTitle, browserId}) => testCollection.enableTest(fullTitle, browserId)); | ||
} | ||
if (!filterTestsByCode) { | ||
return; | ||
} | ||
const filter = _.isFunction(filterTestsByCode) | ||
? filterTestsByCode | ||
: (testSrc) => new RegExp(filterTestsByCode).test(testSrc); | ||
testCollection.eachTest((test, browserId) => { | ||
if (test.disabled) { | ||
return; | ||
} | ||
const testCode = testCodeCollection.getTestCode(test.fullTitle(), test.file); | ||
if (!filter(testCode)) { | ||
testCollection.disableTest(test.fullTitle(), browserId); | ||
} | ||
}); | ||
}); | ||
}); | ||
}; |
{ | ||
"name": "hermione-test-filter", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "plugin for filtering tests specified in json-file", | ||
@@ -23,3 +23,4 @@ "main": "lib/index.js", | ||
"gemini-configparser": "^1.0.0", | ||
"lodash": "^4.17.10" | ||
"lodash": "^4.17.10", | ||
"yargs-parser": "^18.1.3" | ||
}, | ||
@@ -33,4 +34,5 @@ "devDependencies": { | ||
"mocha": "^5.2.0", | ||
"proxyquire": "^2.1.3", | ||
"sinon": "^6.1.4" | ||
} | ||
} |
@@ -12,6 +12,11 @@ # hermione-test-filter | ||
## Configuration | ||
* `enabled` **[Boolean]** (optional, `false` by default) - enable/disable the plugin. | ||
* `inputFile` **[String]** (optional, `hermione-filter.json` by default) - path to file with tests to run. | ||
* `filterTestsByCode` **[String|RegExp|Function]** (optional, `null` by default) - filtering tests by their code and hooks. | ||
## Usage | ||
### With inputFile | ||
* Require plugin in your hermione config file: | ||
@@ -26,2 +31,3 @@ ```js | ||
``` | ||
* Input file format: | ||
@@ -36,1 +42,37 @@ ```json | ||
``` | ||
### With filterTestsByCode | ||
**Works only with hermione@>=3.5.0.** | ||
* Use plugin for filtering tests by their code: | ||
```js | ||
plugins: { | ||
'hermione-test-filter': { | ||
enabled: true, | ||
// run all tests with assertView | ||
filterTestsByCode: 'assertView', | ||
// or | ||
filterTestsByCode: (testSrc) => { | ||
return testSrc.includes('assertView'); | ||
} | ||
} | ||
} | ||
``` | ||
* Use plugin for filtering tests by their code from input file: | ||
```js | ||
plugins: { | ||
'hermione-test-filter': { | ||
enabled: true, | ||
// run all tests with assertView from input file | ||
inputFile: 'some/file.json', | ||
filterTestsByCode: 'assertView' | ||
} | ||
} | ||
``` | ||
* Run plugin with cli option for filtering tests by their code: | ||
``` | ||
npx hermione --filter-tests-by-code assertView | ||
``` |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
10224
7
169
76
4
8
+ Addedyargs-parser@^18.1.3
+ Addedcamelcase@5.3.1(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addedyargs-parser@18.1.3(transitive)