Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(prettier): output to stdout instead of write file by default unless specified --write flag #332

Merged
merged 14 commits into from
May 21, 2019
Prev Previous commit
Next Next commit
add test case for output to stdout
  • Loading branch information
axetroy committed Apr 10, 2019
commit ad907e1a03a8bfe4626cc3b25f7a056b9e45191a
25 changes: 25 additions & 0 deletions prettier/main_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,5 +203,30 @@ incididunt ut labore et dolore magna aliqua.
await run([...cmd, "--end-of-line", "crlf", "--write", file2]);
assertEquals(await getSourceCode(file2), "console.log({ a: 1 });\r\n");

await clearTestdataChanges();
});

test(async function testPrettierPrintToStdout() {
await clearTestdataChanges();

const file0 = join(testdata, "0.ts");
const file1 = join(testdata, "formatted.ts");

const getSourceCode = async (f: string) =>
decoder.decode(await Deno.readFile(f));

const { stdout } = await run([...cmd, file0]);
// the source file will not change without `--write` flags
assertEquals(await getSourceCode(file0), "console.log (0)\n");
// the output will be formatted code
assertEquals(stdout, "console.log(0);\n");

const { stdout:formattedCode } = await run([...cmd, file1]);
// the source file will not change without `--write` flags
assertEquals(await getSourceCode(file1), "console.log(0);\n");
// the output will be empty string. because the formatted content is same with before
assertEquals(formattedCode, "");


await clearTestdataChanges();
});
1 change: 1 addition & 0 deletions prettier/testdata/formatted.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log(0);