Skip to content

Commit

Permalink
test_runner: move fakerTimers to mock module
Browse files Browse the repository at this point in the history
Signed-off-by: Erick Wendel <erick.workspace@gmail.com>
  • Loading branch information
ErickWendel committed May 1, 2023
1 parent 568ad96 commit ac0fab3
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 26 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const {
validateInteger,
validateObject,
} = require('internal/validators');
const { FakeTimers } = require('internal/test_runner/mock/fake_timers');

function kDefaultFunction() {}

Expand All @@ -35,6 +36,7 @@ class MockFunctionContext {
#implementation;
#restore;
#times;
#fakeTimers;

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

get fakeTimers() {
this.#fakeTimers ??= new FakeTimers();
return this.#fakeTimers;
}
callCount() {
return this.#calls.length;
}
Expand Down
8 changes: 1 addition & 7 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ const {
},
AbortError,
} = require('internal/errors');
const { MockTracker } = require('internal/test_runner/mock');
const { FakeTimers } = require('internal/test_runner/fake_timers');
const { MockTracker } = require('internal/test_runner/mock/mock');
const { TestsStream } = require('internal/test_runner/tests_stream');
const {
createDeferredCallback,
Expand Down Expand Up @@ -109,11 +108,6 @@ class TestContext {
return this.#test.mock;
}

get fakeTimers() {
this.#test.fakeTimers ??= new FakeTimers();
return this.#test.fakeTimers;
}

runOnly(value) {
this.#test.runOnlySubtests = !!value;
}
Expand Down
19 changes: 1 addition & 18 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,11 @@ ObjectDefineProperty(module.exports, 'mock', {
enumerable: true,
get() {
if (lazyMock === undefined) {
const { MockTracker } = require('internal/test_runner/mock');
const { MockTracker } = require('internal/test_runner/mock/mock');

lazyMock = new MockTracker();
}

return lazyMock;
},
});

let lazyFakeTimers;

ObjectDefineProperty(module.exports, 'fakeTimers', {
__proto__: null,
configurable: true,
enumerable: true,
get() {
if (lazyFakeTimers === undefined) {
const { FakeTimers } = require('internal/test_runner/fake_timers');

lazyFakeTimers = new FakeTimers();
}

return lazyFakeTimers;
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ const common = require('../common');
process.env.NODE_TEST_KNOWN_GLOBALS = 0;

const assert = require('node:assert');
const { fakeTimers, it, mock, afterEach, describe } = require('node:test');
const { it, mock, afterEach, describe } = require('node:test');
const { fakeTimers } = mock;

describe('Faketimers Test Suite', () => {

describe('setTimeout Suite', () => {
Expand Down

0 comments on commit ac0fab3

Please sign in to comment.