Skip to content

Commit

Permalink
Ported test suite: plugin-options
Browse files Browse the repository at this point in the history
- `--help option` is no longer supported at the moment.
- Config resolution for files piped in through stdin is not wired in yet.
  • Loading branch information
43081j authored and fabiospampinato committed Feb 23, 2025
1 parent 05b0c61 commit 6262bea
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/__fixtures__/plugin-options/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"plugins": ["./plugin.cjs"],
"fooOption": "baz"
}
41 changes: 41 additions & 0 deletions test/__fixtures__/plugin-options/plugin.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"use strict";

module.exports = {
languages: [
{
name: "foo",
parsers: ["foo-parser"],
extensions: [".foo"],
since: "1.0.0",
},
],
options: {
fooOption: {
type: "choice",
default: "bar",
description: "foo description",
choices: [
{
value: "bar",
description: "bar description",
},
{
value: "baz",
description: "baz description",
},
],
},
},
parsers: {
"foo-parser": {
parse: (text) => ({ text }),
astFormat: "foo-ast",
},
},
printers: {
"foo-ast": {
print: (path, options) =>
options.fooOption ? `foo:${options.fooOption}` : path.getValue().text,
},
},
};
62 changes: 62 additions & 0 deletions test/__tests__/__snapshots__/plugin-options.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`include plugin's parsers to the values of the \`parser\` option\` (stderr) 1`] = `""`;

exports[`include plugin's parsers to the values of the \`parser\` option\` (stdout) 1`] = `
"--parser <flow|babel|babel-flow|babel-ts|typescript|acorn|espree|meriyah|css|less|scss|json|json5|jsonc|json-stringify|graphql|markdown|mdx|vue|yaml|glimmer|html|angular|lwc|foo-parser>
Which parser to use.
Valid options:
flow Flow
babel JavaScript
babel-flow Flow
babel-ts TypeScript
typescript TypeScript
acorn JavaScript
espree JavaScript
meriyah JavaScript
css CSS
less Less
scss SCSS
json JSON
json5 JSON5
jsonc JSON with Comments
json-stringify JSON.stringify
graphql GraphQL
markdown Markdown
mdx MDX
vue Vue
yaml YAML
glimmer Ember / Handlebars
html HTML
angular Angular
lwc Lightning Web Components
foo-parser foo (plugin: ./plugin.cjs)"
`;

exports[`include plugin's parsers to the values of the \`parser\` option\` (write) 1`] = `[]`;

exports[`show detailed external option with \`--help foo-option\` (stderr) 1`] = `""`;

exports[`show detailed external option with \`--help foo-option\` (stdout) 1`] = `
"--foo-option <bar|baz>
foo description
Valid options:
bar bar description
baz baz description
Default: bar"
`;

exports[`show detailed external option with \`--help foo-option\` (write) 1`] = `[]`;

exports[`show external options with \`--help\` 1`] = `
" --parser <flow,babel,babel-flow,babel-ts,typescript,acorn,espree,meriyah,css,less,scss,json,json5,json-stringify,graphql,markdown,mdx,vue,yaml,glimmer,html,angular,lwc,foo-parser>
--foo-option <bar|baz> foo description
Defaults to "bar""
`;
44 changes: 44 additions & 0 deletions test/__tests__/plugin-options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { runCli } from "../utils";

test("show external options with `--help`", async () => {
const originalStdout = await runCli("plugin-options", ["--help"]).stdout;
const pluggedStdout = await runCli("plugin-options", ["--help", "--plugin=./plugin.cjs"]).stdout;

const originalLines = originalStdout.split("\n");
const pluggedLines = pluggedStdout.split("\n");
const differentLines = pluggedLines.filter((line) => !originalLines.includes(line));
expect(differentLines.join("\n")).toMatchSnapshot();
});

describe("external options from CLI should work", () => {
runCli("plugin-options", [
"--plugin=./plugin.cjs",
"--stdin-filepath",
"example.foo",
"--foo-option",
"baz",
], {
input: "hello-world",
}).test({
stdout: "foo:baz",
stderr: "",
status: 0,
write: [],
});
});

// TODO (43081j): re-enable this once #21 is fixed
describe.skip("external options from config file should work", () => {
runCli("plugin-options", [
"--config-path=./config.json",
"--stdin-filepath",
"example.foo",
], {
input: "hello-world",
}).test({
stdout: "foo:baz",
stderr: "",
status: 0,
write: [],
});
});

0 comments on commit 6262bea

Please sign in to comment.