Skip to content

Commit

Permalink
fix(tests): making the tests not change the time
Browse files Browse the repository at this point in the history
  • Loading branch information
bassrock committed Apr 17, 2024
1 parent 73f4a64 commit 102f844
Show file tree
Hide file tree
Showing 14 changed files with 182 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,16 @@ describe('clearTags mutation', () => {
beforeAll(async () => {
jest.useFakeTimers({
now: now,
advanceTimers: true,
doNotFake: [
'nextTick',
'setImmediate',
'clearImmediate',
'setInterval',
'clearInterval',
'setTimeout',
'clearTimeout',
],
advanceTimers: false,
});
({ app, server, url } = await startServer(0));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,16 @@ describe('clearTags mutation', () => {
beforeAll(async () => {
jest.useFakeTimers({
now: now,
advanceTimers: true,
doNotFake: [
'nextTick',
'setImmediate',
'clearImmediate',
'setInterval',
'clearInterval',
'setTimeout',
'clearTimeout',
],
advanceTimers: false,
});
({ app, server, url } = await startServer(0));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,19 @@ describe('reAddById mutation', () => {

beforeAll(async () => {
({ app, server, url } = await startServer(0));
jest.useFakeTimers({ advanceTimers: true, now });
jest.useFakeTimers({
doNotFake: [
'nextTick',
'setImmediate',
'clearImmediate',
'setInterval',
'clearInterval',
'setTimeout',
'clearTimeout',
],
advanceTimers: false,
now,
});
});

afterAll(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,16 @@ describe('Delete/Undelete SavedItem: ', () => {
// Mock Date.now() to get a consistent date for inserting data
jest.useFakeTimers({
now: updateDate,
advanceTimers: true,
doNotFake: [
'nextTick',
'setImmediate',
'clearImmediate',
'setInterval',
'clearInterval',
'setTimeout',
'clearTimeout',
],
advanceTimers: false,
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,19 @@ describe('UpsertSavedItem Mutation', () => {

beforeAll(async () => {
({ app, server, url } = await startServer(0));
jest.useFakeTimers({ advanceTimers: true, now: dateNow });
jest.useFakeTimers({
doNotFake: [
'nextTick',
'setImmediate',
'clearImmediate',
'setInterval',
'clearInterval',
'setTimeout',
'clearTimeout',
],
advanceTimers: false,
now: dateNow,
});
});

afterAll(async () => {
Expand Down Expand Up @@ -438,7 +450,19 @@ describe('UpsertSavedItem Mutation', () => {
});

it('should push addItem event to perm lib queue for premium users', async () => {
jest.useFakeTimers({ advanceTimers: true, now: dateNow });
jest.useFakeTimers({
doNotFake: [
'nextTick',
'setImmediate',
'clearImmediate',
'setInterval',
'clearInterval',
'setTimeout',
'clearTimeout',
],
advanceTimers: false,
now: dateNow,
});
const variables = {
url: 'http://addingtoqueue.com',
};
Expand Down Expand Up @@ -517,7 +541,19 @@ describe('UpsertSavedItem Mutation', () => {
});

it(`should update an item already in a user's list`, async () => {
jest.useFakeTimers({ advanceTimers: true, now: dateNow });
jest.useFakeTimers({
doNotFake: [
'nextTick',
'setImmediate',
'clearImmediate',
'setInterval',
'clearInterval',
'setTimeout',
'clearTimeout',
],
advanceTimers: false,
now: dateNow,
});
const variables = {
url: 'http://google.com',
isFavorite: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,16 @@ describe('tags mutation: replace savedItem tags', () => {
// Mock Date.now() to get a consistent date for inserting data
jest.useFakeTimers({
now: updateDate,
advanceTimers: true,
doNotFake: [
'nextTick',
'setImmediate',
'clearImmediate',
'setInterval',
'clearInterval',
'setTimeout',
'clearTimeout',
],
advanceTimers: false,
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,16 @@ describe('updateTag Mutation: ', () => {
beforeEach(async () => {
jest.useFakeTimers({
now: updateDate,
advanceTimers: true,
doNotFake: [
'nextTick',
'setImmediate',
'clearImmediate',
'setInterval',
'clearInterval',
'setTimeout',
'clearTimeout',
],
advanceTimers: false,
});
jest.clearAllMocks();
const baseTag = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,17 @@ describe('tags mutation update: ', () => {
// Mock Date.now() to get a consistent date for inserting body.data
jest.useFakeTimers({
now: updateDate,
advanceTimers: true,
doNotFake: [
'nextTick',
'setImmediate',
'clearImmediate',
'setInterval',
'clearInterval',
'setTimeout',
'clearTimeout',
],
advanceTimers: false,
s,
});
await writeDb('item_tags').truncate();
await writeDb('item_tags').insert([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,16 @@ describe('deleteTagByName mutation', () => {
beforeAll(async () => {
jest.useFakeTimers({
now: now,
advanceTimers: true,
doNotFake: [
'nextTick',
'setImmediate',
'clearImmediate',
'setInterval',
'clearInterval',
'setTimeout',
'clearTimeout',
],
advanceTimers: false,
});
({ app, server, url } = await startServer(0));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,16 @@ describe('deleteTagByName mutation', () => {
beforeAll(async () => {
jest.useFakeTimers({
now: now,
advanceTimers: true,
doNotFake: [
'nextTick',
'setImmediate',
'clearImmediate',
'setInterval',
'clearInterval',
'setTimeout',
'clearTimeout',
],
advanceTimers: false,
});
({ app, server, url } = await startServer(0));
});
Expand Down
11 changes: 10 additions & 1 deletion servers/user-api/src/events/eventBus/eventBusHandler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,16 @@ describe('EventBusHandler', () => {
beforeAll(() => {
jest.useFakeTimers({
now: now,
advanceTimers: true,
doNotFake: [
'nextTick',
'setImmediate',
'clearImmediate',
'setInterval',
'clearInterval',
'setTimeout',
'clearTimeout',
],
advanceTimers: false,
});
});

Expand Down
14 changes: 13 additions & 1 deletion servers/user-list-search/src/freeSearch.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,19 @@ describe('free search test', () => {
});

beforeEach(async () => {
jest.useFakeTimers({ now: updateDate, advanceTimers: true });
jest.useFakeTimers({
now: updateDate,
doNotFake: [
'nextTick',
'setImmediate',
'clearImmediate',
'setInterval',
'clearInterval',
'setTimeout',
'clearTimeout',
],
advanceTimers: false,
});
});

afterAll(async () => {
Expand Down
14 changes: 13 additions & 1 deletion servers/user-list-search/src/freeSearchByOffset.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,19 @@ describe('free-tier search (offset pagination)', () => {
});

beforeEach(async () => {
jest.useFakeTimers({ now: updateDate, advanceTimers: true });
jest.useFakeTimers({
now: updateDate,
doNotFake: [
'nextTick',
'setImmediate',
'clearImmediate',
'setInterval',
'clearInterval',
'setTimeout',
'clearTimeout',
],
advanceTimers: false,
});
});

afterAll(async () => {
Expand Down
14 changes: 13 additions & 1 deletion servers/v3-proxy-api/src/routes/v3Send.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,19 @@ describe('v3/send', () => {
clientSpy = jest
.spyOn(GraphQLClient.prototype, 'request')
.mockResolvedValue(true);
jest.useFakeTimers({ now: now * 1000, advanceTimers: true });
jest.useFakeTimers({
now: now * 1000,
doNotFake: [
'nextTick',
'setImmediate',
'clearImmediate',
'setInterval',
'clearInterval',
'setTimeout',
'clearTimeout',
],
advanceTimers: false,
});
});
afterAll(async () => {
clientSpy.mockRestore();
Expand Down

0 comments on commit 102f844

Please sign in to comment.