| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,6 +17,6 @@ async_hooks.createHook({ | |||
| 17 | 17 | }), | |
| 18 | 18 | }).enable(); | |
| 19 | 19 | ||
| 20 | - runInCallbackScope({}, 1000, 1000, () => { | ||
| 20 | + runInCallbackScope({}, 1000, 1000, common.mustCallAtLeast(() => { | ||
| 21 | 21 | assert(insideHook); | |
| 22 | - }); | ||
| 22 | + })); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,4 +9,4 @@ const { testResolveAsync } = require(`./build/${common.buildType}/binding`); | |||
| 9 | 9 | let called = false; | |
| 10 | 10 | testResolveAsync().then(() => { called = true; }); | |
| 11 | 11 | ||
| 12 | - process.on('beforeExit', () => { assert(called); }); | ||
| 12 | + process.on('beforeExit', common.mustCall(() => { assert(called); })); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,13 +9,13 @@ const server = http.createServer((req, res) => { | |||
| 9 | 9 | res.end('ok'); | |
| 10 | 10 | }); | |
| 11 | 11 | ||
| 12 | - server.listen(0, () => { | ||
| 13 | - asyncLocalStorage.run(new Map(), () => { | ||
| 12 | + server.listen(0, mustCall(() => { | ||
| 13 | + asyncLocalStorage.run(new Map(), mustCall(() => { | ||
| 14 | 14 | const store = asyncLocalStorage.getStore(); | |
| 15 | 15 | store.set('hello', 'world'); | |
| 16 | 16 | http.get({ host: 'localhost', port: server.address().port }, mustCall(() => { | |
| 17 | 17 | assert.strictEqual(asyncLocalStorage.getStore().get('hello'), 'world'); | |
| 18 | 18 | server.close(); | |
| 19 | 19 | })); | |
| 20 | - }); | ||
| 21 | - }); | ||
| 20 | + })); | ||
| 21 | + })); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -193,7 +193,7 @@ export default [ | |||
| 193 | 193 | ].join(',')}}/**/*.{js,mjs,cjs}`, | |
| 194 | 194 | `test/parallel/test-{${ | |
| 195 | 195 | // 0x61 is code for 'a', this generates a string enumerating latin letters: 'a*,b*,…' | |
| 196 | - Array.from({ length: 3 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',') | ||
| 196 | + Array.from({ length: 4 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',') | ||
| 197 | 197 | },${ | |
| 198 | 198 | // 0x61 is code for 'a', this generates a string enumerating latin letters: 'z*,y*,…' | |
| 199 | 199 | Array.from({ length: 2 }, (_, i) => String.fromCharCode(0x61 + 25 - i, 42)).join(',') | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,11 +15,11 @@ const { cjs, esm } = require('../fixtures/es-modules/custom-condition/load.cjs') | |||
| 15 | 15 | // allow a CJS to be resolved with that condition. | |
| 16 | 16 | { | |
| 17 | 17 | const hooks = registerHooks({ | |
| 18 | - resolve(specifier, context, nextResolve) { | ||
| 18 | + resolve: common.mustCall((specifier, context, nextResolve) => { | ||
| 19 | 19 | assert(Array.isArray(context.conditions)); | |
| 20 | 20 | context.conditions = ['foo', ...context.conditions]; | |
| 21 | 21 | return nextResolve(specifier, context); | |
| 22 | - }, | ||
| 22 | + }, 2), | ||
| 23 | 23 | }); | |
| 24 | 24 | assert.strictEqual(cjs('foo/second').result, 'foo'); | |
| 25 | 25 | assert.strictEqual((await esm('foo/second')).result, 'foo'); | |
@@ -30,11 +30,11 @@ const { cjs, esm } = require('../fixtures/es-modules/custom-condition/load.cjs') | |||
| 30 | 30 | // allow a ESM to be resolved with that condition. | |
| 31 | 31 | { | |
| 32 | 32 | const hooks = registerHooks({ | |
| 33 | - resolve(specifier, context, nextResolve) { | ||
| 33 | + resolve: common.mustCall((specifier, context, nextResolve) => { | ||
| 34 | 34 | assert(Array.isArray(context.conditions)); | |
| 35 | 35 | context.conditions = ['foo-esm', ...context.conditions]; | |
| 36 | 36 | return nextResolve(specifier, context); | |
| 37 | - }, | ||
| 37 | + }, 2), | ||
| 38 | 38 | }); | |
| 39 | 39 | assert.strictEqual(cjs('foo/third').result, 'foo-esm'); | |
| 40 | 40 | assert.strictEqual((await esm('foo/third')).result, 'foo-esm'); | |
@@ -44,11 +44,11 @@ const { cjs, esm } = require('../fixtures/es-modules/custom-condition/load.cjs') | |||
| 44 | 44 | // Duplicating the 'foo' condition in the resolve hook should not change the result. | |
| 45 | 45 | { | |
| 46 | 46 | const hooks = registerHooks({ | |
| 47 | - resolve(specifier, context, nextResolve) { | ||
| 47 | + resolve: common.mustCall((specifier, context, nextResolve) => { | ||
| 48 | 48 | assert(Array.isArray(context.conditions)); | |
| 49 | 49 | context.conditions = ['foo', ...context.conditions, 'foo']; | |
| 50 | 50 | return nextResolve(specifier, context); | |
| 51 | - }, | ||
| 51 | + }, 2), | ||
| 52 | 52 | }); | |
| 53 | 53 | assert.strictEqual(cjs('foo/fourth').result, 'foo'); | |
| 54 | 54 | assert.strictEqual((await esm('foo/fourth')).result, 'foo'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,5 @@ | |||
| 1 | 1 | // This tests that custom conditions can be used in module resolution hooks. | |
| 2 | - import '../common/index.mjs'; | ||
| 2 | + import * as common from '../common/index.mjs'; | ||
| 3 | 3 | import { registerHooks } from 'node:module'; | |
| 4 | 4 | import assert from 'node:assert'; | |
| 5 | 5 | import { cjs, esm } from '../fixtures/es-modules/custom-condition/load.cjs'; | |
@@ -12,11 +12,11 @@ assert.strictEqual((await esm('foo')).result, 'default'); | |||
| 12 | 12 | // allow a CJS to be resolved with that condition. | |
| 13 | 13 | { | |
| 14 | 14 | const hooks = registerHooks({ | |
| 15 | - resolve(specifier, context, nextResolve) { | ||
| 15 | + resolve: common.mustCall((specifier, context, nextResolve) => { | ||
| 16 | 16 | assert(Array.isArray(context.conditions)); | |
| 17 | 17 | context.conditions = ['foo', ...context.conditions]; | |
| 18 | 18 | return nextResolve(specifier, context); | |
| 19 | - }, | ||
| 19 | + }, 2), | ||
| 20 | 20 | }); | |
| 21 | 21 | assert.strictEqual(cjs('foo/second').result, 'foo'); | |
| 22 | 22 | assert.strictEqual((await esm('foo/second')).result, 'foo'); | |
@@ -27,11 +27,11 @@ assert.strictEqual((await esm('foo')).result, 'default'); | |||
| 27 | 27 | // allow a ESM to be resolved with that condition. | |
| 28 | 28 | { | |
| 29 | 29 | const hooks = registerHooks({ | |
| 30 | - resolve(specifier, context, nextResolve) { | ||
| 30 | + resolve: common.mustCall((specifier, context, nextResolve) => { | ||
| 31 | 31 | assert(Array.isArray(context.conditions)); | |
| 32 | 32 | context.conditions = ['foo-esm', ...context.conditions]; | |
| 33 | 33 | return nextResolve(specifier, context); | |
| 34 | - }, | ||
| 34 | + }, 2), | ||
| 35 | 35 | }); | |
| 36 | 36 | assert.strictEqual(cjs('foo/third').result, 'foo-esm'); | |
| 37 | 37 | assert.strictEqual((await esm('foo/third')).result, 'foo-esm'); | |
@@ -41,11 +41,11 @@ assert.strictEqual((await esm('foo')).result, 'default'); | |||
| 41 | 41 | // Duplicating the 'foo' condition in the resolve hook should not change the result. | |
| 42 | 42 | { | |
| 43 | 43 | const hooks = registerHooks({ | |
| 44 | - resolve(specifier, context, nextResolve) { | ||
| 44 | + resolve: common.mustCall((specifier, context, nextResolve) => { | ||
| 45 | 45 | assert(Array.isArray(context.conditions)); | |
| 46 | 46 | context.conditions = ['foo', ...context.conditions, 'foo']; | |
| 47 | 47 | return nextResolve(specifier, context); | |
| 48 | - }, | ||
| 48 | + }, 2), | ||
| 49 | 49 | }); | |
| 50 | 50 | assert.strictEqual(cjs('foo/fourth').result, 'foo'); | |
| 51 | 51 | assert.strictEqual((await esm('foo/fourth')).result, 'foo'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,6 +34,6 @@ async_hooks.createHook({ | |||
| 34 | 34 | }), | |
| 35 | 35 | }).enable(); | |
| 36 | 36 | ||
| 37 | - runInCallbackScope(expectedResource, expectedResourceType, () => { | ||
| 37 | + runInCallbackScope(expectedResource, expectedResourceType, common.mustCall(() => { | ||
| 38 | 38 | assert(insideHook); | |
| 39 | - }); | ||
| 39 | + })); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,7 +21,7 @@ | |||
| 21 | 21 | ||
| 22 | 22 | 'use strict'; | |
| 23 | 23 | ||
| 24 | - const { invalidArgTypeHelper } = require('../common'); | ||
| 24 | + const { invalidArgTypeHelper, mustCall } = require('../common'); | ||
| 25 | 25 | const assert = require('assert'); | |
| 26 | 26 | const { inspect } = require('util'); | |
| 27 | 27 | const { test } = require('node:test'); | |
@@ -605,7 +605,7 @@ test('Test strict assert', () => { | |||
| 605 | 605 | } | |
| 606 | 606 | ); | |
| 607 | 607 | strict.throws( | |
| 608 | - () => assert(), | ||
| 608 | + mustCall(() => assert()), | ||
| 609 | 609 | { | |
| 610 | 610 | message: 'No value argument passed to `assert.ok()`', | |
| 611 | 611 | name: 'AssertionError' | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -172,12 +172,12 @@ if (process.argv[2] === 'child') { | |||
| 172 | 172 | function closeServer() { | |
| 173 | 173 | server.close(); | |
| 174 | 174 | ||
| 175 | - setTimeout(() => { | ||
| 175 | + setTimeout(mustCall(() => { | ||
| 176 | 176 | assert(!closeEmitted); | |
| 177 | 177 | child1.send('close'); | |
| 178 | 178 | child2.send('close'); | |
| 179 | 179 | child3.disconnect(); | |
| 180 | - }, platformTimeout(200)); | ||
| 180 | + }), platformTimeout(200)); | ||
| 181 | 181 | } | |
| 182 | 182 | ||
| 183 | 183 | process.on('exit', function() { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -160,36 +160,36 @@ if (cluster.isWorker) { | |||
| 160 | 160 | })); | |
| 161 | 161 | ||
| 162 | 162 | // Check all values | |
| 163 | - process.once('exit', () => { | ||
| 163 | + process.on('exit', () => { | ||
| 164 | 164 | // Check cluster events | |
| 165 | - forEach(checks.cluster.events, (check, name) => { | ||
| 165 | + for (const [ name, check ] of Object.entries(checks.cluster.events)) { | ||
| 166 | 166 | assert(check, | |
| 167 | 167 | `The cluster event "${name}" on the cluster object did not fire`); | |
| 168 | - }); | ||
| 168 | + } | ||
| 169 | 169 | ||
| 170 | 170 | // Check cluster event arguments | |
| 171 | - forEach(checks.cluster.equal, (check, name) => { | ||
| 171 | + for (const [ name, check ] of Object.entries(checks.cluster.equal)) { | ||
| 172 | 172 | assert(check, | |
| 173 | 173 | `The cluster event "${name}" did not emit with correct argument`); | |
| 174 | - }); | ||
| 174 | + } | ||
| 175 | 175 | ||
| 176 | 176 | // Check worker states | |
| 177 | - forEach(checks.worker.states, (check, name) => { | ||
| 177 | + for (const [ name, check ] of Object.entries(checks.worker.states)) { | ||
| 178 | 178 | assert(check, | |
| 179 | 179 | `The worker state "${name}" was not set to true`); | |
| 180 | - }); | ||
| 180 | + } | ||
| 181 | 181 | ||
| 182 | 182 | // Check worker events | |
| 183 | - forEach(checks.worker.events, (check, name) => { | ||
| 183 | + for (const [ name, check ] of Object.entries(checks.worker.events)) { | ||
| 184 | 184 | assert(check, | |
| 185 | 185 | `The worker event "${name}" on the worker object did not fire`); | |
| 186 | - }); | ||
| 186 | + } | ||
| 187 | 187 | ||
| 188 | 188 | // Check worker event arguments | |
| 189 | - forEach(checks.worker.equal, (check, name) => { | ||
| 189 | + for (const [ name, check ] of Object.entries(checks.worker.equal)) { | ||
| 190 | 190 | assert(check, | |
| 191 | 191 | `The worker event "${name}" did not emit with correct argument`); | |
| 192 | - }); | ||
| 192 | + } | ||
| 193 | 193 | }); | |
| 194 | 194 | ||
| 195 | 195 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments