Improve "flow-ambient" test (#19768)

This commit is contained in:
fisker Cheung authored and GitHub committed 2026-08-02 16:01:41 +08:00
1 parent aa357ca077
commit de5c0171d6
4 files changed
+76 -31

No files matched your search

+14
View File
@@ -9,7 +9,19 @@ import {
import { ensurePromise } from "./utilities.js";
import visualizeEndOfLine from "./visualize-end-of-line.js";
function unsetFilepath(options) {
const { filepath, ...restOptions } = options;
if (typeof filepath === "string" && filepath.endsWith(".unset-filepath")) {
return restOptions;
}
return options;
}
async function parse(input, options) {
options = unsetFilepath(options);
const prettier = await getPrettier();
const { ast } = await ensurePromise(
prettier.__debug.parse(input, await loadPlugins(options), {
@@ -20,6 +32,8 @@ async function parse(input, options) {
}
async function format(input, options) {
options = unsetFilepath(options);
const inputWithCursor = insertCursor(input, options.cursorOffset);
const prettier = await getPrettier();
@@ -1,29 +1,6 @@
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
exports[`ambient.js.flow format 1`] = `
====================================options=====================================
parsers: ["flow"]
printWidth: 80 (default) |
=====================================input======================================
const foo: string;
=====================================output=====================================
const foo: string;
================================================================================
`;
exports[`ambient.js.flow format[hermes] 1`] = `
"missing initializer in const declaration (1:7)
> 1 | const foo: string;
| ^
2 |
Cause: missing initializer in const declaration (1:6)
const foo: string;
^~~~~~~~~~~"
`;
exports[`snippet: #0 format 1`] = `
exports[`snippet: const-without-initializer.js.flow format 1`] = `
====================================options=====================================
parsers: ["flow"]
printWidth: 80 (default) |
@@ -35,7 +12,44 @@ const foo: string;
================================================================================
`;
exports[`snippet: #0 format[hermes] 1`] = `
exports[`snippet: const-without-initializer.js.flow format[hermes] 1`] = `
"missing initializer in const declaration (1:7)
> 1 | const foo: string;
| ^
Cause: missing initializer in const declaration (1:6)
const foo: string;
^~~~~~~~~~~"
`;
exports[`snippet: const-without-initializer.unknown format[flow] 1`] = `
"Const must be initialized (1:7)
> 1 | const foo: string;
| ^
Cause: Const must be initialized (1:6)"
`;
exports[`snippet: const-without-initializer.unknown format[hermes] 1`] = `
"missing initializer in const declaration (1:7)
> 1 | const foo: string;
| ^
Cause: missing initializer in const declaration (1:6)
const foo: string;
^~~~~~~~~~~"
`;
exports[`snippet: const-without-initializer.unset-filepath format 1`] = `
====================================options=====================================
parsers: ["flow"]
printWidth: 80 (default) |
=====================================input======================================
const foo: string;
=====================================output=====================================
const foo: string;
================================================================================
`;
exports[`snippet: const-without-initializer.unset-filepath format[hermes] 1`] = `
"missing initializer in const declaration (1:7)
> 1 | const foo: string;
| ^
@@ -1 +0,0 @@
const foo: string;
@@ -1,11 +1,29 @@
const tests = [
{
code: "const foo: string;",
baseFilename: "const-without-initializer",
},
].flatMap(({ code, baseFilename }) =>
[".js.flow", ".unknown", ".unset-filepath"].map((extension) => {
const filename = `${baseFilename}${extension}`;
return {
name: filename,
code,
filename,
};
}),
);
runFormatTest(
{
snippets: [
// Unknown filename
"const foo: string;",
],
importMeta: import.meta,
snippets: tests,
},
["flow"],
{ errors: { hermes: true } },
{
errors: {
flow: ["const-without-initializer.unknown"],
hermes: true,
},
},
);