From bf6ceadb8b901941ae40fbc04495fd8991d447c3 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 18 Feb 2020 22:36:17 +0800 Subject: [PATCH] Add a test with same packageName and fileName (#7517) --- .../__tests__/plugin-resolution.js | 27 +++++++++++----- .../node_modules/prettier-plugin-bar/index.js | 8 +++-- .../plugins/automatic/prettier-plugin-bar.js | 31 +++++++++++++++++++ 3 files changed, 57 insertions(+), 9 deletions(-) create mode 100644 tests_integration/plugins/automatic/prettier-plugin-bar.js diff --git a/tests_integration/__tests__/plugin-resolution.js b/tests_integration/__tests__/plugin-resolution.js index 153b62118..a7c4a2158 100644 --- a/tests_integration/__tests__/plugin-resolution.js +++ b/tests_integration/__tests__/plugin-resolution.js @@ -5,7 +5,7 @@ const EOL = "\n"; describe("automatically loads 'prettier-plugin-*'", () => { runPrettier("plugins/automatic", ["file.txt", "--parser=bar"]).test({ - stdout: "bar+contents" + EOL, + stdout: "content from `prettier-plugin-bar` package + contents" + EOL, stderr: "", status: 0, write: [] @@ -49,7 +49,7 @@ describe("automatically loads '@prettier/plugin-*' from --plugin-search-dir (sam "--parser=bar", "--plugin-search-dir=." ]).test({ - stdout: "bar+contents" + EOL, + stdout: "content from `prettier-plugin-bar` package + contents" + EOL, stderr: "", status: 0, write: [] @@ -88,7 +88,7 @@ describe("automatically loads '@prettier/plugin-*' from --plugin-search-dir (dif "--parser=bar", "--plugin-search-dir=automatic" ]).test({ - stdout: "bar+contents" + EOL, + stdout: "content from `prettier-plugin-bar` package + contents" + EOL, stderr: "", status: 0, write: [] @@ -134,7 +134,7 @@ describe("loads --plugin by its relative path", () => { "--parser=bar", "--plugin=./automatic/node_modules/prettier-plugin-bar/index.js" ]).test({ - stdout: "bar+contents" + EOL, + stdout: "content from `prettier-plugin-bar` package + contents" + EOL, stderr: "", status: 0, write: [] @@ -147,7 +147,7 @@ describe("loads --plugin by its relative path without leading ./", () => { "--parser=bar", "--plugin=automatic/node_modules/prettier-plugin-bar/index.js" ]).test({ - stdout: "bar+contents" + EOL, + stdout: "content from `prettier-plugin-bar` package + contents" + EOL, stderr: "", status: 0, write: [] @@ -160,7 +160,7 @@ describe("loads --plugin by relative path to its directory (assuming index.js)", "--parser=bar", "--plugin=./automatic/node_modules/prettier-plugin-bar" ]).test({ - stdout: "bar+contents" + EOL, + stdout: "content from `prettier-plugin-bar` package + contents" + EOL, stderr: "", status: 0, write: [] @@ -173,7 +173,20 @@ describe("loads --plugin by relative path to its directory without leading ./ (a "--parser=bar", "--plugin=automatic/node_modules/prettier-plugin-bar" ]).test({ - stdout: "bar+contents" + EOL, + stdout: "content from `prettier-plugin-bar` package + contents" + EOL, + stderr: "", + status: 0, + write: [] + }); +}); + +describe("loads --plugin by filename without leading ./ and ext, should resolve to file, not package", () => { + runPrettier("plugins/automatic", [ + "file.txt", + "--parser=bar", + "--plugin=prettier-plugin-bar" + ]).test({ + stdout: "content from `prettier-plugin-bar.js` file + contents" + EOL, stderr: "", status: 0, write: [] diff --git a/tests_integration/plugins/automatic/node_modules/prettier-plugin-bar/index.js b/tests_integration/plugins/automatic/node_modules/prettier-plugin-bar/index.js index 283278563..666876275 100644 --- a/tests_integration/plugins/automatic/node_modules/prettier-plugin-bar/index.js +++ b/tests_integration/plugins/automatic/node_modules/prettier-plugin-bar/index.js @@ -1,7 +1,7 @@ "use strict"; const prettier = require("prettier/local"); -const concat = prettier.doc.builders.concat; +const { concat } = prettier.doc.builders; module.exports = { languages: [ @@ -18,7 +18,11 @@ module.exports = { }, printers: { bar: { - print: path => concat(["bar+", path.getValue().text]) + print: path => + concat([ + "content from `prettier-plugin-bar` package + ", + path.getValue().text + ]) } }, defaultOptions: { diff --git a/tests_integration/plugins/automatic/prettier-plugin-bar.js b/tests_integration/plugins/automatic/prettier-plugin-bar.js new file mode 100644 index 000000000..4be637d6d --- /dev/null +++ b/tests_integration/plugins/automatic/prettier-plugin-bar.js @@ -0,0 +1,31 @@ +"use strict"; + +const prettier = require("prettier/local"); +const { concat } = prettier.doc.builders; + +module.exports = { + languages: [ + { + name: "bar", + parsers: ["bar"] + } + ], + parsers: { + bar: { + parse: text => ({ text }), + astFormat: "bar" + } + }, + printers: { + bar: { + print: path => + concat([ + "content from `prettier-plugin-bar.js` file + ", + path.getValue().text + ]) + } + }, + defaultOptions: { + tabWidth: 4 + } +};