Skip to content

Commit 613849c

Browse files
committed
Split tests
1 parent 49a3890 commit 613849c

4 files changed

Lines changed: 43 additions & 30 deletions

File tree

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
"node": ">=12"
1717
},
1818
"scripts": {
19-
"mocha": "mocha",
19+
"mocha": "mocha -i --fgrep=server",
2020
"lint": "xo",
2121
"fix": "xo --fix",
2222
"test": "npm run lint && npm run mocha",
2323
"test:grunt": "grunt ci --force",
24-
"test:ci": "npm run test:server && npm run test:grunt",
24+
"test:ci": "npm run mocha && npm run test:server && npm run test:grunt",
2525
"test:coverage": "c8 npm run test:ci",
26-
"test:server": "start-server-and-test start:server http://localhost:8888 mocha",
26+
"test:server": "start-server-and-test start:server http://localhost:8888 \"mocha --fgrep=server\"",
2727
"start:server": "java -cp ./node_modules/vnu-jar/build/dist/vnu.jar nu.validator.servlet.Main"
2828
},
2929
"dependencies": {

test/helpers/run.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
const assert = require('assert').strict;
4+
const htmllint = require('../../lib/htmllint.js');
5+
6+
function run(config, expected, message, done) {
7+
htmllint(config, (error, result) => {
8+
if (error) {
9+
throw error;
10+
}
11+
12+
// Only keep the properties we want to test;
13+
// the url property is an absolute, system-dependent path
14+
const newResult = result.map(({ file, type, message, lastLine, lastColumn }) => ({ file, type, message, lastLine, lastColumn }));
15+
assert.deepEqual(newResult, expected, message);
16+
done();
17+
});
18+
}
19+
20+
module.exports = run;

test/html_test.js

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,9 @@
11
'use strict';
22

3-
const assert = require('assert').strict;
43
const fs = require('fs');
54
const path = require('path');
6-
const htmllint = require('../lib/htmllint.js');
75
const expectedResults = require('./helpers/expected_results.js');
8-
9-
function run(config, expected, message, done) {
10-
htmllint(config, (error, result) => {
11-
if (error) {
12-
throw error;
13-
}
14-
15-
// Only keep the properties we want to test;
16-
// the url property is an absolute, system-dependent path
17-
const newResult = result.map(({ file, type, message, lastLine, lastColumn }) => ({ file, type, message, lastLine, lastColumn }));
18-
assert.deepEqual(newResult, expected, message);
19-
done();
20-
});
21-
}
6+
const run = require('./helpers/run.js');
227

238
describe('htmllint', () => {
249
describe('all', () => {
@@ -32,17 +17,6 @@ describe('htmllint', () => {
3217
run(options, expected, 'four errors from test/fixtures/invalid.html', done);
3318
});
3419

35-
it('with relative paths using server', done => {
36-
const options = {
37-
files: ['test/fixtures/valid.html', 'test/fixtures/invalid.html'],
38-
server: {},
39-
errorlevels: ['info', 'warning', 'error']
40-
};
41-
const expected = expectedResults.server.invalid;
42-
43-
run(options, expected, 'four errors from test/fixtures/invalid.html', done);
44-
});
45-
4620
it('with absolute paths', done => {
4721
const options = {
4822
files: ['test/fixtures/valid.html', 'test/fixtures/invalid.html'],

test/server_test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
3+
const expectedResults = require('./helpers/expected_results.js');
4+
const run = require('./helpers/run.js');
5+
6+
describe('htmllint', () => {
7+
describe('server', () => {
8+
it('with relative paths using server', done => {
9+
const options = {
10+
files: ['test/fixtures/valid.html', 'test/fixtures/invalid.html'],
11+
server: {},
12+
errorlevels: ['info', 'warning', 'error']
13+
};
14+
const expected = expectedResults.server.invalid;
15+
16+
run(options, expected, 'four errors from test/fixtures/invalid.html', done);
17+
});
18+
});
19+
});

0 commit comments

Comments
 (0)