Welcome to mirror list, hosted at ThFree Co, Russian Federation.

bootlint_test.js « test - github.com/twbs/grunt-bootlint.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 56b7fbbb1c617a962ecc3205e8cbc8649631b575 (plain)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
'use strict';

const grunt = require('grunt');

/*
  ======== 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 = {
  defaultOptions(test) {
    test.expect(4);
    grunt.util.spawn({
      grunt: true,
      args: ['bootlint:defaultOptions', '--no-color']
    }, (err, result) => {
      test.strictEqual(err, null);
      test.ok(result.stdout.includes('test/fixtures/missing-doctype.html'),
        'Should print file path');
      test.ok(result.stdout.includes('Document is missing a DOCTYPE declaration'),
        'Should warn about missing a DOCTYPE');
      test.ok(result.stdout.includes('9 lint errors found across 5 files'),
        'Should print number of lint errors and files');
      test.done();
    });
  },
  relaxerror(test) {
    test.expect(5);
    grunt.util.spawn({
      grunt: true,
      args: ['bootlint:relaxerror', '--no-color']
    }, (err, result) => {
      test.strictEqual(err, null);
      test.ok(!result.stdout.includes('E001'),
        'Should not warn about missing a DOCTYPE');
      test.ok(result.stdout.includes('W001'),
        'Should warn about missing charset');
      test.ok(!result.stdout.includes('W005'),
        'Should not warn about missing jQuery');
      test.ok(result.stdout.includes('1 lint error found across 3 files'),
        'Should print correct number of lint errors and files');
      test.done();
    });
  },
  stoponerror(test) {
    test.expect(3);
    grunt.util.spawn({
      grunt: true,
      args: ['bootlint:stoponerror', '--no-color']
    }, (err, result) => {
      test.throws(err);
      test.ok(result.stdout.includes('E001'),
        'Should warn about missing a DOCTYPE');
      test.ok(!result.stdout.includes('W001'),
        'Should not warn about anything after E001');
      test.done();
    });
  },
  stoponwarning(test) {
    test.expect(4);
    grunt.util.spawn({
      grunt: true,
      args: ['bootlint:stoponwarning', '--no-color']
    }, (err, result) => {
      test.throws(err);
      test.ok(result.stdout.includes('E001'),
        'Should display error of missing a DOCTYPE');
      test.ok(result.stdout.includes('W001'),
        'Should warn about W001');
      test.ok(!result.stdout.includes('E029'),
        'Should not warn about anything after W001');
      test.done();
    });
  },
  stoponboth(test) {
    test.expect(2);
    grunt.util.spawn({
      grunt: true,
      args: ['bootlint:stoponboth', '--no-color']
    }, (err, result) => {
      test.throws(err);
      test.ok(!result.stdout.includes('E001'),
        'Should not warn about E001');
      test.done();
    });
  },
  showallerrors(test) {
    test.expect(2);
    grunt.util.spawn({
      grunt: true,
      args: ['bootlint:showallerrors', '--no-color']
    }, (err, result) => {
      test.throws(err);
      test.ok(result.stdout.includes('8 lint errors found across 3 files. Use --force to continue.'),
        'Should show all errors before hard fail.');
      test.done();
    });
  },
  showallerrorswithstop(test) {
    test.expect(2);
    grunt.util.spawn({
      grunt: true,
      args: ['bootlint:showallerrorswithstop', '--no-color']
    }, (err, result) => {
      test.throws(err);
      test.ok(result.stdout.includes('8 lint errors found across 3 files. Use --force to continue.'),
        'Should show all errors before hard fail even if stopon* is set.');
      test.done();
    });
  },
  pass(test) {
    test.expect(2);
    grunt.util.spawn({
      grunt: true,
      args: ['bootlint:pass', '--no-color']
    }, (err, result) => {
      test.strictEqual(err, null);
      test.ok(result.stdout.includes('1 file lint free.'),
        'Should print correct number of lint free files');
      test.done();
    });
  }
};