-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.spec.js
47 lines (40 loc) · 1.66 KB
/
test.spec.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
const fs = require('fs');
//include custom matchers
const styleMatchers = require('jest-style-matchers');
expect.extend(styleMatchers);
describe('Source code is valid', () => {
test('HTML validates without errors', async () => {
const lintOpts = {
'attr-bans':['align', 'background', 'bgcolor', 'border', 'frameborder', 'marginwidth', 'marginheight', 'scrolling', 'style', 'width', 'height'], //adding height, allow longdesc
'tag-bans':['style','b'], //<i> allowed for font-awesome
'doctype-first':true,
'doctype-html5':true,
'html-req-lang':true,
'attr-name-style': false, //for meta tags
'line-end-style':false, //either way
'indent-style':false, //can mix/match
'indent-width':false, //don't need to beautify
'line-no-trailing-whitespace': false, //don't need to beautify
'id-class-style':false, //I like dashes in classnames
'id-class-no-ad': false, //stupid rule
'img-req-alt':true,
'link-req-noopener':false,
'spec-char-escape':false, //for params in link urls
}
const htmlfiles = fs.readdirSync(__dirname).filter((f) => f.endsWith('.html'));
for(let f of htmlfiles) {
await expect(f).toHaveNoHtmlLintErrorsAsync(lintOpts);
}
})
test('CSS validates without errors', async () => {
await expect('css/*.css').toHaveNoCssLintErrorsAsync(); //test all files in css folder
})
test('JavaScript lints without errors', () => {
if(fs.existsSync(__dirname+'/js')) {
const jsfiles = fs.readdirSync(__dirname+'/js').filter((f) => f.endsWith('.js'));
for(let f of jsfiles) {
expect(['js/'+f]).toHaveNoEsLintErrors();
}
}
})
});