Skip to content

Commit 2bb2c07

Browse files
committed
moving test second format into it's own file
1 parent a74f4bf commit 2bb2c07

2 files changed

Lines changed: 29 additions & 19 deletions

File tree

tests/config/run-test.js

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { format, parse } from "./run-prettier.js";
66
import consistentEndOfLine from "./utils/consistent-end-of-line.js";
77
import createSnapshot from "./utils/create-snapshot.js";
88
import visualizeEndOfLine from "./utils/visualize-end-of-line.js";
9+
import * as testSecondFormat from "./test-second-format.js";
910
import { shouldThrowOnFormat } from "./utilities.js";
1011
import getPrettier from "./get-prettier.js";
1112
import getCreateParser from "./get-create-parser.js";
@@ -125,25 +126,7 @@ async function runTest({
125126
}
126127
}
127128

128-
const isUnstableTest = failedTests.isUnstable(filename, formatOptions);
129-
if (
130-
(formatResult.changed || isUnstableTest) &&
131-
// No range and cursor
132-
formatResult.input === code
133-
) {
134-
const { eolVisualizedOutput: firstOutput, output } = formatResult;
135-
const { eolVisualizedOutput: secondOutput } = await format(
136-
output,
137-
formatOptions,
138-
);
139-
if (isUnstableTest) {
140-
// To keep eye on failed tests, this assert never supposed to pass,
141-
// if it fails, just remove the file from `unstableTests`
142-
expect(secondOutput).not.toEqual(firstOutput);
143-
} else {
144-
expect(secondOutput).toEqual(firstOutput);
145-
}
146-
}
129+
testSecondFormat.run(code, formatResult, filename, formatOptions);
147130

148131
const isAstUnstableTest = failedTests.isAstUnstable(filename, formatOptions);
149132
// Some parsers skip parsing empty files

tests/config/test-second-format.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import * as failedTests from "./failed-format-tests.js";
2+
import { format } from "./run-prettier.js";
3+
4+
async function testSecondFormat(source, formatResult, filename, formatOptions) {
5+
const isUnstableTest = failedTests.isUnstable(filename, formatOptions);
6+
if (
7+
(formatResult.changed || isUnstableTest) &&
8+
// No range and cursor
9+
formatResult.input === source
10+
) {
11+
const { eolVisualizedOutput: firstOutput, output } = formatResult;
12+
const { eolVisualizedOutput: secondOutput } = await format(
13+
output,
14+
formatOptions,
15+
);
16+
// To keep eye on failed tests, this assert never supposed to pass,
17+
// if it fails, just remove the file from `unstableTests`
18+
if (isUnstableTest) {
19+
expect(secondOutput).not.toEqual(firstOutput);
20+
return;
21+
}
22+
23+
expect(secondOutput).toEqual(firstOutput);
24+
}
25+
}
26+
27+
export { testSecondFormat as run };

0 commit comments

Comments
 (0)