Files
test-repo/tests/integration/__tests__/format-ast.js
T

95 lines
2.0 KiB
JavaScript

import prettier from "prettier-local";
const { formatAST } = prettier.__debug;
describe("formatAST", () => {
const formatExportSpecifier = async (specifier) => {
const { formatted } = await formatAST(
{
type: "Program",
body: [
{
type: "ExportNamedDeclaration",
specifiers: [specifier],
},
],
},
{ parser: "meriyah" }
);
return formatted;
};
test("Shorthand specifier", async () => {
expect(
await formatExportSpecifier({
type: "ExportSpecifier",
local: {
type: "Identifier",
name: "specifier1",
},
exported: {
type: "Identifier",
name: "specifier2",
},
})
).toMatchSnapshot();
});
test("Shorthand specifier 2", async () => {
expect(
await formatExportSpecifier({
type: "ExportSpecifier",
local: {
type: "Identifier",
name: "specifier1",
range: [0, 0],
},
exported: {
type: "Identifier",
name: "specifier2",
range: [0, 0],
},
})
).toMatchSnapshot();
});
test("Shorthand specifier 3", async () => {
expect(
await formatExportSpecifier({
type: "ExportSpecifier",
local: {
type: "Literal",
value: "specifier",
raw: '"specifier"',
range: [0, 0],
},
exported: {
type: "Identifier",
name: "specifier",
range: [0, 0],
},
})
).toMatchSnapshot();
});
test("Shorthand specifier 4", async () => {
expect(
await formatExportSpecifier({
type: "ExportSpecifier",
local: {
type: "Literal",
value: "specifier",
raw: '"specifier"',
range: [0, 0],
},
exported: {
type: "Literal",
value: "specifier",
raw: "'specifier'",
range: [0, 0],
},
})
).toMatchSnapshot();
});
});