Skip to content

Commit 6262bea

Browse files
43081jfabiospampinato
authored andcommitted
Ported test suite: plugin-options
- `--help option` is no longer supported at the moment. - Config resolution for files piped in through stdin is not wired in yet.
1 parent 05b0c61 commit 6262bea

4 files changed

Lines changed: 151 additions & 0 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"plugins": ["./plugin.cjs"],
3+
"fooOption": "baz"
4+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"use strict";
2+
3+
module.exports = {
4+
languages: [
5+
{
6+
name: "foo",
7+
parsers: ["foo-parser"],
8+
extensions: [".foo"],
9+
since: "1.0.0",
10+
},
11+
],
12+
options: {
13+
fooOption: {
14+
type: "choice",
15+
default: "bar",
16+
description: "foo description",
17+
choices: [
18+
{
19+
value: "bar",
20+
description: "bar description",
21+
},
22+
{
23+
value: "baz",
24+
description: "baz description",
25+
},
26+
],
27+
},
28+
},
29+
parsers: {
30+
"foo-parser": {
31+
parse: (text) => ({ text }),
32+
astFormat: "foo-ast",
33+
},
34+
},
35+
printers: {
36+
"foo-ast": {
37+
print: (path, options) =>
38+
options.fooOption ? `foo:${options.fooOption}` : path.getValue().text,
39+
},
40+
},
41+
};
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`include plugin's parsers to the values of the \`parser\` option\` (stderr) 1`] = `""`;
4+
5+
exports[`include plugin's parsers to the values of the \`parser\` option\` (stdout) 1`] = `
6+
"--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>
7+
8+
Which parser to use.
9+
10+
Valid options:
11+
12+
flow Flow
13+
babel JavaScript
14+
babel-flow Flow
15+
babel-ts TypeScript
16+
typescript TypeScript
17+
acorn JavaScript
18+
espree JavaScript
19+
meriyah JavaScript
20+
css CSS
21+
less Less
22+
scss SCSS
23+
json JSON
24+
json5 JSON5
25+
jsonc JSON with Comments
26+
json-stringify JSON.stringify
27+
graphql GraphQL
28+
markdown Markdown
29+
mdx MDX
30+
vue Vue
31+
yaml YAML
32+
glimmer Ember / Handlebars
33+
html HTML
34+
angular Angular
35+
lwc Lightning Web Components
36+
foo-parser foo (plugin: ./plugin.cjs)"
37+
`;
38+
39+
exports[`include plugin's parsers to the values of the \`parser\` option\` (write) 1`] = `[]`;
40+
41+
exports[`show detailed external option with \`--help foo-option\` (stderr) 1`] = `""`;
42+
43+
exports[`show detailed external option with \`--help foo-option\` (stdout) 1`] = `
44+
"--foo-option <bar|baz>
45+
46+
foo description
47+
48+
Valid options:
49+
50+
bar bar description
51+
baz baz description
52+
53+
Default: bar"
54+
`;
55+
56+
exports[`show detailed external option with \`--help foo-option\` (write) 1`] = `[]`;
57+
58+
exports[`show external options with \`--help\` 1`] = `
59+
" --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>
60+
--foo-option <bar|baz> foo description
61+
Defaults to "bar""
62+
`;

test/__tests__/plugin-options.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { runCli } from "../utils";
2+
3+
test("show external options with `--help`", async () => {
4+
const originalStdout = await runCli("plugin-options", ["--help"]).stdout;
5+
const pluggedStdout = await runCli("plugin-options", ["--help", "--plugin=./plugin.cjs"]).stdout;
6+
7+
const originalLines = originalStdout.split("\n");
8+
const pluggedLines = pluggedStdout.split("\n");
9+
const differentLines = pluggedLines.filter((line) => !originalLines.includes(line));
10+
expect(differentLines.join("\n")).toMatchSnapshot();
11+
});
12+
13+
describe("external options from CLI should work", () => {
14+
runCli("plugin-options", [
15+
"--plugin=./plugin.cjs",
16+
"--stdin-filepath",
17+
"example.foo",
18+
"--foo-option",
19+
"baz",
20+
], {
21+
input: "hello-world",
22+
}).test({
23+
stdout: "foo:baz",
24+
stderr: "",
25+
status: 0,
26+
write: [],
27+
});
28+
});
29+
30+
// TODO (43081j): re-enable this once #21 is fixed
31+
describe.skip("external options from config file should work", () => {
32+
runCli("plugin-options", [
33+
"--config-path=./config.json",
34+
"--stdin-filepath",
35+
"example.foo",
36+
], {
37+
input: "hello-world",
38+
}).test({
39+
stdout: "foo:baz",
40+
stderr: "",
41+
status: 0,
42+
write: [],
43+
});
44+
});

0 commit comments

Comments
 (0)