/
conventional-release-labels.js
44 lines (41 loc) · 1.86 KB
/
conventional-release-labels.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
const { beforeEach, describe, it, afterEach } = require('mocha')
const api = require('../index.js')
const core = require('@actions/core')
const fs = require('fs')
const sinon = require('sinon')
const yaml = require('js-yaml')
const sandbox = sinon.createSandbox()
process.env.GITHUB_EVENT_PATH = process.env.GITHUB_EVENT_PATH || ''
const metadata = yaml.load(fs.readFileSync('./action.yml', 'utf8'))
describe('conventional-release-labels', () => {
beforeEach(() => {
sandbox.replace(core, 'getInput', (key) => {
return metadata.inputs[key].default
})
})
afterEach(() => {
sandbox.restore()
})
it('handles unconventional commit', async () => {
const addLabels = sandbox.stub(api, 'addLabels').resolves(undefined)
sandbox.stub(process.env, 'GITHUB_EVENT_PATH').value('./test/fixtures/unconventional.json')
await api.main()
sandbox.assert.notCalled(addLabels)
})
it('it adds feature label', async () => {
const addLabels = sandbox.stub(api, 'addLabels').resolves(undefined)
const removeLabels = sandbox.stub(api, 'removeLabels').resolves(undefined)
sandbox.stub(process.env, 'GITHUB_EVENT_PATH').value('./test/fixtures/feature.json')
await api.main()
sandbox.assert.calledWith(removeLabels, ['feature', 'fix', 'breaking'], sandbox.match.any)
sandbox.assert.calledWith(addLabels, ['feature'], sandbox.match.any)
})
it('it adds breaking label along with type', async () => {
const addLabels = sandbox.stub(api, 'addLabels').resolves(undefined)
const removeLabels = sandbox.stub(api, 'removeLabels').resolves(undefined)
sandbox.stub(process.env, 'GITHUB_EVENT_PATH').value('./test/fixtures/breaking-fix.json')
await api.main()
sandbox.assert.calledWith(removeLabels, ['feature', 'fix', 'breaking'], sandbox.match.any)
sandbox.assert.calledWith(addLabels, ['breaking', 'fix'], sandbox.match.any)
})
})