Skip to content

Commit 1393fa1

Browse files
committed
testing: allow negative indexes for valid/invalid
1 parent dfa9b23 commit 1393fa1

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ flag passed to `test-index`, e.g., for `check-examples` and `require-example`:
5858
`npm run --rule=check-examples,require-example test-index`.
5959

6060
You can further limit this by providing `--invalid` and/or `--valid` flags
61-
with a comma-separated list of 0-based indexes that you wish to include. For
61+
with a comma-separated list of 0-based indexes that you wish to include (also
62+
accepts negative offsets from the end, e.g., `-1` for the last item). For
6263
example, to check the first and third invalid tests of `check-examples`
6364
alon with the second valid test, you can run:
6465

test/rules/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ const ruleTester = new RuleTester();
5858
if (process.env.npm_config_invalid) {
5959
const indexes = process.env.npm_config_invalid.split(',');
6060
assertions.invalid = assertions.invalid.filter((assertion, idx) => {
61-
return indexes.includes(String(idx));
61+
return indexes.includes(String(idx)) ||
62+
indexes.includes(String(idx - assertions.invalid.length));
6263
});
6364
if (!process.env.npm_config_valid) {
6465
assertions.valid = [];
@@ -67,7 +68,8 @@ const ruleTester = new RuleTester();
6768
if (process.env.npm_config_valid) {
6869
const indexes = process.env.npm_config_valid.split(',');
6970
assertions.valid = assertions.valid.filter((assertion, idx) => {
70-
return indexes.includes(String(idx));
71+
return indexes.includes(String(idx)) ||
72+
indexes.includes(String(idx - assertions.valid.length));
7173
});
7274
if (!process.env.npm_config_invalid) {
7375
assertions.invalid = [];

0 commit comments

Comments
 (0)