forked from CondeNast/conventional-pull-request-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlint-rules.spec.js
More file actions
76 lines (63 loc) · 2.28 KB
/
Copy pathlint-rules.spec.js
File metadata and controls
76 lines (63 loc) · 2.28 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { describe, it, before, beforeEach, mock } from 'node:test'
import assert from 'node:assert/strict'
import actionConfigFixture from './fixtures/action-config.js'
import actionMessage from '../src/action-message.js'
import rulesFixture from './fixtures/commitlint.rules.js'
const mockCore = {
info: mock.fn(),
warning: mock.fn(),
error: mock.fn(),
setFailed: mock.fn()
}
mock.module('@actions/core', { namedExports: mockCore })
let getLintRules
before(async () => {
;({ default: getLintRules } = await import('../src/lint-rules.js'))
})
describe('lint-rules', () => {
beforeEach(() => {
for (const fn of [mockCore.info, mockCore.warning, mockCore.error, mockCore.setFailed]) {
fn.mock.resetCalls()
}
})
it('warns when RULES_PATH is set without github checkout action', async () => {
await getLintRules({
...actionConfigFixture,
GITHUB_WORKSPACE: undefined,
RULES_PATH: './fixtures/commitlint.rules.js'
})
assert.ok(
mockCore.warning.mock.calls.some((c) => c.arguments[0] === actionMessage.warning.action.checkout)
)
})
it('warns if rules module is not found', async () => {
await getLintRules({
...actionConfigFixture,
GITHUB_WORKSPACE: './',
RULES_PATH: '/invalid/path/to/rules'
})
assert.ok(
mockCore.warning.mock.calls.some((c) => c.arguments[0] === actionMessage.warning.action.rules_not_found)
)
})
it('overrides config-conventional rules with lint rules in rules module', async () => {
const rules = await getLintRules({
...actionConfigFixture,
GITHUB_WORKSPACE: './',
RULES_PATH: './test/fixtures/commitlint.rules.js'
})
assert.strictEqual(mockCore.warning.mock.callCount(), 0)
assert.deepEqual(rules['some-overriden-rule'], rulesFixture.rules['some-overriden-rule'])
})
it('applies config conventional rules and rules module rules', async () => {
const rules = await getLintRules({
...actionConfigFixture,
GITHUB_WORKSPACE: './',
RULES_PATH: './test/fixtures/commitlint.rules.js'
})
assert.strictEqual(mockCore.warning.mock.callCount(), 0)
assert.ok(Array.isArray(rules['header-max-length']))
assert.ok(Array.isArray(rules['only-rules-module-rule']))
assert.ok(Array.isArray(rules['some-overriden-rule']))
})
})