| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0ef99de commit fd8be14
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -82,6 +82,7 @@ const kParentAlreadyFinished = 'parentAlreadyFinished'; | |||
| 82 | 82 | const kSubtestsFailed = 'subtestsFailed'; | |
| 83 | 83 | const kTestCodeFailure = 'testCodeFailure'; | |
| 84 | 84 | const kTestTimeoutFailure = 'testTimeoutFailure'; | |
| 85 | + const kExpectedFailure = 'expectedFailure'; | ||
| 85 | 86 | const kHookFailure = 'hookFailed'; | |
| 86 | 87 | const kDefaultTimeout = null; | |
| 87 | 88 | const noop = FunctionPrototype; | |
@@ -957,6 +958,14 @@ class Test extends AsyncResource { | |||
| 957 | 958 | } | |
| 958 | 959 | ||
| 959 | 960 | pass() { | |
| 961 | + if (this.error == null && this.expectFailure === true && !this.skipped) { | ||
| 962 | + this.passed = false; | ||
| 963 | + this.error = new ERR_TEST_FAILURE( | ||
| 964 | + 'test was expected to fail but passed', | ||
| 965 | + kExpectedFailure, | ||
| 966 | + ); | ||
| 967 | + return; | ||
| 968 | + } | ||
| 960 | 969 | if (this.error !== null) { | |
| 961 | 970 | return; | |
| 962 | 971 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,18 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const assert = require('node:assert'); | ||
| 4 | + const { run, test } = require('node:test'); | ||
| 5 | + | ||
| 6 | + if (!process.env.NODE_TEST_CONTEXT) { | ||
| 7 | + const stream = run({ files: [__filename] }); | ||
| 8 | + | ||
| 9 | + stream.on('test:pass', common.mustNotCall()); | ||
| 10 | + stream.on('test:fail', common.mustCall((event) => { | ||
| 11 | + assert.strictEqual(event.expectFailure, true); | ||
| 12 | + assert.strictEqual(event.details.error.code, 'ERR_TEST_FAILURE'); | ||
| 13 | + assert.strictEqual(event.details.error.failureType, 'expectedFailure'); | ||
| 14 | + assert.strictEqual(event.details.error.cause, 'test was expected to fail but passed'); | ||
| 15 | + }, 1)); | ||
| 16 | + } else { | ||
| 17 | + test('passing test', { expectFailure: true }, () => {}); | ||
| 18 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,15 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const assert = require('node:assert'); | ||
| 4 | + const { run, test } = require('node:test'); | ||
| 5 | + | ||
| 6 | + if (!process.env.NODE_TEST_CONTEXT) { | ||
| 7 | + const stream = run({ files: [__filename] }); | ||
| 8 | + | ||
| 9 | + stream.on('test:fail', common.mustNotCall()); | ||
| 10 | + stream.on('test:pass', common.mustCall((event) => { | ||
| 11 | + assert.strictEqual(event.expectFailure, true); | ||
| 12 | + }, 1)); | ||
| 13 | + } else { | ||
| 14 | + test('failing test', { expectFailure: true }, () => assert.fail('should not pass')); | ||
| 15 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments