Plugins
The plugins allow to change behavior of TSTyche.
Usage
A plugin can be a package or a local module.
If you are publishing your plugin to npm, consider prefixing its name with tstyche-plugin-.
To specify a plugin, pass it with the --plugins command line option:
tstyche --plugins tstyche-plugin,./custom-plugin.jsOr use the plugins configuration option:
{
"plugins": ["tstyche-plugin", "./custom-plugin.js"]
}The Plugin
The plugin must export an object with the name property and implement one or more hooks:
/**
* @type {import("tstyche/tstyche").Plugin}
*/
export default {
name: "example-plugin",
config(resolvedConfig) {
return { ...resolvedConfig, testFileMatch: [] };
},
async select() {
return await getTestFilesSomehow(this.resolvedConfig);
},
};Properties
name
- Type:
string
The name of this plugin.
Hooks
The hooks are called with a particular value which can be modified or replaced with a new value.
config()
- Signature:
(resolvedConfig: ResolvedConfig) => ResolvedConfig
Is called after configuration is resolved and allows to modify it.
/**
* @type {import("tstyche/tstyche").Plugin}
*/
export default {
name: "modify-config",
config(resolvedConfig) {
return {
...resolvedConfig,
reporters: [new URL("./custom-reporter.js", import.meta.url).toString()],
testFileMatch: [] /* disables look up */,
};
},
};Use the --showConfig command line option to inspect the resolved configuration.
select()
- Signature:
(testFiles: Array<string>) => Array<string | URL> - Context:
this.resolvedConfig: ResolvedConfig
Is called after test files are selected and allows to modify the list.
/**
* @type {import("tstyche/tstyche").Plugin}
*/
export default {
name: "filter-test-files",
select(testFiles) {
return testFiles.filter((testFile) => !testFile.endsWith("toBeNumber.test.ts"));
},
};Use the --listFiles command line option to inspect the list of selected files.
Examples
Providing List of Test Files
For example, you can disable test file look up and provide own list of test files:
/**
* @type {import("tstyche/tstyche").Plugin}
*/
export default {
name: "provide-test-files",
config(resolvedConfig) {
return { ...resolvedConfig, testFileMatch: [] /* disables look up */ };
},
async select() {
// The resolved configuration is provided as a property of 'this' context
return await getTestFilesSomehow(this.resolvedConfig.rootPath);
},
};