forked from bahmutov/npm-install
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspec.js
54 lines (47 loc) · 1.59 KB
/
spec.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
47
48
49
50
51
52
53
54
const action = require('../index')
const utils = action.utils
describe('misc', () => {
it('exports a function', () => {
expect(action)
.to.have.property('npmInstallAction')
.and.be.a('function')
expect(action).to.have.property('utils')
})
it('cache was not hit', async () => {
// previous cache not found
const cacheHit = false
const restoreCache = sandbox.stub(utils, 'restoreCachedNpm')
const install = sandbox.stub(utils, 'install')
const saveCache = sandbox.stub(utils, 'saveCachedNpm')
restoreCache.resolves(cacheHit)
install.resolves()
saveCache.resolves()
await action.npmInstallAction()
expect(saveCache, 'new cache was saved').to.have.been.calledOnce
expect(
restoreCache,
'restore cache was checked first'
).to.have.been.calledBefore(install)
expect(
install,
'install was called before saving cache'
).to.have.been.calledBefore(saveCache)
})
it('cache was hit', async () => {
// we don't need to save cache in this case
const cacheHit = true
const restoreCache = sandbox.stub(utils, 'restoreCachedNpm')
const install = sandbox.stub(utils, 'install')
const saveCache = sandbox.stub(utils, 'saveCachedNpm')
restoreCache.resolves(cacheHit)
install.resolves()
saveCache.resolves()
await action.npmInstallAction()
expect(install, 'install was called').to.have.been.calledOnce
expect(saveCache, 'cache remains the same').to.have.not.been.called
expect(
restoreCache,
'restore cache was checked first'
).to.have.been.calledBefore(install)
})
})