Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/prettier-plugin-java/scripts/update-test-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,20 @@ const updateTestOutput = async () => {
try {
console.log(`Reading <${fileDesc.path}>`);
let newExpectedText = javaFileText;

const testDir = path.dirname(fileDesc.path);
const optionsPath = path.join(testDir, ".prettierrc.json");
const testOptions = fs.existsSync(optionsPath)
? fs.readJsonSync(optionsPath)
: {};

for (let i = 0; i < numberOfTime; i++) {
newExpectedText = await prettier.format(newExpectedText, {
parser: "java",
plugins: [path.resolve(__dirname, "../dist/index.js")],
tabWidth: 2,
endOfLine: "lf"
endOfLine: "lf",
...testOptions
});
}
let outputFilePath = fileDesc.path.replace(
Expand Down
9 changes: 6 additions & 3 deletions packages/prettier-plugin-java/test/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ const { readFileSync, existsSync, removeSync, copySync } = fs;
const __dirname = dirname(url.fileURLToPath(import.meta.url));
export function testSampleWithOptions({
testFolder,
exclusive,
prettierOptions = {}
exclusive
}: {
testFolder: string;
exclusive?: boolean;
prettierOptions?: any;
}) {
const itOrItOnly = exclusive ? it.only : it;
const inputPath = resolve(testFolder, "_input.java");
Expand All @@ -29,6 +27,11 @@ export function testSampleWithOptions({
let inputContents: string;
let expectedContents: string;

const prettierrcPath = resolve(testFolder, ".prettierrc.json");
const prettierOptions = existsSync(prettierrcPath)
? fs.readJsonSync(prettierrcPath)
: {};

// @ts-ignore
before(() => {
inputContents = readFileSync(inputPath, "utf8");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ const __dirname = path.dirname(url.fileURLToPath(import.meta.url));

describe("prettier-java", () => {
testSampleWithOptions({
testFolder: path.resolve(__dirname, "operator-position-start"),
prettierOptions: { experimentalOperatorPosition: "start" }
testFolder: path.resolve(__dirname, "operator-position-start")
});

testSampleWithOptions({
testFolder: path.resolve(__dirname, "operator-position-end"),
prettierOptions: { experimentalOperatorPosition: "end" }
testFolder: path.resolve(__dirname, "operator-position-end")
});
testSample(path.resolve(__dirname, "operator-position-end"));
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"experimentalOperatorPosition": "end"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"experimentalOperatorPosition": "start"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"requirePragma": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"requirePragma": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"requirePragma": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ describe("prettier-java: require-pragma option", () => {
path.resolve(__dirname, "./format-pragma"),
path.resolve(__dirname, "./prettier-pragma"),
path.resolve(__dirname, "./invalid-pragma")
].forEach(testFolder =>
].forEach(testFolder => {
testSampleWithOptions({
testFolder,
prettierOptions: { requirePragma: true }
})
);
testFolder
});
});
});