Skip to content

Commit

Permalink
Experimental support for skip, closes #12
Browse files Browse the repository at this point in the history
  • Loading branch information
LeaVerou committed Mar 4, 2024
1 parent 07bd824 commit 47e6bda
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
5 changes: 5 additions & 0 deletions docs/define/js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ export default {
}
```

### Skipping tests: `skip`

You can set `skip: true` to skip a test.
The number of skipped tests will be shown separately.

### Example


Expand Down
21 changes: 19 additions & 2 deletions src/js/classes/TestResult.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ export default class TestResult extends BubblingEventTarget {
let originalTarget = e.detail?.target ?? e.target;

if (originalTarget.test.isTest) {
if (originalTarget.pass) {
if (originalTarget.test.skip) {
this.stats.skipped++;
}
else if (originalTarget.pass) {
this.stats.pass++;
}
else {
Expand Down Expand Up @@ -90,6 +93,7 @@ export default class TestResult extends BubblingEventTarget {
total: this.test.testCount,
totalTime: 0,
totalTimeAsync: 0,
skipped: 0,
};

this.stats.pending = this.stats.total;
Expand Down Expand Up @@ -123,7 +127,12 @@ export default class TestResult extends BubblingEventTarget {

delay(1).then(() => {
if (this.test.isTest) {
this.run();
if (this.test.skip) {
this.skip();
}
else {
this.run();
}
}

this.tests?.forEach(t => t.runAll());
Expand All @@ -148,6 +157,10 @@ export default class TestResult extends BubblingEventTarget {
this.dispatchEvent(new Event("done", {bubbles: true}));
}

skip () {
this.dispatchEvent(new Event("done", {bubbles: true}));
}

evaluateThrown () {
let test = this.test;
let ret = {pass: !!this.error, details: []};
Expand Down Expand Up @@ -284,6 +297,10 @@ ${ this.error.stack }`);
ret.push(`<b>${ stats.pending }</b>/${ stats.total } remaining`);
}

if (stats.skipped > 0) {
ret.push(`<dim><b>${ stats.skipped }</b>/${ stats.total } skipped</dim>`);
}

let icon = stats.fail > 0? "❌" : stats.pending > 0? "⏳" : "✅";
ret = [
`${this.name ?? (this.test.level === 0? "<i>(All tests)</i>" : "")}`,
Expand Down

0 comments on commit 47e6bda

Please sign in to comment.