Skip to content

Commit ac0fab3

Browse files
committed
test_runner: move fakerTimers to mock module
Signed-off-by: Erick Wendel <[email protected]>
1 parent 568ad96 commit ac0fab3

File tree

5 files changed

+11
-26
lines changed

5 files changed

+11
-26
lines changed

lib/internal/test_runner/mock.js lib/internal/test_runner/mock/mock.js

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const {
2626
validateInteger,
2727
validateObject,
2828
} = require('internal/validators');
29+
const { FakeTimers } = require('internal/test_runner/mock/fake_timers');
2930

3031
function kDefaultFunction() {}
3132

@@ -35,6 +36,7 @@ class MockFunctionContext {
3536
#implementation;
3637
#restore;
3738
#times;
39+
#fakeTimers;
3840

3941
constructor(implementation, restore, times) {
4042
this.#calls = [];
@@ -48,6 +50,10 @@ class MockFunctionContext {
4850
return ArrayPrototypeSlice(this.#calls, 0);
4951
}
5052

53+
get fakeTimers() {
54+
this.#fakeTimers ??= new FakeTimers();
55+
return this.#fakeTimers;
56+
}
5157
callCount() {
5258
return this.#calls.length;
5359
}

lib/internal/test_runner/test.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ const {
3030
},
3131
AbortError,
3232
} = require('internal/errors');
33-
const { MockTracker } = require('internal/test_runner/mock');
34-
const { FakeTimers } = require('internal/test_runner/fake_timers');
33+
const { MockTracker } = require('internal/test_runner/mock/mock');
3534
const { TestsStream } = require('internal/test_runner/tests_stream');
3635
const {
3736
createDeferredCallback,
@@ -109,11 +108,6 @@ class TestContext {
109108
return this.#test.mock;
110109
}
111110

112-
get fakeTimers() {
113-
this.#test.fakeTimers ??= new FakeTimers();
114-
return this.#test.fakeTimers;
115-
}
116-
117111
runOnly(value) {
118112
this.#test.runOnlySubtests = !!value;
119113
}

lib/test.js

+1-18
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,11 @@ ObjectDefineProperty(module.exports, 'mock', {
2323
enumerable: true,
2424
get() {
2525
if (lazyMock === undefined) {
26-
const { MockTracker } = require('internal/test_runner/mock');
26+
const { MockTracker } = require('internal/test_runner/mock/mock');
2727

2828
lazyMock = new MockTracker();
2929
}
3030

3131
return lazyMock;
3232
},
3333
});
34-
35-
let lazyFakeTimers;
36-
37-
ObjectDefineProperty(module.exports, 'fakeTimers', {
38-
__proto__: null,
39-
configurable: true,
40-
enumerable: true,
41-
get() {
42-
if (lazyFakeTimers === undefined) {
43-
const { FakeTimers } = require('internal/test_runner/fake_timers');
44-
45-
lazyFakeTimers = new FakeTimers();
46-
}
47-
48-
return lazyFakeTimers;
49-
},
50-
});

test/parallel/test-runner-fake-timers.js test/parallel/test-runner-mocking-fake-timers.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ const common = require('../common');
33
process.env.NODE_TEST_KNOWN_GLOBALS = 0;
44

55
const assert = require('node:assert');
6-
const { fakeTimers, it, mock, afterEach, describe } = require('node:test');
6+
const { it, mock, afterEach, describe } = require('node:test');
7+
const { fakeTimers } = mock;
8+
79
describe('Faketimers Test Suite', () => {
810

911
describe('setTimeout Suite', () => {

0 commit comments

Comments
 (0)