Skip to content

Commit fc1ee40

Browse files
committed
wip: remove old testInFiber and related methods
1 parent 3a66d85 commit fc1ee40

File tree

29 files changed

+324
-390
lines changed

29 files changed

+324
-390
lines changed

meteor/__mocks__/helpers/jest.ts

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,3 @@
1-
/* eslint-disable jest/no-export, jest/valid-title, jest/expect-expect, jest/no-focused-tests */
2-
3-
export function beforeAllInFiber(fcn: () => void | Promise<void>, timeout?: number): void {
4-
beforeAll(async () => {
5-
await fcn()
6-
}, timeout)
7-
}
8-
export function afterAllInFiber(fcn: () => void | Promise<void>, timeout?: number): void {
9-
afterAll(async () => {
10-
await fcn()
11-
}, timeout)
12-
}
13-
export function beforeEachInFiber(fcn: () => void | Promise<void>, timeout?: number): void {
14-
beforeEach(async () => {
15-
await fcn()
16-
}, timeout)
17-
}
18-
export function afterEachInFiber(fcn: () => void | Promise<void>, timeout?: number): void {
19-
afterEach(async () => {
20-
await fcn()
21-
}, timeout)
22-
}
23-
24-
export function testInFiber(testName: string, fcn: () => void | Promise<void>, timeout?: number): void {
25-
test(
26-
testName,
27-
async () => {
28-
await fcn()
29-
},
30-
timeout
31-
)
32-
}
33-
34-
export function testInFiberOnly(testName: string, fcn: () => void | Promise<void>, timeout?: number): void {
35-
// eslint-disable-next-line custom-rules/no-focused-test
36-
test.only(
37-
testName,
38-
async () => {
39-
await fcn()
40-
},
41-
timeout
42-
)
43-
}
441
const orgSetTimeout = setTimeout
452
const DateOrg = Date
463
export async function runAllTimers(): Promise<void> {

meteor/server/__tests__/_testEnvironment.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { RandomMock } from '../../__mocks__/random'
22
import { MongoMock } from '../../__mocks__/mongo'
33
import { protectString, getRandomString } from '../lib/tempLib'
44
import { sleep } from '../lib/lib'
5-
import { testInFiber } from '../../__mocks__/helpers/jest'
65
import {
76
AdLibPieces,
87
Blueprints,
@@ -147,7 +146,7 @@ describe('Basic test of test environment', () => {
147146
MongoMock.mockSetData(Studios, null)
148147
expect(await Studios.findFetchAsync({})).toHaveLength(0)
149148
})
150-
testInFiber('Mongo mock', async () => {
149+
test('Mongo mock', async () => {
151150
const mockAdded = jest.fn()
152151
const mockChanged = jest.fn()
153152
const mockRemoved = jest.fn()

meteor/server/__tests__/coreSystem.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { testInFiber } from '../../__mocks__/helpers/jest'
21
import { RelevantSystemVersions } from '../coreSystem'
32

43
describe('coreSystem', () => {
5-
testInFiber('RelevantSystemVersions', async () => {
4+
test('RelevantSystemVersions', async () => {
65
const versions = await RelevantSystemVersions
76

87
expect(versions).toEqual({

meteor/server/__tests__/cronjobs.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import '../../__mocks__/_extendJest'
2-
import { testInFiber, runAllTimers, beforeAllInFiber, waitUntil } from '../../__mocks__/helpers/jest'
2+
import { runAllTimers, waitUntil } from '../../__mocks__/helpers/jest'
33
import { MeteorMock } from '../../__mocks__/meteor'
44
import { logger } from '../logging'
55
import { getRandomId, getRandomString, protectString } from '../lib/tempLib'
@@ -69,7 +69,7 @@ describe('cronjobs', () => {
6969
let env: DefaultEnvironment
7070
let rundownId: RundownId
7171

72-
beforeAllInFiber(async () => {
72+
beforeAll(async () => {
7373
env = await setupDefaultStudioEnvironment()
7474

7575
const o = await setupDefaultRundownPlaylist(env)
@@ -101,7 +101,7 @@ describe('cronjobs', () => {
101101
await CoreSystem.removeAsync(SYSTEM_ID)
102102
})
103103
describe('Runs at the appropriate time', () => {
104-
testInFiber("Doesn't run during the day", async () => {
104+
test("Doesn't run during the day", async () => {
105105
// set time to 2020/07/19 12:00 Local Time
106106
mockCurrentTime = new Date(2020, 6, 19, 12, 0, 0).getTime()
107107
// cronjob is checked every 5 minutes, so advance 6 minutes
@@ -112,7 +112,7 @@ describe('cronjobs', () => {
112112

113113
expect(logger.info).toHaveBeenCalledTimes(0)
114114
})
115-
testInFiber("Runs at 4 o'clock", async () => {
115+
test("Runs at 4 o'clock", async () => {
116116
// set time to 2020/07/20 04:05 Local Time, should be more than 24 hours after 2020/07/19 00:00 UTC
117117
mockCurrentTime = new Date(2020, 6, 20, 4, 5, 0).getTime()
118118
// cronjob is checked every 5 minutes, so advance 6 minutes
@@ -127,7 +127,7 @@ describe('cronjobs', () => {
127127
expect(logger.info).toHaveBeenLastCalledWith('Nightly cronjob: done')
128128
}, MAX_WAIT_TIME)
129129
})
130-
testInFiber("Doesn't run if less than 20 hours have passed since last run", async () => {
130+
test("Doesn't run if less than 20 hours have passed since last run", async () => {
131131
// set time to 2020/07/21 04:05 Local Time, should be more than 24 hours after 2020/07/19 00:00 UTC
132132
mockCurrentTime = new Date(2020, 6, 21, 4, 5, 0).getTime()
133133
// cronjob is checked every 5 minutes, so advance 6 minutes
@@ -173,7 +173,7 @@ describe('cronjobs', () => {
173173
await PeripheralDevices.removeAsync({})
174174
})
175175

176-
testInFiber('Remove NrcsIngestDataCache objects that are not connected to any Rundown', async () => {
176+
test('Remove NrcsIngestDataCache objects that are not connected to any Rundown', async () => {
177177
// Set up a mock rundown, a detached NrcsIngestDataCache object and an object attached to the mock rundown
178178
// Detached NrcsIngestDataCache object 0
179179
const dataCache0Id = protectString<NrcsIngestDataCacheObjId>(getRandomString())
@@ -217,7 +217,7 @@ describe('cronjobs', () => {
217217
})
218218
expect(await NrcsIngestDataCache.findOneAsync(dataCache0Id)).toBeUndefined()
219219
})
220-
testInFiber('Remove SofieIngestDataCache objects that are not connected to any Rundown', async () => {
220+
test('Remove SofieIngestDataCache objects that are not connected to any Rundown', async () => {
221221
// Set up a mock rundown, a detached SofieIngestDataCache object and an object attached to the mock rundown
222222
// Detached SofieIngestDataCache object 0
223223
const dataCache0Id = protectString<SofieIngestDataCacheObjId>(getRandomString())
@@ -263,7 +263,7 @@ describe('cronjobs', () => {
263263
})
264264
expect(await SofieIngestDataCache.findOneAsync(dataCache0Id)).toBeUndefined()
265265
})
266-
testInFiber('Removes old PartInstances and PieceInstances', async () => {
266+
test('Removes old PartInstances and PieceInstances', async () => {
267267
// nightlyCronjobInner()
268268

269269
const segment0: DBSegment = {
@@ -396,7 +396,7 @@ describe('cronjobs', () => {
396396
expect(await PieceInstances.findOneAsync(pieceInstance0._id)).toBeDefined()
397397
expect(await PieceInstances.findOneAsync(pieceInstance1._id)).toBeUndefined() // Removed, since owned by non-existent partInstance2
398398
})
399-
testInFiber('Removes old entries in UserActionsLog', async () => {
399+
test('Removes old entries in UserActionsLog', async () => {
400400
// reasonably fresh entry
401401
const userAction0 = protectString<UserActionsLogItemId>(getRandomString())
402402
await UserActionsLog.insertAsync({
@@ -430,7 +430,7 @@ describe('cronjobs', () => {
430430
})
431431
expect(await UserActionsLog.findOneAsync(userAction1)).toBeUndefined()
432432
})
433-
testInFiber('Removes old entries in Snapshots', async () => {
433+
test('Removes old entries in Snapshots', async () => {
434434
// reasonably fresh entry
435435
const snapshot0 = protectString<SnapshotId>(getRandomString())
436436
await Snapshots.insertAsync({
@@ -524,7 +524,7 @@ describe('cronjobs', () => {
524524
}
525525
}
526526

527-
testInFiber('Attempts to restart CasparCG when job is enabled', async () => {
527+
test('Attempts to restart CasparCG when job is enabled', async () => {
528528
const { mockCasparCg } = await createMockPlayoutGatewayAndDevices(Date.now()) // Some time after the threshold
529529

530530
;(logger.info as jest.Mock).mockClear()
@@ -563,7 +563,7 @@ describe('cronjobs', () => {
563563
expect(logger.info).toHaveBeenLastCalledWith('Nightly cronjob: done')
564564
}, MAX_WAIT_TIME)
565565
})
566-
testInFiber('Skips offline CasparCG when job is enabled', async () => {
566+
test('Skips offline CasparCG when job is enabled', async () => {
567567
const { mockCasparCg } = await createMockPlayoutGatewayAndDevices(Date.now()) // Some time after the threshold
568568
await PeripheralDevices.updateAsync(mockCasparCg, {
569569
$set: {
@@ -589,7 +589,7 @@ describe('cronjobs', () => {
589589
expect(logger.info).toHaveBeenLastCalledWith('Nightly cronjob: done')
590590
}, MAX_WAIT_TIME)
591591
})
592-
testInFiber('Does not attempt to restart CasparCG when job is disabled', async () => {
592+
test('Does not attempt to restart CasparCG when job is disabled', async () => {
593593
await createMockPlayoutGatewayAndDevices(Date.now()) // Some time after the threshold
594594
await CoreSystem.updateAsync(
595595
{},

meteor/server/__tests__/logging.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { testInFiber } from '../../__mocks__/helpers/jest'
21
import { supressLogging } from '../../__mocks__/helpers/lib'
32
import { SupressLogMessages } from '../../__mocks__/suppressLogging'
43
import { logger } from '../logging'
54

65
describe('server/logger', () => {
7-
testInFiber('supress errors', async () => {
6+
test('supress errors', async () => {
87
const logMessages = () => {
98
logger.debug('This is a debug message')
109
logger.info('This is an info message')
@@ -20,7 +19,7 @@ describe('server/logger', () => {
2019
expect(1).toBe(1)
2120
})
2221

23-
testInFiber('logger', () => {
22+
test('logger', () => {
2423
expect(typeof logger.error).toEqual('function')
2524
expect(typeof logger.warn).toEqual('function')
2625
// expect(typeof logger.help).toEqual('function')

meteor/server/__tests__/systemTime.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { runTimersUntilNow, testInFiber } from '../../__mocks__/helpers/jest'
1+
import { runTimersUntilNow } from '../../__mocks__/helpers/jest'
22
import { TimeJumpDetector } from '../systemTime'
33

44
describe('lib/systemTime', () => {
5-
testInFiber('TimeJumpDetector', async () => {
5+
test('TimeJumpDetector', async () => {
66
jest.useFakeTimers()
77
const mockCallback = jest.fn()
88
let now = Date.now()

meteor/server/api/__tests__/cleanup.test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { getRandomId } from '../../lib/tempLib'
2-
import { beforeEachInFiber, testInFiber } from '../../../__mocks__/helpers/jest'
32

43
import '../../collections' // include this in order to get all of the collection set up
54
import { cleanupOldDataInner } from '../cleanup'
@@ -56,12 +55,12 @@ import { DBNotificationTargetType } from '@sofie-automation/corelib/dist/dataMod
5655
describe('Cleanup', () => {
5756
let env: DefaultEnvironment
5857

59-
beforeEachInFiber(async () => {
58+
beforeEach(async () => {
6059
await clearAllDBCollections()
6160
env = await setupDefaultStudioEnvironment()
6261
})
6362

64-
testInFiber('Check that all collections are covered', async () => {
63+
test('Check that all collections are covered', async () => {
6564
expect(Collections.size).toBeGreaterThan(10)
6665

6766
const result = await cleanupOldDataInner(false)
@@ -73,7 +72,7 @@ describe('Cleanup', () => {
7372
}
7473
})
7574

76-
testInFiber('No bad removals', async () => {
75+
test('No bad removals', async () => {
7776
// Check that cleanupOldDataInner() doesn't remove any data when the default data set is in the DB.
7877

7978
await setDefaultDatatoDB(env, Date.now())
@@ -94,7 +93,7 @@ describe('Cleanup', () => {
9493
expect(await RundownPlaylists.countDocuments()).toBe(1)
9594
expect(await Rundowns.countDocuments()).toBe(1)
9695
})
97-
testInFiber('All dependants should be removed', async () => {
96+
test('All dependants should be removed', async () => {
9897
// Check that cleanupOldDataInner() cleans up all data from the database.
9998

10099
await setDefaultDatatoDB(env, 0)
@@ -137,7 +136,7 @@ describe('Cleanup', () => {
137136
}
138137
}
139138
})
140-
testInFiber('PieceInstance should be removed when PartInstance is removed', async () => {
139+
test('PieceInstance should be removed when PartInstance is removed', async () => {
141140
// Check that cleanupOldDataInner() cleans up all data from the database.
142141

143142
await setDefaultDatatoDB(env, 0)

0 commit comments

Comments
 (0)