-
Notifications
You must be signed in to change notification settings - Fork 12
/
test-utils.js
46 lines (39 loc) · 1.18 KB
/
test-utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const fse = require('fs-extra')
const os = require('os')
const path = require('path')
const CloudFrontComponent = require('./serverless')
module.exports = {
createComponent: async () => {
// mock to prevent jest snapshots changing every time
Date.now = () => 1566599541192
// create tmp folder to avoid state collisions between tests
const tmpFolder = await fse.mkdtemp(path.join(os.tmpdir(), 'test-'))
const component = new CloudFrontComponent('TestCloudFront', {
stateRoot: tmpFolder
})
await component.init()
return component
},
assertHasCacheBehavior: (spy, cacheBehavior) => {
expect(spy).toBeCalledWith(
expect.objectContaining({
DistributionConfig: expect.objectContaining({
CacheBehaviors: expect.objectContaining({
Items: [expect.objectContaining(cacheBehavior)]
})
})
})
)
},
assertHasOrigin: (spy, origin) => {
expect(spy).toBeCalledWith(
expect.objectContaining({
DistributionConfig: expect.objectContaining({
Origins: expect.objectContaining({
Items: [expect.objectContaining(origin)]
})
})
})
)
}
}