Skip to content

Commit 07c4b8b

Browse files
authored
test: fix RuleTester test without test runners (#20631)
* test: fix `RuleTester` test without test runners * account for different message in Node.js v20
1 parent 7143dbf commit 07c4b8b

File tree

3 files changed

+49
-45
lines changed

3 files changed

+49
-45
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @fileoverview Tests for RuleTester without any test runner
3+
* @author Weijia Wang <starkwang@126.com>
4+
*/
5+
"use strict";
6+
7+
const assert = require("node:assert");
8+
const { RuleTester } = require("../../../../lib/rule-tester");
9+
10+
const ruleTester = new RuleTester();
11+
12+
assert.throws(
13+
() => {
14+
ruleTester.run("no-var", require("./no-var"), {
15+
valid: ["bar = baz;"],
16+
invalid: [
17+
{
18+
code: "var foo = bar;",
19+
output: "invalid output",
20+
errors: 1,
21+
},
22+
],
23+
});
24+
},
25+
{
26+
constructor: assert.AssertionError,
27+
actual: " foo = bar;",
28+
expected: "invalid output",
29+
operator: "strictEqual",
30+
message: process.version.startsWith("v20.")
31+
? "Output is incorrect.\n+ actual - expected\n\n+ ' foo = bar;'\n- 'invalid output' (' foo = bar;' strictEqual 'invalid output')"
32+
: "Output is incorrect.\n+ actual - expected\n\n+ ' foo = bar;'\n- 'invalid output'\n (' foo = bar;' strictEqual 'invalid output')",
33+
},
34+
);

tests/lib/rule-tester/no-test-runners.js

Lines changed: 0 additions & 45 deletions
This file was deleted.

tests/lib/rule-tester/rule-tester.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4489,6 +4489,21 @@ describe("RuleTester", () => {
44894489
}, /A fatal parsing error occurred in autofix.\nError: .+\nAutofix output:\n.+/u);
44904490
});
44914491

4492+
it("should throw an error with expected message without a test runner", done => {
4493+
const { execFile } = require("node:child_process");
4494+
4495+
execFile(
4496+
process.execPath,
4497+
[
4498+
require.resolve(
4499+
"../../fixtures/testers/rule-tester/no-test-runners",
4500+
),
4501+
],
4502+
{ timeout: 1000 },
4503+
done,
4504+
);
4505+
});
4506+
44924507
describe("type checking", () => {
44934508
it('should throw if "only" property is not a boolean', () => {
44944509
// "only" has to be falsy as itOnly is not mocked for all test cases

0 commit comments

Comments
 (0)