Skip to content

Commit 65414d0

Browse files
committed
Improve testing skip features.
- Improve skip logging. - Add `skip` and `only` flags in manifests. - Add `VERBOSE_SKIP=true` env var to debug skipping.
1 parent a3c6626 commit 65414d0

File tree

4 files changed

+79
-21
lines changed

4 files changed

+79
-21
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
# jsonld ChangeLog
22

33
### Fixed
4-
- Use explicit id or description test skipping regexes.
4+
- Testing: Use explicit id and description skipping regexes.
5+
6+
### Changed
7+
- Testing: Improve skip logging.
8+
9+
### Added
10+
- Testing: `skip` and `only` flags in manifests.
11+
- Testing: `VERBOSE_SKIP=true` env var to debug skipping.
512

613
## 1.5.4 - 2019-02-28
714

tests/test-common.js

Lines changed: 65 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@ function _testsToMocha(tests) {
326326
}
327327
describe(suite.title, () => {
328328
suite.tests.forEach(test => {
329-
if(test.skip) {
330-
it.skip(test.title);
329+
if(test.only) {
330+
it.only(test.title, test.f);
331331
return;
332332
}
333333
it(test.title, test.f);
@@ -433,48 +433,89 @@ function addTest(manifest, test, tests) {
433433
test.manifest = manifest;
434434
const description = test_id + ' ' + (test.purpose || test.name);
435435

436-
tests.push({
436+
const _test = {
437437
title: description,
438438
f: makeFn()
439-
});
439+
};
440+
// only based on test manifest
441+
// skip handled via skip()
442+
if('only' in test) {
443+
_test.only = test.only;
444+
}
445+
tests.push(_test);
440446

441447
function makeFn() {
442448
return async function() {
443449
const self = this;
444450
self.timeout(5000);
445451
const testInfo = TEST_TYPES[getJsonLdTestType(test)];
446452

447-
// skip unknown and explicitly skipped test types
453+
// skip based on test manifest
454+
if('skip' in test && test.skip) {
455+
if(options.verboseSkip) {
456+
console.log('Skipping test due to manifest:',
457+
{id: test['@id'], name: test.name});
458+
}
459+
self.skip();
460+
}
461+
462+
// skip based on unknown test type
448463
const testTypes = Object.keys(TEST_TYPES);
449-
if(!isJsonLdType(test, testTypes) || isJsonLdType(test, SKIP_TESTS)) {
450-
//const type = [].concat(
451-
// getJsonLdValues(test, '@type'),
452-
// getJsonLdValues(test, 'type')
453-
//);
454-
//console.log('Skipping test "' + test.name + '" of type: ' + type);
464+
if(!isJsonLdType(test, testTypes)) {
465+
if(options.verboseSkip) {
466+
const type = [].concat(
467+
getJsonLdValues(test, '@type'),
468+
getJsonLdValues(test, 'type')
469+
);
470+
console.log('Skipping test due to unknown type:',
471+
{id: test['@id'], name: test.name, type});
472+
}
455473
self.skip();
456474
}
457475

476+
// skip based on test type
477+
if(isJsonLdType(test, SKIP_TESTS)) {
478+
if(options.verboseSkip) {
479+
const type = [].concat(
480+
getJsonLdValues(test, '@type'),
481+
getJsonLdValues(test, 'type')
482+
);
483+
console.log('Skipping test due to test type:',
484+
{id: test['@id'], name: test.name, type});
485+
}
486+
self.skip();
487+
}
488+
489+
// skip based on type info
458490
if(testInfo.skip && testInfo.skip.type) {
459-
//console.log('Skipping test "' + test.name + '" of type: ' + type);
491+
if(options.verboseSkip) {
492+
console.log('Skipping test due to type info:',
493+
{id: test['@id'], name: test.name});
494+
}
460495
self.skip();
461496
}
462497

498+
// skip based on id regex
463499
if(testInfo.skip && testInfo.skip.idRegex) {
464500
testInfo.skip.idRegex.forEach(function(re) {
465501
if(re.test(test['@id'])) {
466-
//console.log('Skipping test due to id:',
467-
// {id: test['@id']});
502+
if(options.verboseSkip) {
503+
console.log('Skipping test due to id:',
504+
{id: test['@id']});
505+
}
468506
self.skip();
469507
}
470508
});
471509
}
472510

511+
// skip based on description regex
473512
if(testInfo.skip && testInfo.skip.descriptionRegex) {
474513
testInfo.skip.descriptionRegex.forEach(function(re) {
475514
if(re.test(description)) {
476-
//console.log('Skipping test due to description:',
477-
// {id: test['@id'], name: test.name, description});
515+
if(options.verboseSkip) {
516+
console.log('Skipping test due to description:',
517+
{id: test['@id'], name: test.name, description});
518+
}
478519
self.skip();
479520
}
480521
});
@@ -490,8 +531,10 @@ function addTest(manifest, test, tests) {
490531
skipModes = testInfo.skip.processingMode;
491532
}
492533
if(skipModes.indexOf(pm) !== -1) {
493-
//console.log('Skipping test due to processingMode:',
494-
// {id: test['@id'], name: test.name, processingMode: pm});
534+
if(options.verboseSkip) {
535+
console.log('Skipping test due to processingMode:',
536+
{id: test['@id'], name: test.name, processingMode: pm});
537+
}
495538
self.skip();
496539
}
497540
});
@@ -505,8 +548,10 @@ function addTest(manifest, test, tests) {
505548
skipVersions = testInfo.skip.specVersion;
506549
}
507550
if(skipVersions.indexOf(sv) !== -1) {
508-
//console.log('Skipping test due to specVersion:',
509-
// {id: test['@id'], name: test.name, specVersion: sv});
551+
if(options.verboseSkip) {
552+
console.log('Skipping test due to specVersion:',
553+
{id: test['@id'], name: test.name, specVersion: sv});
554+
}
510555
self.skip();
511556
}
512557
});

tests/test-karma.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* EARL=filename
1010
* Bail with tests fail:
1111
* BAIL=true
12+
* Verbose skip reasons:
13+
* VERBOSE_SKIP=true
1214
* Benchmark mode:
1315
* Basic:
1416
* JSONLD_BENCHMARK=1
@@ -106,6 +108,7 @@ const options = {
106108
id: 'browser',
107109
filename: process.env.EARL
108110
},
111+
verboseSkip: process.env.VERBOSE_SKIP === 'true',
109112
bailOnError: process.env.BAIL === 'true',
110113
entries,
111114
benchmark,

tests/test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* EARL=filename
1010
* Bail with tests fail:
1111
* BAIL=true
12+
* Verbose skip reasons:
13+
* VERBOSE_SKIP=true
1214
* Benchmark mode:
1315
* Basic:
1416
* JSONLD_BENCHMARK=1
@@ -119,6 +121,7 @@ const options = {
119121
id: 'node.js',
120122
filename: process.env.EARL
121123
},
124+
verboseSkip: process.env.VERBOSE_SKIP === 'true',
122125
bailOnError: process.env.BAIL === 'true',
123126
entries,
124127
benchmark,

0 commit comments

Comments
 (0)