New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

hermione-test-filter

Package Overview
Dependencies
Maintainers
5
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hermione-test-filter - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

lib/test-code-collection.js

8

lib/config.js

@@ -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});

68

lib/index.js

@@ -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);
}
});
});
});
};

6

package.json
{
"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
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc