This repository was archived by the owner on Aug 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathbroccoli-test.js
More file actions
252 lines (189 loc) · 9.9 KB
/
broccoli-test.js
File metadata and controls
252 lines (189 loc) · 9.9 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
'use strict';
const co = require('co');
const expect = require('chai').expect;
const broccoliTestHelper = require('broccoli-test-helper');
const { fromBuilder, createTempDir } = broccoliTestHelper;
const TemplateLinter = require('../../broccoli-template-linter');
const fixturePath = `${__dirname}/../fixtures`;
describe('broccoli-template-linter', function() {
this.timeout(10000);
let input, output, subject, mockConsole;
function createBuilder(node) {
const Builder = require("broccoli").Builder;
return fromBuilder(new Builder(node));
}
beforeEach(co.wrap(function *() {
input = yield createTempDir();
mockConsole = buildFakeConsole();
}));
afterEach(co.wrap(function *() {
yield input.dispose();
yield output.dispose();
}));
function buildFakeConsole() {
return {
_logLines: [],
log(data) {
this._logLines.push(data);
}
};
}
it('generates a QUnit test file if "testGenerator: qunit" is provided', co.wrap(function *() {
input.copy(`${fixturePath}/with-errors`);
subject = TemplateLinter.create(`${input.path()}/app`, {
console: mockConsole,
testGenerator: 'qunit'
});
output = createBuilder(subject);
yield output.build();
let result = output.read();
expect(result).to.have.property('templates');
expect(result.templates).to.have.property('application.template.lint-test.js');
let contents = result.templates['application.template.lint-test.js'];
expect(contents).to.equal("QUnit.module('TemplateLint | templates/application.hbs');\nQUnit.test('should pass TemplateLint', function(assert) {\n assert.expect(1);\n assert.ok(false, 'templates/application.hbs should pass TemplateLint.\\n\\ntemplates/application.hbs\\n 5:9 error Incorrect indentation for `div` beginning at L2:C0. Expected `</div>` ending at L5:C9 to be at an indentation of 0 but was found at 3. block-indentation\\n 4:5 error Incorrect indentation for `p` beginning at L3:C2. Expected `</p>` ending at L4:C5 to be at an indentation of 2 but was found at 1. block-indentation\\n 1:0 error HTML comment detected no-html-comments\\n');\n});\n");
}));
it('generates a Mocha test file if "testGenerator: mocha" is provided', co.wrap(function *() {
input.copy(`${fixturePath}/with-errors`);
subject = TemplateLinter.create(`${input.path()}/app`, {
console: mockConsole,
testGenerator: 'mocha'
});
output = createBuilder(subject);
yield output.build();
let result = output.read();
expect(result).to.have.property('templates');
expect(result.templates).to.have.property('application.template.lint-test.js');
let contents = result.templates['application.template.lint-test.js'];
expect(contents).to.equal("describe('TemplateLint | templates/application.hbs', function() {\n it('should pass TemplateLint', function() {\n // test failed\n var error = new chai.AssertionError('templates/application.hbs should pass TemplateLint.\\n\\ntemplates/application.hbs\\n 5:9 error Incorrect indentation for `div` beginning at L2:C0. Expected `</div>` ending at L5:C9 to be at an indentation of 0 but was found at 3. block-indentation\\n 4:5 error Incorrect indentation for `p` beginning at L3:C2. Expected `</p>` ending at L4:C5 to be at an indentation of 2 but was found at 1. block-indentation\\n 1:0 error HTML comment detected no-html-comments\\n');\n error.stack = undefined;\n throw error;\n });\n});\n");
}));
it('generates a QUnit test file if "testGenerator: qunit" and "groupName: foo" are provided', co.wrap(function *() {
this.timeout(10000);
input.copy(`${fixturePath}/with-errors`);
subject = TemplateLinter.create(`${input.path()}/app`, {
console: mockConsole,
testGenerator: 'qunit',
groupName: 'foo'
});
output = createBuilder(subject);
yield output.build();
let result = output.read();
expect(result).to.have.property('foo.template.lint-test.js');
let contents = result['foo.template.lint-test.js'];
expect(contents.trim()).to.equal("QUnit.module('TemplateLint | foo');\n\nQUnit.test('templates/application.hbs', function(assert) {\n assert.expect(1);\n assert.ok(false, 'templates/application.hbs should pass TemplateLint.\\n\\ntemplates/application.hbs\\n 5:9 error Incorrect indentation for `div` beginning at L2:C0. Expected `</div>` ending at L5:C9 to be at an indentation of 0 but was found at 3. block-indentation\\n 4:5 error Incorrect indentation for `p` beginning at L3:C2. Expected `</p>` ending at L4:C5 to be at an indentation of 2 but was found at 1. block-indentation\\n 1:0 error HTML comment detected no-html-comments\\n');\n});");
}));
it('generates a Mocha test file if "testGenerator: mocha" and "groupName: foo" are provided', co.wrap(function *() {
input.copy(`${fixturePath}/with-errors`);
subject = TemplateLinter.create(`${input.path()}/app`, {
console: mockConsole,
testGenerator: 'mocha',
groupName: 'foo'
});
output = createBuilder(subject);
yield output.build();
let result = output.read();
expect(result).to.have.property('foo.template.lint-test.js');
let contents = result['foo.template.lint-test.js'];
expect(contents.trim()).to.equal("describe('TemplateLint | foo', function() {\n\n it('templates/application.hbs', function() {\n // test failed\n var error = new chai.AssertionError('templates/application.hbs should pass TemplateLint.\\n\\ntemplates/application.hbs\\n 5:9 error Incorrect indentation for `div` beginning at L2:C0. Expected `</div>` ending at L5:C9 to be at an indentation of 0 but was found at 3. block-indentation\\n 4:5 error Incorrect indentation for `p` beginning at L3:C2. Expected `</p>` ending at L4:C5 to be at an indentation of 2 but was found at 1. block-indentation\\n 1:0 error HTML comment detected no-html-comments\\n');\n error.stack = undefined;\n throw error;\n });\n\n});");
}));
it('generates empty test files if no "generateTestFile" option is provided', co.wrap(function *() {
input.copy(`${fixturePath}/with-errors`);
subject = TemplateLinter.create(`${input.path()}/app`, {
console: mockConsole
});
output = createBuilder(subject);
yield output.build();
let result = output.read();
expect(result).to.have.property('templates');
expect(result.templates).to.have.property('application.template.lint-test.js');
let contents = result.templates['application.template.lint-test.js'];
expect(contents).to.equal('');
}));
it('prints warnings to console', co.wrap(function *() {
input.copy(`${fixturePath}/with-errors`);
subject = TemplateLinter.create(`${input.path()}/app`, {
persist: false, // console messages are only printed when initially processed
console: mockConsole
});
output = createBuilder(subject);
yield output.build();
let combinedLog = mockConsole._logLines.join('\n');
expect(combinedLog).to.contain('Incorrect indentation for `div`');
expect(combinedLog).to.contain('Incorrect indentation for `p`');
expect(combinedLog).to.contain('HTML comment detected');
}));
it('prints warnings when no-bare-strings is not used with a localization addon present', co.wrap(function *() {
input.copy(`${fixturePath}/no-bare-strings`);
let localizationAddon = {
name: 'ember-intl',
isLocalizationFramework: true
};
subject = TemplateLinter.create(`${input.path()}/app`, {
console: mockConsole,
project: {
addons: [
{ name: 'ember-cli-qunit' },
{ name: 'ember-cli-template-lint' },
localizationAddon
]
}
});
output = createBuilder(subject);
yield output.build();
let combinedLog = mockConsole._logLines.join('\n');
expect(combinedLog).to.contain('ember-intl');
expect(combinedLog).to.contain('The `no-bare-strings` rule must be configured when using a localization framework');
}));
it('does not print warning when no-bare-strings is not used when a localization addon is not present', co.wrap(function *() {
input.copy(`${fixturePath}/no-bare-strings`);
subject = TemplateLinter.create(`${input.path()}/app`, {
console: mockConsole,
project: {
addons: [
{ name: 'ember-cli-qunit' },
{ name: 'ember-cli-template-lint' }
]
}
});
output = createBuilder(subject);
yield output.build();
let combinedLog = mockConsole._logLines.join('\n');
expect(combinedLog)
.to.not.contain('The `no-bare-strings` rule must be configured when using a localization framework');
}));
it('does not print warning when no-bare-strings is specified in config', co.wrap(function *() {
input.copy(`${fixturePath}/with-bare-strings`);
// broccoliTestHelpers.makeTestHelper does a chdir, but after instantiation
process.chdir(input.path());
let localizationAddon = {
name: 'ember-intl',
isLocalizationFramework: true
};
subject = TemplateLinter.create(`${input.path()}/app`, {
console: mockConsole,
project: {
addons: [
{ name: 'ember-cli-qunit' },
{ name: 'ember-cli-template-lint' },
localizationAddon
]
}
});
output = createBuilder(subject);
yield output.build();
let combinedLog = mockConsole._logLines.join('\n');
expect(combinedLog)
.to.not.contain('The `no-bare-strings` rule must be configured when using a localization framework');
}));
it('generates tests for .handlebars files', co.wrap(function *() {
input.copy(`${fixturePath}/handlebars-extension`);
subject = TemplateLinter.create(`${input.path()}/app`, {
console: mockConsole,
testGenerator: 'qunit'
});
output = createBuilder(subject);
yield output.build();
let result = output.read();
expect(result).to.have.property('templates');
expect(result.templates).to.have.property('application.template.lint-test.js');
}));
});