Skip to content

Commit 159b0ae

Browse files
committed
Inline test files
1 parent c60a882 commit 159b0ae

2 files changed

Lines changed: 45 additions & 37 deletions

File tree

test/helpers/rule-test-harness.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// https://github.com/ember-template-lint/ember-template-lint/blob/v1.3.0/lib/helpers/rule-test-harness.js
33
const plugin = require("../../ember-template-lint-plugin-prettier");
44

5-
const fs = require("fs");
65
const assert = require("assert");
76

87
const Linter = require("ember-template-lint");
@@ -30,8 +29,7 @@ function generateRuleTests({
3029
groupingMethod(name, function() {
3130
let linter, config, meta;
3231

33-
function verify(path) {
34-
const template = fs.readFileSync(path, { encoding: "utf8" });
32+
function verify(template) {
3533
linter.config.rules[name] = config;
3634
return linter.verify({ source: template, moduleId: meta.moduleId });
3735
}
@@ -69,10 +67,10 @@ function generateRuleTests({
6967
}
7068

7169
bad.forEach(function(badItem) {
72-
let path = badItem.path;
70+
let template = badItem.template;
7371

7472
testMethod(
75-
`logs a message in the console when given \`${path}\``,
73+
`logs a message in the console when given \`${template}\``,
7674
function() {
7775
let expectedResults = badItem.results || [badItem.result];
7876

@@ -82,7 +80,7 @@ function generateRuleTests({
8280
config = badItem.config;
8381
}
8482

85-
let actual = verify(path);
83+
let actual = verify(template);
8684

8785
if (badItem.fatal) {
8886
assert.strictEqual(actual.length, 1); // can't have more than one fatal error
@@ -97,20 +95,23 @@ function generateRuleTests({
9795
);
9896

9997
if (!skipDisabledTests) {
100-
testMethod(`passes with \`${path}\` when rule is disabled`, function() {
101-
config = false;
102-
meta = parseMeta(badItem);
103-
let actual = verify(path);
104-
105-
assert.deepStrictEqual(actual, []);
106-
});
98+
testMethod(
99+
`passes with \`${template}\` when rule is disabled`,
100+
function() {
101+
config = false;
102+
meta = parseMeta(badItem);
103+
let actual = verify(template);
104+
105+
assert.deepStrictEqual(actual, []);
106+
}
107+
);
107108
}
108109
});
109110

110111
good.forEach(function(goodItem) {
111-
let path = goodItem.path;
112+
let template = goodItem.template;
112113

113-
testMethod(`passes when given \`${path}\``, function() {
114+
testMethod(`passes when given \`${template}\``, function() {
114115
meta = parseMeta(goodItem);
115116
let actual;
116117

@@ -121,7 +122,7 @@ function generateRuleTests({
121122
config = goodItem.config;
122123
}
123124

124-
actual = verify(path);
125+
actual = verify(template);
125126
}
126127

127128
assert.deepStrictEqual(actual, []);

test/unit/rules/lint-prettier-test.js

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,25 @@ generateRuleTests({
44
name: "prettier",
55

66
good: [
7-
{
8-
config: true,
9-
path: "test/unit/files/valid/empty.hbs"
10-
},
11-
{
12-
config: true,
13-
path: "test/unit/files/invalid/block-disabled-one.hbs"
14-
},
15-
{
16-
config: true,
17-
path: "test/unit/files/invalid/block-disabled-all.hbs"
18-
}
7+
``,
8+
`{{! template-lint-disable prettier}}
9+
{{#my-component}}
10+
11+
test
12+
13+
{{/my-component}}`,
14+
`{{! template-lint-disable }}
15+
{{#my-component}}
16+
17+
test
18+
19+
{{/my-component}}`
1920
],
2021

2122
bad: [
2223
{
2324
config: true,
24-
path: "test/unit/files/valid/dummy.hbs",
25+
template: "{{#my-component}}{{/my-component}}\n",
2526
result: {
2627
moduleId: "layout.hbs",
2728
message: "Delete `⏎`",
@@ -32,7 +33,7 @@ generateRuleTests({
3233
},
3334
{
3435
config: true,
35-
path: "test/unit/files/valid/block.hbs",
36+
template: "test\n",
3637
result: {
3738
moduleId: "layout.hbs",
3839
message: "Delete `⏎`",
@@ -43,26 +44,32 @@ generateRuleTests({
4344
},
4445
{
4546
config: true,
46-
path: "test/unit/files/invalid/block.hbs",
47+
template: `{{#my-component}}
48+
49+
test
50+
51+
{{/my-component}}`,
4752
result: {
4853
moduleId: "layout.hbs",
49-
message:
50-
"Replace `⏎⏎test⏎⏎{{/my-component}}⏎` with `test{{/my-component}}`",
54+
message: "Replace `⏎⏎test⏎⏎` with `test`",
5155
line: 1,
5256
column: 17,
53-
source: "{{#my-component}}\n\ntest\n\n{{/my-component}}\n"
57+
source: "{{#my-component}}\n\ntest\n\n{{/my-component}}"
5458
}
5559
},
5660
{
5761
config: true,
58-
path: "test/unit/files/invalid/lines.hbs",
62+
template: `{{#my-component class="class1 class2"}}
63+
test
64+
65+
{{/my-component}}`,
5966
result: {
6067
moduleId: "layout.hbs",
61-
message: "Replace `⏎{{/my-component}}⏎` with `{{/my-component}}`",
68+
message: "Delete `⏎`",
6269
line: 2,
6370
column: 7,
6471
source:
65-
'{{#my-component class="class1 class2"}}\n test\n\n{{/my-component}}\n'
72+
'{{#my-component class="class1 class2"}}\n test\n\n{{/my-component}}'
6673
}
6774
}
6875
]

0 commit comments

Comments
 (0)