Skip to content

Commit 77f56cb

Browse files
PaulHaxfinetjul
authored andcommitted
chore(Testing): add VTKJS_TEST_PATTERN env var for filtering tests
Allows running a subset of tests by setting VTKJS_TEST_PATTERN: VTKJS_TEST_PATTERN=ConeSource npm test
1 parent 9d00695 commit 77f56cb

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

CONTRIBUTING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ To create and debug a test:
121121
- Run `npm run test:debug`
122122
- In the opened window, click the Debug button and place breakpoints in browser debugger.
123123

124+
To run a subset of tests matching a pattern:
125+
```sh
126+
$ VTKJS_TEST_PATTERN=ConeSource npm test
127+
```
128+
124129
## Updating Documentation
125130

126131
The vtk.js documentation is part of the code repository and is entirely written in

Sources/Testing/index.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,26 @@
33
* entrypoints into one chunk. This cuts down on extraneous
44
* code generation and addresses a race issue with the
55
* timer task queue.
6+
*
7+
* Optional filtering:
8+
* VTKJS_TEST_PATTERN=ConeSource npm test
9+
* VTKJS_TEST_PATTERN=Filters/Sources/ConeSource/test npm test
610
*/
711

12+
/* global __VTKJS_TEST_PATTERN__ */
13+
814
import './setupTestEnv';
915

1016
// webpack will include files that match the regex
1117
// '..' refers to the Sources/ dir
1218
const testsContext = require.context('..', true, /test[^/]+\.js$/);
13-
testsContext.keys().forEach(testsContext);
19+
20+
const testPattern =
21+
typeof __VTKJS_TEST_PATTERN__ !== 'undefined' ? __VTKJS_TEST_PATTERN__ : '';
22+
const testKeys = testsContext.keys();
23+
24+
if (testPattern) {
25+
testKeys.filter((key) => key.includes(testPattern)).forEach(testsContext);
26+
} else {
27+
testKeys.forEach(testsContext);
28+
}

karma.conf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ module.exports = function init(config) {
5858
new ESLintPlugin(),
5959
new webpack.DefinePlugin({
6060
__BASE_PATH__: "'/base'",
61+
__TEST_PATTERN__: JSON.stringify(process.env.VTKJS_TEST_PATTERN || ''),
6162
}),
6263
new webpack.ProvidePlugin({ process: ['process/browser'] }),
6364
],

0 commit comments

Comments
 (0)