-
Notifications
You must be signed in to change notification settings - Fork 3
/
required-regex-rule.e2e-test.js
105 lines (95 loc) · 1.94 KB
/
required-regex-rule.e2e-test.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright (c) 2020 Gonzalo Müller Bravo.
// Licensed under the MIT License (MIT), see LICENSE.txt
const RuleTester = require('eslint').RuleTester
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2015 }})
const shouldNotFind = {
code: 'var z = 1\nvar x = "valid"',
filename: 'some.js',
options: [
['required']
],
errors: [{
message: 'Required regular expression /required/gm not found in file',
line: 1,
column: 1
}]
}
const shouldHandleEmptyFile = {
code: '',
filename: 'some.test.js',
options: [
['required']
],
errors: [{
message: 'Required regular expression /required/gm not found in file',
line: 1,
column: 1
}]
}
const shouldIgnoreFile = {
code: 'var z = 1\nvar x = "valid"',
filename: 'some.test.js',
options: [
['required'],
'.*test\.js'
]
}
const shouldFind = {
code: 'var z = 1\nvar x = "required"',
filename: 'some.js',
options: [
['required']
]
}
const shouldFindAcrossLines = {
code: 'function z() {}\nconst \nrequired = "1"',
filename: 'some.js',
options: [
['^const\\s*required']
]
}
ruleTester.run(
'required',
require('../../../lib').rules.required, {
valid: [
shouldIgnoreFile,
shouldFind,
shouldFindAcrossLines
],
invalid: [
shouldNotFind,
shouldHandleEmptyFile
]
}
)
ruleTester.run(
'required_extra',
require('../../../lib').rules.required_extra, {
valid: [
shouldIgnoreFile,
shouldFind,
shouldFindAcrossLines
],
invalid: [
shouldNotFind,
shouldHandleEmptyFile
]
}
)
ruleTester.run(
'required-extra',
require('../../../lib').rules['required-extra'], {
valid: [
shouldIgnoreFile,
shouldFind,
shouldFindAcrossLines
],
invalid: [
shouldNotFind,
shouldHandleEmptyFile
]
}
)
if(require('../../../lib').rules['no-valid-extra'] !== undefined) {
throw 'non valid rule should be undefined'
}