GeezerVison is showing github.com — test: ensure assertions are reached on all tests · nodejs/node@8e9aded
File treeExpand file treeCollapse file tree Open diff view settings fixtures/test-runner/output
Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: test/eslint.config_partial.mjs +2-50Lines changed: 2 additions & 50 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -140,6 +140,7 @@ export default [ | 140 | 140 | ], | 141 | 141 | 'node-core/require-common-first': 'error', | 142 | 142 | 'node-core/no-duplicate-requires': 'off', | | 143 | + 'node-core/must-call-assert': 'error', | 143 | 144 | }, | 144 | 145 | }, | 145 | 146 | { | @@ -161,56 +162,6 @@ export default [ | 161 | 162 | ], | 162 | 163 | }, | 163 | 164 | }, | 164 | | - { | 165 | | - files: [ | 166 | | - `test/{${[ | 167 | | - 'abort', | 168 | | - 'addons', | 169 | | - 'async-hooks', | 170 | | - 'benchmark', | 171 | | - 'cctest', | 172 | | - 'client-proxy', | 173 | | - 'doctool', | 174 | | - 'embedding', | 175 | | - 'es-module', | 176 | | - 'fixtures', | 177 | | - 'fuzzers', | 178 | | - 'internet', | 179 | | - 'js-native-api', | 180 | | - 'known_issues', | 181 | | - 'message', | 182 | | - 'module-hooks', | 183 | | - 'node-api', | 184 | | - 'nop', | 185 | | - 'overlapped-checker', | 186 | | - 'pseudo-tty', | 187 | | - 'pummel', | 188 | | - 'report', | 189 | | - 'sea', | 190 | | - 'sequential', | 191 | | - 'sqlite', | 192 | | - 'system-ca', | 193 | | - 'test426', | 194 | | - 'testpy', | 195 | | - 'tick-processor', | 196 | | - 'tools', | 197 | | - 'v8-updates', | 198 | | - 'wasi', | 199 | | - 'wasm-allocation', | 200 | | - 'wpt', | 201 | | - ].join(',')}}/**/*.{js,mjs,cjs}`, | 202 | | - `test/parallel/test-{${ | 203 | | - // 0x61 is code for 'a', this generates a string enumerating latin letters: 'a*,b*,…' | 204 | | - Array.from({ length: 13 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',') | 205 | | - },n*,r*,${ | 206 | | - // 0x61 is code for 'a', this generates a string enumerating latin letters: 'z*,y*,…' | 207 | | - Array.from({ length: 8 }, (_, i) => String.fromCharCode(0x61 + 25 - i, 42)).join(',') | 208 | | - }}.{js,mjs,cjs}`, | 209 | | - ], | 210 | | - rules: { | 211 | | - 'node-core/must-call-assert': 'error', | 212 | | - }, | 213 | | - }, | 214 | 165 | { | 215 | 166 | files: [ | 216 | 167 | 'test/{common,fixtures,wpt}/**/*.{js,mjs,cjs}', | @@ -219,6 +170,7 @@ export default [ | 219 | 170 | rules: { | 220 | 171 | 'node-core/required-modules': 'off', | 221 | 172 | 'node-core/require-common-first': 'off', | | 173 | + 'node-core/must-call-assert': 'off', | 222 | 174 | }, | 223 | 175 | }, | 224 | 176 | { | |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/test-runner/output/hooks-with-no-global-test.js -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -9,7 +9,6 @@ before(() => testArr.push('global before')); | 9 | 9 | after(() => { | 10 | 10 | testArr.push('global after'); | 11 | 11 |
| 12 | | - // eslint-disable-next-line node-core/must-call-assert | 13 | 12 | assert.deepStrictEqual(testArr, [ | 14 | 13 | 'global before', | 15 | 14 | 'describe before', | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-os.js +13-15Lines changed: 13 additions & 15 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -27,16 +27,16 @@ const path = require('path'); | 27 | 27 | const { inspect } = require('util'); | 28 | 28 |
| 29 | 29 | const is = { | 30 | | - number: (value, key) => { | | 30 | + number: common.mustCallAtLeast((value, key) => { | 31 | 31 | assert(!Number.isNaN(value), `${key} should not be NaN`); | 32 | 32 | assert.strictEqual(typeof value, 'number'); | 33 | | - }, | 34 | | - string: (value) => { assert.strictEqual(typeof value, 'string'); }, | 35 | | - array: (value) => { assert.ok(Array.isArray(value)); }, | 36 | | - object: (value) => { | | 33 | + }), | | 34 | + string: common.mustCallAtLeast((value) => { assert.strictEqual(typeof value, 'string'); }), | | 35 | + array: common.mustCallAtLeast((value) => { assert.ok(Array.isArray(value)); }), | | 36 | + object: common.mustCallAtLeast((value) => { | 37 | 37 | assert.strictEqual(typeof value, 'object'); | 38 | 38 | assert.notStrictEqual(value, null); | 39 | | - } | | 39 | + }), | 40 | 40 | }; | 41 | 41 |
| 42 | 42 | process.env.TMPDIR = '/tmpdir'; | @@ -181,15 +181,13 @@ const netmaskToCIDRSuffixMap = new Map(Object.entries({ | 181 | 181 | 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff': 128 | 182 | 182 | })); | 183 | 183 |
| 184 | | -Object.values(interfaces) | 185 | | - .flat(Infinity) | 186 | | - .map((v) => ({ v, mask: netmaskToCIDRSuffixMap.get(v.netmask) })) | 187 | | - .forEach(({ v, mask }) => { | 188 | | - assert.ok('cidr' in v, `"cidr" prop not found in ${inspect(v)}`); | 189 | | - if (mask) { | 190 | | - assert.strictEqual(v.cidr, `${v.address}/${mask}`); | 191 | | - } | 192 | | - }); | | 184 | +for (const v of Object.values(interfaces).flat(Infinity)) { | | 185 | + assert.ok('cidr' in v, `"cidr" prop not found in ${inspect(v)}`); | | 186 | + const mask = netmaskToCIDRSuffixMap.get(v.netmask); | | 187 | + if (mask) { | | 188 | + assert.strictEqual(v.cidr, `${v.address}/${mask}`); | | 189 | + } | | 190 | +} | 193 | 191 |
| 194 | 192 | const EOL = os.EOL; | 195 | 193 | if (common.isWindows) { | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-perf-hooks-histogram.js +53-58Lines changed: 53 additions & 58 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 |
| 3 | 3 | const common = require('../common'); | 4 | 4 |
| 5 | | -const { | 6 | | - deepStrictEqual, | 7 | | - ok, | 8 | | - strictEqual, | 9 | | - throws, | 10 | | -} = require('assert'); | | 5 | +const assert = require('assert'); | 11 | 6 |
| 12 | 7 | const { | 13 | 8 | createHistogram, | @@ -19,64 +14,64 @@ const { inspect } = require('util'); | 19 | 14 | { | 20 | 15 | const h = createHistogram(); | 21 | 16 |
| 22 | | - strictEqual(h.min, 9223372036854776000); | 23 | | - strictEqual(h.minBigInt, 9223372036854775807n); | 24 | | - strictEqual(h.max, 0); | 25 | | - strictEqual(h.maxBigInt, 0n); | 26 | | - strictEqual(h.exceeds, 0); | 27 | | - strictEqual(h.exceedsBigInt, 0n); | 28 | | - ok(Number.isNaN(h.mean)); | 29 | | - ok(Number.isNaN(h.stddev)); | | 17 | + assert.strictEqual(h.min, 9223372036854776000); | | 18 | + assert.strictEqual(h.minBigInt, 9223372036854775807n); | | 19 | + assert.strictEqual(h.max, 0); | | 20 | + assert.strictEqual(h.maxBigInt, 0n); | | 21 | + assert.strictEqual(h.exceeds, 0); | | 22 | + assert.strictEqual(h.exceedsBigInt, 0n); | | 23 | + assert.ok(Number.isNaN(h.mean)); | | 24 | + assert.ok(Number.isNaN(h.stddev)); | 30 | 25 |
| 31 | | - strictEqual(h.count, 0); | 32 | | - strictEqual(h.countBigInt, 0n); | | 26 | + assert.strictEqual(h.count, 0); | | 27 | + assert.strictEqual(h.countBigInt, 0n); | 33 | 28 |
| 34 | 29 | h.record(1); | 35 | 30 |
| 36 | | - strictEqual(h.count, 1); | 37 | | - strictEqual(h.countBigInt, 1n); | | 31 | + assert.strictEqual(h.count, 1); | | 32 | + assert.strictEqual(h.countBigInt, 1n); | 38 | 33 |
| 39 | 34 | [false, '', {}, undefined, null].forEach((i) => { | 40 | | - throws(() => h.record(i), { | | 35 | + assert.throws(() => h.record(i), { | 41 | 36 | code: 'ERR_INVALID_ARG_TYPE' | 42 | 37 | }); | 43 | 38 | }); | 44 | 39 | [0, Number.MAX_SAFE_INTEGER + 1].forEach((i) => { | 45 | | - throws(() => h.record(i), { | | 40 | + assert.throws(() => h.record(i), { | 46 | 41 | code: 'ERR_OUT_OF_RANGE' | 47 | 42 | }); | 48 | 43 | }); | 49 | 44 |
| 50 | | - strictEqual(h.min, 1); | 51 | | - strictEqual(h.minBigInt, 1n); | 52 | | - strictEqual(h.max, 1); | 53 | | - strictEqual(h.maxBigInt, 1n); | 54 | | - strictEqual(h.exceeds, 0); | 55 | | - strictEqual(h.mean, 1); | 56 | | - strictEqual(h.stddev, 0); | | 45 | + assert.strictEqual(h.min, 1); | | 46 | + assert.strictEqual(h.minBigInt, 1n); | | 47 | + assert.strictEqual(h.max, 1); | | 48 | + assert.strictEqual(h.maxBigInt, 1n); | | 49 | + assert.strictEqual(h.exceeds, 0); | | 50 | + assert.strictEqual(h.mean, 1); | | 51 | + assert.strictEqual(h.stddev, 0); | 57 | 52 |
| 58 | | - strictEqual(h.percentile(1), 1); | 59 | | - strictEqual(h.percentile(100), 1); | | 53 | + assert.strictEqual(h.percentile(1), 1); | | 54 | + assert.strictEqual(h.percentile(100), 1); | 60 | 55 |
| 61 | | - strictEqual(h.percentileBigInt(1), 1n); | 62 | | - strictEqual(h.percentileBigInt(100), 1n); | | 56 | + assert.strictEqual(h.percentileBigInt(1), 1n); | | 57 | + assert.strictEqual(h.percentileBigInt(100), 1n); | 63 | 58 |
| 64 | | - deepStrictEqual(h.percentiles, new Map([[0, 1], [100, 1]])); | | 59 | + assert.deepStrictEqual(h.percentiles, new Map([[0, 1], [100, 1]])); | 65 | 60 |
| 66 | | - deepStrictEqual(h.percentilesBigInt, new Map([[0, 1n], [100, 1n]])); | | 61 | + assert.deepStrictEqual(h.percentilesBigInt, new Map([[0, 1n], [100, 1n]])); | 67 | 62 |
| 68 | 63 | const mc = new MessageChannel(); | 69 | 64 | mc.port1.onmessage = common.mustCall(({ data }) => { | 70 | | - strictEqual(h.min, 1); | 71 | | - strictEqual(h.max, 1); | 72 | | - strictEqual(h.exceeds, 0); | 73 | | - strictEqual(h.mean, 1); | 74 | | - strictEqual(h.stddev, 0); | | 65 | + assert.strictEqual(h.min, 1); | | 66 | + assert.strictEqual(h.max, 1); | | 67 | + assert.strictEqual(h.exceeds, 0); | | 68 | + assert.strictEqual(h.mean, 1); | | 69 | + assert.strictEqual(h.stddev, 0); | 75 | 70 |
| 76 | 71 | data.record(2n); | 77 | 72 | data.recordDelta(); | 78 | 73 |
| 79 | | - strictEqual(h.max, 2); | | 74 | + assert.strictEqual(h.max, 2); | 80 | 75 |
| 81 | 76 | mc.port1.close(); | 82 | 77 | }); | @@ -85,15 +80,15 @@ const { inspect } = require('util'); | 85 | 80 |
| 86 | 81 | { | 87 | 82 | const e = monitorEventLoopDelay(); | 88 | | - strictEqual(e.count, 0); | | 83 | + assert.strictEqual(e.count, 0); | 89 | 84 | e.enable(); | 90 | 85 | const mc = new MessageChannel(); | 91 | 86 | mc.port1.onmessage = common.mustCall(({ data }) => { | 92 | | - strictEqual(typeof data.min, 'number'); | 93 | | - ok(data.min > 0); | 94 | | - ok(data.count > 0); | 95 | | - strictEqual(data.disable, undefined); | 96 | | - strictEqual(data.enable, undefined); | | 87 | + assert.strictEqual(typeof data.min, 'number'); | | 88 | + assert.ok(data.min > 0); | | 89 | + assert.ok(data.count > 0); | | 90 | + assert.strictEqual(data.disable, undefined); | | 91 | + assert.strictEqual(data.enable, undefined); | 97 | 92 | mc.port1.close(); | 98 | 93 | }); | 99 | 94 | const interval = setInterval(() => { | @@ -112,19 +107,19 @@ const { inspect } = require('util'); | 112 | 107 | histogram = hi; | 113 | 108 | } | 114 | 109 | // The histogram should already be disabled. | 115 | | - strictEqual(histogram.disable(), false); | | 110 | + assert.strictEqual(histogram.disable(), false); | 116 | 111 | } | 117 | 112 |
| 118 | 113 | { | 119 | 114 | const h = createHistogram(); | 120 | | - ok(inspect(h, { depth: null }).startsWith('Histogram')); | 121 | | - strictEqual(inspect(h, { depth: -1 }), '[RecordableHistogram]'); | | 115 | + assert.ok(inspect(h, { depth: null }).startsWith('Histogram')); | | 116 | + assert.strictEqual(inspect(h, { depth: -1 }), '[RecordableHistogram]'); | 122 | 117 | } | 123 | 118 |
| 124 | 119 | { | 125 | 120 | // Tests that RecordableHistogram is impossible to construct manually | 126 | 121 | const h = createHistogram(); | 127 | | - throws(() => new h.constructor(), { code: 'ERR_ILLEGAL_CONSTRUCTOR' }); | | 122 | + assert.throws(() => new h.constructor(), { code: 'ERR_ILLEGAL_CONSTRUCTOR' }); | 128 | 123 | } | 129 | 124 |
| 130 | 125 | { | @@ -133,7 +128,7 @@ const { inspect } = require('util'); | 133 | 128 | 1, | 134 | 129 | null, | 135 | 130 | ].forEach((i) => { | 136 | | - throws(() => createHistogram(i), { code: 'ERR_INVALID_ARG_TYPE' }); | | 131 | + assert.throws(() => createHistogram(i), { code: 'ERR_INVALID_ARG_TYPE' }); | 137 | 132 | }); | 138 | 133 |
| 139 | 134 | [ | @@ -142,20 +137,20 @@ const { inspect } = require('util'); | 142 | 137 | null, | 143 | 138 | {}, | 144 | 139 | ].forEach((i) => { | 145 | | - throws(() => createHistogram({ lowest: i }), { | | 140 | + assert.throws(() => createHistogram({ lowest: i }), { | 146 | 141 | code: 'ERR_INVALID_ARG_TYPE', | 147 | 142 | }); | 148 | | - throws(() => createHistogram({ highest: i }), { | | 143 | + assert.throws(() => createHistogram({ highest: i }), { | 149 | 144 | code: 'ERR_INVALID_ARG_TYPE', | 150 | 145 | }); | 151 | | - throws(() => createHistogram({ figures: i }), { | | 146 | + assert.throws(() => createHistogram({ figures: i }), { | 152 | 147 | code: 'ERR_INVALID_ARG_TYPE', | 153 | 148 | }); | 154 | 149 | }); | 155 | 150 |
| 156 | 151 | // Number greater than 5 is not allowed | 157 | 152 | for (const i of [6, 10]) { | 158 | | - throws(() => createHistogram({ figures: i }), { | | 153 | + assert.throws(() => createHistogram({ figures: i }), { | 159 | 154 | code: 'ERR_OUT_OF_RANGE', | 160 | 155 | }); | 161 | 156 | } | @@ -169,20 +164,20 @@ const { inspect } = require('util'); | 169 | 164 |
| 170 | 165 | h1.record(1); | 171 | 166 |
| 172 | | - strictEqual(h2.count, 0); | 173 | | - strictEqual(h1.count, 1); | | 167 | + assert.strictEqual(h2.count, 0); | | 168 | + assert.strictEqual(h1.count, 1); | 174 | 169 |
| 175 | 170 | h2.add(h1); | 176 | 171 |
| 177 | | - strictEqual(h2.count, 1); | | 172 | + assert.strictEqual(h2.count, 1); | 178 | 173 |
| 179 | 174 | [ | 180 | 175 | 'hello', | 181 | 176 | 1, | 182 | 177 | false, | 183 | 178 | {}, | 184 | 179 | ].forEach((i) => { | 185 | | - throws(() => h1.add(i), { | | 180 | + assert.throws(() => h1.add(i), { | 186 | 181 | code: 'ERR_INVALID_ARG_TYPE', | 187 | 182 | }); | 188 | 183 | }); | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-performance-gc.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -48,9 +48,9 @@ const kinds = [ | 48 | 48 | // GC should not keep the event loop alive | 49 | 49 | { | 50 | 50 | let didCall = false; | 51 | | - process.on('beforeExit', () => { | | 51 | + process.on('beforeExit', common.mustCall(() => { | 52 | 52 | assert(!didCall); | 53 | 53 | didCall = true; | 54 | 54 | globalThis.gc(); | 55 | | - }); | | 55 | + })); | 56 | 56 | } |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-performance-global.js +4-6Lines changed: 4 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | require('../common'); | 5 | 5 |
| 6 | 6 | const perf_hooks = require('perf_hooks'); | 7 | | -const { | 8 | | - strictEqual | 9 | | -} = require('assert'); | | 7 | +const assert = require('assert'); | 10 | 8 |
| 11 | 9 | const perf = performance; | 12 | | -strictEqual(globalThis.performance, perf_hooks.performance); | | 10 | +assert.strictEqual(globalThis.performance, perf_hooks.performance); | 13 | 11 | performance = undefined; | 14 | | -strictEqual(globalThis.performance, undefined); | 15 | | -strictEqual(typeof perf_hooks.performance.now, 'function'); | | 12 | +assert.strictEqual(globalThis.performance, undefined); | | 13 | +assert.strictEqual(typeof perf_hooks.performance.now, 'function'); | 16 | 14 |
| 17 | 15 | // Restore the value of performance for the known globals check | 18 | 16 | performance = perf; |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-performance-measure.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -9,10 +9,10 @@ const ALLOWED_MARGIN = 10; | 9 | 9 |
| 10 | 10 | const expected = ['Start to Now', 'A to Now', 'A to B']; | 11 | 11 | const obs = new PerformanceObserver(common.mustCall((items) => { | 12 | | - items.getEntries().forEach(({ name, duration }) => { | | 12 | + for (const { name, duration } of items.getEntries()) { | 13 | 13 | assert.ok(duration > (DELAY - ALLOWED_MARGIN)); | 14 | 14 | assert.strictEqual(expected.shift(), name); | 15 | | - }); | | 15 | + } | 16 | 16 | })); | 17 | 17 | obs.observe({ entryTypes: ['measure'] }); | 18 | 18 |
| |
|