Skip to content

Commit 58e1be2

Browse files
committed
Add more node:util tests
1 parent 9851ddb commit 58e1be2

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

src/workerd/api/node/util-nodejs-test.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2525

2626
import assert from 'node:assert';
27+
import { mock } from 'node:test';
2728
import util, { inspect } from 'node:util';
2829

2930
const remainingMustCallErrors = new Set();
@@ -3777,3 +3778,49 @@ export const utilInspectError = {
37773778
);
37783779
}
37793780
};
3781+
3782+
export const logTest = {
3783+
test() {
3784+
const original = console.log;
3785+
console.log = mock.fn();
3786+
3787+
util.log('test');
3788+
3789+
assert.strictEqual(console.log.mock.callCount(), 1);
3790+
const args = console.log.mock.calls[0].arguments;
3791+
assert.strictEqual(args.length, 3);
3792+
assert.strictEqual(args[0], '%s - %s');
3793+
// skipping the check on args[1] since it'll be a timestamp that changes
3794+
assert.strictEqual(args[2], 'test');
3795+
3796+
console.log = original;
3797+
}
3798+
};
3799+
3800+
export const aborted = {
3801+
async test() {
3802+
const signal = AbortSignal.timeout(10);
3803+
await util.aborted(signal, {});
3804+
3805+
await assert.rejects(util.aborted({}, {}), {
3806+
message: 'The "signal" argument must be an instance of AbortSignal. ' +
3807+
'Received an instance of Object'
3808+
});
3809+
}
3810+
};
3811+
3812+
export const debuglog = {
3813+
test() {
3814+
const original = console.log;
3815+
console.log = mock.fn();
3816+
3817+
util.debuglog('test')('hello');
3818+
3819+
assert.strictEqual(console.log.mock.callCount(), 1);
3820+
const args = console.log.mock.calls[0].arguments;
3821+
assert.strictEqual(args.length, 1);
3822+
assert.strictEqual(args[0], 'TEST: hello\n');
3823+
3824+
console.log = original;
3825+
}
3826+
};

0 commit comments

Comments
 (0)