|
24 | 24 | // USE OR OTHER DEALINGS IN THE SOFTWARE. |
25 | 25 |
|
26 | 26 | import assert from 'node:assert'; |
| 27 | +import { mock } from 'node:test'; |
27 | 28 | import util, { inspect } from 'node:util'; |
28 | 29 |
|
29 | 30 | const remainingMustCallErrors = new Set(); |
@@ -3777,3 +3778,49 @@ export const utilInspectError = { |
3777 | 3778 | ); |
3778 | 3779 | } |
3779 | 3780 | }; |
| 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