summaryrefslogtreecommitdiff
path: root/std/prettier/main_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'std/prettier/main_test.ts')
-rw-r--r--std/prettier/main_test.ts156
1 files changed, 156 insertions, 0 deletions
diff --git a/std/prettier/main_test.ts b/std/prettier/main_test.ts
index 16c19ed03..a63890741 100644
--- a/std/prettier/main_test.ts
+++ b/std/prettier/main_test.ts
@@ -378,4 +378,160 @@ test(async function testPrettierReadFromStdin(): Promise<void> {
}
});
+test(async function testPrettierWithAutoConfig(): Promise<void> {
+ const configs = [
+ "config_file_json",
+ "config_file_toml",
+ "config_file_js",
+ "config_file_ts"
+ ];
+
+ for (const configName of configs) {
+ const cwd = join(testdata, configName);
+ const prettierFile = join(Deno.cwd(), "prettier", "main.ts");
+ const { stdout, stderr } = Deno.run({
+ args: [
+ execPath(),
+ "run",
+ "--allow-read",
+ "--allow-env",
+ prettierFile,
+ "../5.ts",
+ "--config",
+ "auto"
+ ],
+ stdout: "piped",
+ stderr: "piped",
+ cwd
+ });
+
+ const output = decoder.decode(await Deno.readAll(stdout));
+ const errMsg = decoder.decode(await Deno.readAll(stderr));
+
+ assertEquals(
+ errMsg
+ .split(EOL)
+ .filter((line: string) => line.indexOf("Compile") !== 0)
+ .join(EOL),
+ ""
+ );
+
+ assertEquals(output, `console.log('0');\n`);
+ }
+});
+
+test(async function testPrettierWithSpecifiedConfig(): Promise<void> {
+ interface Config {
+ dir: string;
+ name: string;
+ }
+ const configs: Config[] = [
+ {
+ dir: "config_file_json",
+ name: ".prettierrc.json"
+ },
+ {
+ dir: "config_file_toml",
+ name: ".prettierrc.toml"
+ },
+ {
+ dir: "config_file_js",
+ name: ".prettierrc.js"
+ },
+ {
+ dir: "config_file_ts",
+ name: ".prettierrc.ts"
+ }
+ ];
+
+ for (const config of configs) {
+ const cwd = join(testdata, config.dir);
+ const prettierFile = join(Deno.cwd(), "prettier", "main.ts");
+ const { stdout, stderr } = Deno.run({
+ args: [
+ execPath(),
+ "run",
+ "--allow-read",
+ "--allow-env",
+ prettierFile,
+ "../5.ts",
+ "--config",
+ config.name
+ ],
+ stdout: "piped",
+ stderr: "piped",
+ cwd
+ });
+
+ const output = decoder.decode(await Deno.readAll(stdout));
+ const errMsg = decoder.decode(await Deno.readAll(stderr));
+
+ assertEquals(
+ errMsg
+ .split(EOL)
+ .filter((line: string) => line.indexOf("Compile") !== 0)
+ .join(EOL),
+ ""
+ );
+
+ assertEquals(output, `console.log('0');\n`);
+ }
+});
+
+test(async function testPrettierWithAutoIgnore(): Promise<void> {
+ // only format typescript file
+ const cwd = join(testdata, "ignore_file");
+ const prettierFile = join(Deno.cwd(), "prettier", "main.ts");
+ const { stdout, stderr } = Deno.run({
+ args: [
+ execPath(),
+ "run",
+ "--allow-read",
+ "--allow-env",
+ prettierFile,
+ "**/*",
+ "--ignore-path",
+ "auto"
+ ],
+ stdout: "piped",
+ stderr: "piped",
+ cwd
+ });
+
+ assertEquals(decoder.decode(await Deno.readAll(stderr)), "");
+
+ assertEquals(
+ decoder.decode(await Deno.readAll(stdout)),
+ `console.log("typescript");\nconsole.log("typescript1");\n`
+ );
+});
+
+test(async function testPrettierWithSpecifiedIgnore(): Promise<void> {
+ // only format javascript file
+ const cwd = join(testdata, "ignore_file");
+ const prettierFile = join(Deno.cwd(), "prettier", "main.ts");
+ const { stdout, stderr } = Deno.run({
+ args: [
+ execPath(),
+ "run",
+ "--allow-read",
+ "--allow-env",
+ prettierFile,
+ "**/*",
+ "--ignore-path",
+ "typescript.prettierignore"
+ ],
+ stdout: "piped",
+ stderr: "piped",
+ cwd
+ });
+
+ assertEquals(decoder.decode(await Deno.readAll(stderr)), "");
+
+ assertEquals(
+ decoder.decode(await Deno.readAll(stdout)),
+ `console.log("javascript");\nconsole.log("javascript1");\n`
+ );
+});
+
runIfMain(import.meta);