1
1
import loadPlugin from './load-plugin' ;
2
+ import { AsyncRule , Plugin , Rule , SyncRule } from '@commitlint/types' ;
2
3
3
4
jest . mock ( 'commitlint-plugin-example' , ( ) => ( { example : true } ) , {
4
5
virtual : true ,
@@ -8,6 +9,39 @@ jest.mock('@scope/commitlint-plugin-example', () => ({scope: true}), {
8
9
virtual : true ,
9
10
} ) ;
10
11
12
+ jest . mock (
13
+ 'commitlint-plugin-rule' ,
14
+ ( ) : Plugin => {
15
+ const rule : Rule < number > = ( _parsed , when , _value ) => {
16
+ return [ when === 'never' ] ;
17
+ } ;
18
+ return { rules : { rule} } ;
19
+ } ,
20
+ { virtual : true }
21
+ ) ;
22
+
23
+ jest . mock (
24
+ 'commitlint-plugin-sync-rule' ,
25
+ ( ) : Plugin => {
26
+ const syncRule : SyncRule < number > = ( _parsed , when , _value ) => {
27
+ return [ when === 'never' ] ;
28
+ } ;
29
+ return { rules : { syncRule} } ;
30
+ } ,
31
+ { virtual : true }
32
+ ) ;
33
+
34
+ jest . mock (
35
+ 'commitlint-plugin-async-rule' ,
36
+ ( ) : Plugin => {
37
+ const asyncRule : AsyncRule < number > = ( _parsed , when , _value ) => {
38
+ return new Promise ( ( ) => [ when === 'never' ] ) ;
39
+ } ;
40
+ return { rules : { asyncRule} } ;
41
+ } ,
42
+ { virtual : true }
43
+ ) ;
44
+
11
45
test ( 'should load a plugin when referenced by short name' , ( ) => {
12
46
const plugins = loadPlugin ( { } , 'example' ) ;
13
47
expect ( plugins [ 'example' ] ) . toBe ( require ( 'commitlint-plugin-example' ) ) ;
@@ -18,6 +52,21 @@ test('should load a plugin when referenced by long name', () => {
18
52
expect ( plugins [ 'example' ] ) . toBe ( require ( 'commitlint-plugin-example' ) ) ;
19
53
} ) ;
20
54
55
+ test ( 'should load a plugin with a rule' , ( ) => {
56
+ const plugins = loadPlugin ( { } , 'commitlint-plugin-rule' ) ;
57
+ expect ( plugins [ 'rule' ] ) . toBe ( require ( 'commitlint-plugin-rule' ) ) ;
58
+ } ) ;
59
+
60
+ test ( 'should load a plugin with a sync rule' , ( ) => {
61
+ const plugins = loadPlugin ( { } , 'commitlint-plugin-sync-rule' ) ;
62
+ expect ( plugins [ 'sync-rule' ] ) . toBe ( require ( 'commitlint-plugin-sync-rule' ) ) ;
63
+ } ) ;
64
+
65
+ test ( 'should load a plugin with an async rule' , ( ) => {
66
+ const plugins = loadPlugin ( { } , 'commitlint-plugin-async-rule' ) ;
67
+ expect ( plugins [ 'async-rule' ] ) . toBe ( require ( 'commitlint-plugin-async-rule' ) ) ;
68
+ } ) ;
69
+
21
70
test ( 'should throw an error when a plugin has whitespace' , ( ) => {
22
71
expect ( ( ) => loadPlugin ( { } , 'whitespace ' ) ) . toThrow (
23
72
"Whitespace found in plugin name 'whitespace '"
0 commit comments