Skip to content

Commit

Permalink
Ported test suite: plugin-default-options
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiospampinato committed Sep 15, 2024
1 parent 51c4400 commit 17406c9
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/__fixtures__/plugin-default-options/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["./plugin"]
}
30 changes: 30 additions & 0 deletions test/__fixtures__/plugin-default-options/plugin.cjs
Original file line number Diff line number Diff line change
@@ -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,
}),
},
},
};
39 changes: 39 additions & 0 deletions test/__tests__/plugin-default-options.js
Original file line number Diff line number Diff line change
@@ -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: [],
});
});

0 comments on commit 17406c9

Please sign in to comment.