Skip to content

Commit 7a3dd48

Browse files
committed
test: make failures more clear/actionable in rule setup tests
1 parent da9754b commit 7a3dd48

File tree

1 file changed

+42
-37
lines changed

1 file changed

+42
-37
lines changed

tests/rule-setup.js

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe('rules setup is correct', function () {
7878
);
7979
});
8080

81-
it('should have the right contents (title, examples, notices) for each rule documentation file', function () {
81+
describe('rule documentation files', function () {
8282
const CONFIG_MSG_RECOMMENDED =
8383
':white_check_mark: The `"extends": "plugin:ember/recommended"` property in a configuration file enables this rule.';
8484
const CONFIG_MSG_OCTANE =
@@ -92,42 +92,47 @@ describe('rules setup is correct', function () {
9292
const path = join(__dirname, '..', 'docs', 'rules', `${ruleName}.md`);
9393
const file = readFileSync(path, 'utf8');
9494

95-
expect(file).toContain(`# ${ruleName}`); // Title header.
96-
expect(file).toContain('## Examples'); // Examples section header.
97-
98-
// Check if the rule has configuration options.
99-
if (
100-
(Array.isArray(rule.meta.schema) && rule.meta.schema.length > 0) ||
101-
(typeof rule.meta.schema === 'object' && Object.keys(rule.meta.schema).length > 0)
102-
) {
103-
// Should have a configuration section header:
104-
expect(file).toContain('## Configuration');
105-
106-
// Ensure all configuration options are mentioned.
107-
getAllNamedOptions(rule.meta.schema).forEach((namedOption) =>
108-
expect(file).toContain(namedOption)
109-
);
110-
} else {
111-
expect(file).not.toContain('## Configuration');
112-
}
113-
114-
if (rule.meta.fixable === 'code') {
115-
expect(file).toContain(FIXABLE_MSG);
116-
} else {
117-
expect(file).not.toContain(FIXABLE_MSG);
118-
}
119-
120-
if (rule.meta.docs.recommended) {
121-
expect(file).toContain(CONFIG_MSG_RECOMMENDED);
122-
} else {
123-
expect(file).not.toContain(CONFIG_MSG_RECOMMENDED);
124-
}
125-
126-
if (rule.meta.docs.octane) {
127-
expect(file).toContain(CONFIG_MSG_OCTANE);
128-
} else {
129-
expect(file).not.toContain(CONFIG_MSG_OCTANE);
130-
}
95+
// eslint-disable-next-line jest/valid-title
96+
describe(ruleName, function () {
97+
it('should have the right contents (title, examples, notices)', function () {
98+
expect(file).toContain(`# ${ruleName}`); // Title header.
99+
expect(file).toContain('## Examples'); // Examples section header.
100+
101+
// Check if the rule has configuration options.
102+
if (
103+
(Array.isArray(rule.meta.schema) && rule.meta.schema.length > 0) ||
104+
(typeof rule.meta.schema === 'object' && Object.keys(rule.meta.schema).length > 0)
105+
) {
106+
// Should have a configuration section header:
107+
expect(file).toContain('## Configuration');
108+
109+
// Ensure all configuration options are mentioned.
110+
getAllNamedOptions(rule.meta.schema).forEach((namedOption) =>
111+
expect(file).toContain(namedOption)
112+
);
113+
} else {
114+
expect(file).not.toContain('## Configuration');
115+
}
116+
117+
if (rule.meta.fixable === 'code') {
118+
expect(file).toContain(FIXABLE_MSG);
119+
} else {
120+
expect(file).not.toContain(FIXABLE_MSG);
121+
}
122+
123+
if (rule.meta.docs.recommended) {
124+
expect(file).toContain(CONFIG_MSG_RECOMMENDED);
125+
} else {
126+
expect(file).not.toContain(CONFIG_MSG_RECOMMENDED);
127+
}
128+
129+
if (rule.meta.docs.octane) {
130+
expect(file).toContain(CONFIG_MSG_OCTANE);
131+
} else {
132+
expect(file).not.toContain(CONFIG_MSG_OCTANE);
133+
}
134+
});
135+
});
131136
});
132137
});
133138

0 commit comments

Comments
 (0)