| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ef174ea commit ddf7518
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -75,15 +75,14 @@ function setup(root) { | |||
| 75 | 75 | const rejectionHandler = | |
| 76 | 76 | createProcessEventHandler('unhandledRejection', root); | |
| 77 | 77 | ||
| 78 | - process.on('uncaughtException', exceptionHandler); | ||
| 79 | - process.on('unhandledRejection', rejectionHandler); | ||
| 80 | - process.on('beforeExit', () => { | ||
| 78 | + const exitHandler = () => { | ||
| 81 | 79 | root.postRun(); | |
| 82 | 80 | ||
| 83 | 81 | let passCount = 0; | |
| 84 | 82 | let failCount = 0; | |
| 85 | 83 | let skipCount = 0; | |
| 86 | 84 | let todoCount = 0; | |
| 85 | + let cancelledCount = 0; | ||
| 87 | 86 | ||
| 88 | 87 | for (let i = 0; i < root.subtests.length; i++) { | |
| 89 | 88 | const test = root.subtests[i]; | |
@@ -94,6 +93,8 @@ function setup(root) { | |||
| 94 | 93 | skipCount++; | |
| 95 | 94 | } else if (test.isTodo) { | |
| 96 | 95 | todoCount++; | |
| 96 | + } else if (test.cancelled) { | ||
| 97 | + cancelledCount++; | ||
| 97 | 98 | } else if (!test.passed) { | |
| 98 | 99 | failCount++; | |
| 99 | 100 | } else { | |
@@ -110,6 +111,7 @@ function setup(root) { | |||
| 110 | 111 | root.reporter.diagnostic(root.indent, `tests ${root.subtests.length}`); | |
| 111 | 112 | root.reporter.diagnostic(root.indent, `pass ${passCount}`); | |
| 112 | 113 | root.reporter.diagnostic(root.indent, `fail ${failCount}`); | |
| 114 | + root.reporter.diagnostic(root.indent, `cancelled ${cancelledCount}`); | ||
| 113 | 115 | root.reporter.diagnostic(root.indent, `skipped ${skipCount}`); | |
| 114 | 116 | root.reporter.diagnostic(root.indent, `todo ${todoCount}`); | |
| 115 | 117 | root.reporter.diagnostic(root.indent, `duration_ms ${process.uptime()}`); | |
@@ -119,10 +121,21 @@ function setup(root) { | |||
| 119 | 121 | process.removeListener('unhandledRejection', rejectionHandler); | |
| 120 | 122 | process.removeListener('uncaughtException', exceptionHandler); | |
| 121 | 123 | ||
| 122 | - if (failCount > 0) { | ||
| 124 | + if (failCount > 0 || cancelledCount > 0) { | ||
| 123 | 125 | process.exitCode = 1; | |
| 124 | 126 | } | |
| 125 | - }); | ||
| 127 | + }; | ||
| 128 | + | ||
| 129 | + const terminationHandler = () => { | ||
| 130 | + exitHandler(); | ||
| 131 | + process.exit(); | ||
| 132 | + }; | ||
| 133 | + | ||
| 134 | + process.on('uncaughtException', exceptionHandler); | ||
| 135 | + process.on('unhandledRejection', rejectionHandler); | ||
| 136 | + process.on('beforeExit', exitHandler); | ||
| 137 | + process.on('SIGINT', terminationHandler); | ||
| 138 | + process.on('SIGTERM', terminationHandler); | ||
| 126 | 139 | ||
| 127 | 140 | root.reporter.pipe(process.stdout); | |
| 128 | 141 | root.reporter.version(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -509,6 +509,7 @@ not ok 54 - invalid subtest fail | |||
| 509 | 509 | # tests 54 | |
| 510 | 510 | # pass 23 | |
| 511 | 511 | # fail 17 | |
| 512 | + # cancelled 0 | ||
| 512 | 513 | # skipped 9 | |
| 513 | 514 | # todo 5 | |
| 514 | 515 | # duration_ms * | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,7 +23,8 @@ not ok 1 - does not keep event loop alive | |||
| 23 | 23 | 1..1 | |
| 24 | 24 | # tests 1 | |
| 25 | 25 | # pass 0 | |
| 26 | - # fail 1 | ||
| 26 | + # fail 0 | ||
| 27 | + # cancelled 1 | ||
| 27 | 28 | # skipped 0 | |
| 28 | 29 | # todo 0 | |
| 29 | 30 | # duration_ms * | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -120,6 +120,7 @@ ok 11 - only = true, with subtests | |||
| 120 | 120 | # tests 11 | |
| 121 | 121 | # pass 1 | |
| 122 | 122 | # fail 0 | |
| 123 | + # cancelled 0 | ||
| 123 | 124 | # skipped 10 | |
| 124 | 125 | # todo 0 | |
| 125 | 126 | # duration_ms * | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -582,6 +582,7 @@ not ok 57 - invalid subtest fail | |||
| 582 | 582 | # tests 57 | |
| 583 | 583 | # pass 24 | |
| 584 | 584 | # fail 18 | |
| 585 | + # cancelled 0 | ||
| 585 | 586 | # skipped 10 | |
| 586 | 587 | # todo 5 | |
| 587 | 588 | # duration_ms * | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,7 +27,8 @@ not ok 3 - fail | |||
| 27 | 27 | 1..3 | |
| 28 | 28 | # tests 3 | |
| 29 | 29 | # pass 1 | |
| 30 | - # fail 2 | ||
| 30 | + # fail 0 | ||
| 31 | + # cancelled 2 | ||
| 31 | 32 | # skipped 0 | |
| 32 | 33 | # todo 0 | |
| 33 | 34 | # duration_ms * | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,8 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - require('../common'); | ||
| 2 | + const common = require('../common'); | ||
| 3 | 3 | const assert = require('assert'); | |
| 4 | 4 | const { spawnSync } = require('child_process'); | |
| 5 | + const { setTimeout } = require('timers/promises'); | ||
| 5 | 6 | ||
| 6 | 7 | if (process.argv[2] === 'child') { | |
| 7 | 8 | const test = require('node:test'); | |
@@ -10,12 +11,18 @@ if (process.argv[2] === 'child') { | |||
| 10 | 11 | test('passing test', () => { | |
| 11 | 12 | assert.strictEqual(true, true); | |
| 12 | 13 | }); | |
| 13 | - } else { | ||
| 14 | + } else if (process.argv[3] === 'fail') { | ||
| 14 | 15 | assert.strictEqual(process.argv[3], 'fail'); | |
| 15 | 16 | test('failing test', () => { | |
| 16 | 17 | assert.strictEqual(true, false); | |
| 17 | 18 | }); | |
| 18 | - } | ||
| 19 | + } else if (process.argv[3] === 'never_ends') { | ||
| 20 | + assert.strictEqual(process.argv[3], 'never_ends'); | ||
| 21 | + test('never ending test', () => { | ||
| 22 | + return setTimeout(100_000_000); | ||
| 23 | + }); | ||
| 24 | + process.kill(process.pid, 'SIGINT'); | ||
| 25 | + } else assert.fail('unreachable'); | ||
| 19 | 26 | } else { | |
| 20 | 27 | let child = spawnSync(process.execPath, [__filename, 'child', 'pass']); | |
| 21 | 28 | assert.strictEqual(child.status, 0); | |
@@ -24,4 +31,15 @@ if (process.argv[2] === 'child') { | |||
| 24 | 31 | child = spawnSync(process.execPath, [__filename, 'child', 'fail']); | |
| 25 | 32 | assert.strictEqual(child.status, 1); | |
| 26 | 33 | assert.strictEqual(child.signal, null); | |
| 34 | + | ||
| 35 | + child = spawnSync(process.execPath, [__filename, 'child', 'never_ends']); | ||
| 36 | + assert.strictEqual(child.status, 1); | ||
| 37 | + assert.strictEqual(child.signal, null); | ||
| 38 | + if (common.isWindows) { | ||
| 39 | + common.printSkipMessage('signals are not supported in windows'); | ||
| 40 | + } else { | ||
| 41 | + const stdout = child.stdout.toString(); | ||
| 42 | + assert.match(stdout, /not ok 1 - never ending test/); | ||
| 43 | + assert.match(stdout, /# cancelled 1/); | ||
| 44 | + } | ||
| 27 | 45 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments