3
3
const test = require ( 'tap' ) . test
4
4
const Rule = require ( '../../lib/rules/pr-url' )
5
5
const MISSING_PR_URL = 'Commit must have a PR-URL.'
6
- const INVALID_PR_URL = 'PR-URL must be a url, not a pr number.'
6
+ const INVALID_PR_URL = 'PR-URL must be a GitHub pull request URL.'
7
+ const NUMERIC_PR_URL = 'PR-URL must be a URL, not a pull request number.'
8
+ const VALID_PR_URL = 'PR-URL is valid.'
7
9
8
10
test ( 'rule: pr-url' , ( t ) => {
9
11
t . test ( 'missing' , ( tt ) => {
@@ -24,7 +26,8 @@ test('rule: pr-url', (t) => {
24
26
Rule . validate ( context )
25
27
} )
26
28
27
- t . test ( 'invalid' , ( tt ) => {
29
+
30
+ t . test ( 'invalid numeric' , ( tt ) => {
28
31
tt . plan ( 7 )
29
32
const context = {
30
33
prUrl : '#1234'
@@ -35,7 +38,7 @@ test('rule: pr-url', (t) => {
35
38
, report : ( opts ) => {
36
39
tt . pass ( 'called report' )
37
40
tt . equal ( opts . id , 'pr-url' , 'id' )
38
- tt . equal ( opts . message , INVALID_PR_URL , 'message' )
41
+ tt . equal ( opts . message , NUMERIC_PR_URL , 'message' )
39
42
tt . equal ( opts . string , '#1234' , 'string' )
40
43
tt . equal ( opts . line , 1 , 'line' )
41
44
tt . equal ( opts . column , 8 , 'column' )
@@ -46,5 +49,51 @@ test('rule: pr-url', (t) => {
46
49
Rule . validate ( context )
47
50
} )
48
51
52
+ t . test ( 'invalid' , ( tt ) => {
53
+ tt . plan ( 7 )
54
+ const url = 'https://github.com/nodejs/node/issues/1234'
55
+ const context = {
56
+ prUrl : url
57
+ , body : [
58
+ ''
59
+ , `PR-URL: ${ url } `
60
+ ]
61
+ , report : ( opts ) => {
62
+ tt . pass ( 'called report' )
63
+ tt . equal ( opts . id , 'pr-url' , 'id' )
64
+ tt . equal ( opts . message , INVALID_PR_URL , 'message' )
65
+ tt . equal ( opts . string , url , 'string' )
66
+ tt . equal ( opts . line , 1 , 'line' )
67
+ tt . equal ( opts . column , 8 , 'column' )
68
+ tt . equal ( opts . level , 'fail' , 'level' )
69
+ }
70
+ }
71
+
72
+ Rule . validate ( context )
73
+ } )
74
+
75
+ t . test ( 'valid' , ( tt ) => {
76
+ tt . plan ( 7 )
77
+ const url = 'https://github.com/nodejs/node/pull/1234'
78
+ const context = {
79
+ prUrl : url
80
+ , body : [
81
+ ''
82
+ , `PR-URL: ${ url } `
83
+ ]
84
+ , report : ( opts ) => {
85
+ tt . pass ( 'called report' )
86
+ tt . equal ( opts . id , 'pr-url' , 'id' )
87
+ tt . equal ( opts . message , VALID_PR_URL , 'message' )
88
+ tt . equal ( opts . string , url , 'string' )
89
+ tt . equal ( opts . line , 1 , 'line' )
90
+ tt . equal ( opts . column , 8 , 'column' )
91
+ tt . equal ( opts . level , 'pass' , 'level' )
92
+ }
93
+ }
94
+
95
+ Rule . validate ( context )
96
+ } )
97
+
49
98
t . end ( )
50
99
} )
0 commit comments