diff --git a/test/__fixtures__/plugin-default-options/config.json b/test/__fixtures__/plugin-default-options/config.json new file mode 100644 index 0000000..37ed1cf --- /dev/null +++ b/test/__fixtures__/plugin-default-options/config.json @@ -0,0 +1,3 @@ +{ + "plugins": ["./plugin"] +} diff --git a/test/__fixtures__/plugin-default-options/plugin.cjs b/test/__fixtures__/plugin-default-options/plugin.cjs new file mode 100644 index 0000000..3f08e6f --- /dev/null +++ b/test/__fixtures__/plugin-default-options/plugin.cjs @@ -0,0 +1,30 @@ +"use strict"; + +module.exports = { + languages: [ + { + name: "foo", + parsers: ["foo-parser"], + extensions: [".foo"], + }, + ], + defaultOptions: { + tabWidth: 8, + bracketSpacing: false, + }, + parsers: { + "foo-parser": { + parse: (text) => ({ text }), + astFormat: "foo-ast", + }, + }, + printers: { + "foo-ast": { + print: (path, options) => + JSON.stringify({ + tabWidth: options.tabWidth, + bracketSpacing: options.bracketSpacing, + }), + }, + }, +}; diff --git a/test/__tests__/plugin-default-options.js b/test/__tests__/plugin-default-options.js new file mode 100644 index 0000000..44f4811 --- /dev/null +++ b/test/__tests__/plugin-default-options.js @@ -0,0 +1,39 @@ +import { runCli } from "../utils"; + +describe("plugin default options should work", () => { + runCli("plugin-default-options", [ + "--stdin-filepath", + "example.foo", + "--plugin=./plugin.cjs", + "--no-editorconfig", + ], { + input: "hello-world", + }).test({ + stdout: JSON.stringify({ + tabWidth: 8, + bracketSpacing: false, + }), + stderr: "", + status: 0, + write: [], + }); +}); + +describe("overriding plugin default options should work", () => { + runCli("plugin-default-options", [ + "--stdin-filepath", + "example.foo", + "--plugin=./plugin.cjs", + "--tab-width=4", + ], { + input: "hello-world", + }).test({ + stdout: JSON.stringify({ + tabWidth: 4, + bracketSpacing: false, + }), + stderr: "", + status: 0, + write: [], + }); +});