grunt-bootlint/test/bootlint_test.js

139 строки
4.2 KiB
JavaScript
Исходник Постоянная ссылка Обычный вид История

2014-07-26 08:48:19 +04:00
'use strict';
2018-07-10 03:12:38 +03:00
const grunt = require('grunt');
2014-07-26 08:48:19 +04:00
/*
======== A Handy Little Nodeunit Reference ========
https://github.com/caolan/nodeunit
Test methods:
test.expect(numAssertions)
test.done()
Test assertions:
test.ok(value, [message])
test.equal(actual, expected, [message])
test.notEqual(actual, expected, [message])
test.deepEqual(actual, expected, [message])
test.notDeepEqual(actual, expected, [message])
test.strictEqual(actual, expected, [message])
test.notStrictEqual(actual, expected, [message])
test.throws(block, [error], [message])
test.doesNotThrow(block, [error], [message])
test.ifError(value)
*/
exports.bootlint = {
2018-07-10 03:12:38 +03:00
defaultOptions(test) {
2019-01-10 18:00:59 +03:00
test.expect(4);
2014-08-19 21:48:10 +04:00
grunt.util.spawn({
grunt: true,
2015-11-16 18:56:08 +03:00
args: ['bootlint:defaultOptions', '--no-color']
2018-07-10 03:12:38 +03:00
}, (err, result) => {
2019-01-10 18:00:59 +03:00
test.strictEqual(err, null);
2018-07-10 03:12:38 +03:00
test.ok(result.stdout.includes('test/fixtures/missing-doctype.html'),
2014-08-19 21:48:10 +04:00
'Should print file path');
2018-07-10 03:12:38 +03:00
test.ok(result.stdout.includes('Document is missing a DOCTYPE declaration'),
2014-08-19 21:48:10 +04:00
'Should warn about missing a DOCTYPE');
2018-07-10 03:12:38 +03:00
test.ok(result.stdout.includes('9 lint errors found across 5 files'),
'Should print number of lint errors and files');
2014-08-19 21:48:10 +04:00
test.done();
});
2014-07-26 08:48:19 +04:00
},
2018-07-10 03:12:38 +03:00
relaxerror(test) {
2019-01-10 18:00:59 +03:00
test.expect(5);
2014-08-19 21:48:10 +04:00
grunt.util.spawn({
grunt: true,
2015-11-16 18:56:08 +03:00
args: ['bootlint:relaxerror', '--no-color']
2018-07-10 03:12:38 +03:00
}, (err, result) => {
2019-01-10 18:00:59 +03:00
test.strictEqual(err, null);
2018-07-10 03:12:38 +03:00
test.ok(!result.stdout.includes('E001'),
2014-08-19 21:48:10 +04:00
'Should not warn about missing a DOCTYPE');
2018-07-10 03:12:38 +03:00
test.ok(result.stdout.includes('W001'),
2014-11-14 23:51:46 +03:00
'Should warn about missing charset');
2018-07-10 03:12:38 +03:00
test.ok(!result.stdout.includes('W005'),
'Should not warn about missing jQuery');
2018-07-10 03:12:38 +03:00
test.ok(result.stdout.includes('1 lint error found across 3 files'),
'Should print correct number of lint errors and files');
2014-08-19 21:48:10 +04:00
test.done();
});
2014-11-10 20:38:10 +03:00
},
2018-07-10 03:12:38 +03:00
stoponerror(test) {
2019-01-10 18:00:59 +03:00
test.expect(3);
2014-11-14 23:51:46 +03:00
grunt.util.spawn({
grunt: true,
2015-11-16 18:56:08 +03:00
args: ['bootlint:stoponerror', '--no-color']
2018-07-10 03:12:38 +03:00
}, (err, result) => {
2019-01-10 18:00:59 +03:00
test.throws(err);
2018-07-10 03:12:38 +03:00
test.ok(result.stdout.includes('E001'),
2014-11-14 23:51:46 +03:00
'Should warn about missing a DOCTYPE');
2018-07-10 03:12:38 +03:00
test.ok(!result.stdout.includes('W001'),
2014-11-14 23:51:46 +03:00
'Should not warn about anything after E001');
test.done();
});
},
2018-07-10 03:12:38 +03:00
stoponwarning(test) {
2019-01-10 18:00:59 +03:00
test.expect(4);
2014-11-14 23:51:46 +03:00
grunt.util.spawn({
grunt: true,
2015-11-16 18:56:08 +03:00
args: ['bootlint:stoponwarning', '--no-color']
2018-07-10 03:12:38 +03:00
}, (err, result) => {
2019-01-10 18:00:59 +03:00
test.throws(err);
2018-07-10 03:12:38 +03:00
test.ok(result.stdout.includes('E001'),
2014-11-14 23:51:46 +03:00
'Should display error of missing a DOCTYPE');
2018-07-10 03:12:38 +03:00
test.ok(result.stdout.includes('W001'),
2014-11-14 23:51:46 +03:00
'Should warn about W001');
2018-07-10 03:12:38 +03:00
test.ok(!result.stdout.includes('E029'),
2014-11-14 23:51:46 +03:00
'Should not warn about anything after W001');
test.done();
});
},
2018-07-10 03:12:38 +03:00
stoponboth(test) {
2019-01-10 18:00:59 +03:00
test.expect(2);
2014-11-14 23:51:46 +03:00
grunt.util.spawn({
grunt: true,
2015-11-16 18:56:08 +03:00
args: ['bootlint:stoponboth', '--no-color']
2018-07-10 03:12:38 +03:00
}, (err, result) => {
2019-01-10 18:00:59 +03:00
test.throws(err);
2018-07-10 03:12:38 +03:00
test.ok(!result.stdout.includes('E001'),
2014-11-14 23:51:46 +03:00
'Should not warn about E001');
test.done();
});
},
2018-07-10 03:12:38 +03:00
showallerrors(test) {
2019-01-10 18:00:59 +03:00
test.expect(2);
2014-11-18 00:18:18 +03:00
grunt.util.spawn({
grunt: true,
2015-11-16 18:56:08 +03:00
args: ['bootlint:showallerrors', '--no-color']
2018-07-10 03:12:38 +03:00
}, (err, result) => {
2019-01-10 18:00:59 +03:00
test.throws(err);
2018-07-10 03:12:38 +03:00
test.ok(result.stdout.includes('8 lint errors found across 3 files. Use --force to continue.'),
2014-11-18 00:18:18 +03:00
'Should show all errors before hard fail.');
test.done();
});
},
2018-07-10 03:12:38 +03:00
showallerrorswithstop(test) {
2019-01-10 18:00:59 +03:00
test.expect(2);
2014-11-18 00:18:18 +03:00
grunt.util.spawn({
grunt: true,
2015-11-16 18:56:08 +03:00
args: ['bootlint:showallerrorswithstop', '--no-color']
2018-07-10 03:12:38 +03:00
}, (err, result) => {
2019-01-10 18:00:59 +03:00
test.throws(err);
2018-07-10 03:12:38 +03:00
test.ok(result.stdout.includes('8 lint errors found across 3 files. Use --force to continue.'),
2014-11-18 00:18:18 +03:00
'Should show all errors before hard fail even if stopon* is set.');
test.done();
});
},
2018-07-10 03:12:38 +03:00
pass(test) {
2019-01-10 18:00:59 +03:00
test.expect(2);
2014-11-10 20:38:10 +03:00
grunt.util.spawn({
grunt: true,
2015-11-16 18:56:08 +03:00
args: ['bootlint:pass', '--no-color']
2018-07-10 03:12:38 +03:00
}, (err, result) => {
2019-01-10 18:00:59 +03:00
test.strictEqual(err, null);
2018-07-10 03:12:38 +03:00
test.ok(result.stdout.includes('1 file lint free.'),
2014-11-10 20:38:10 +03:00
'Should print correct number of lint free files');
test.done();
});
}
2014-07-26 08:48:19 +04:00
};