forked from prettier/prettier-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copies the `plugin-option` tests from prettier. Note that these will need updating once prettier#39 and prettier#21 are fixed.
- Loading branch information
Showing
4 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"plugins": ["./plugin.cjs"], | ||
"fooOption": "baz" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// 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`] = ` | ||
" --foo-option <bar|baz> foo description | ||
Defaults to "bar"" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
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; | ||
|
||
// TODO (43081j): this should also show the custom parser once we fix #39 | ||
const originalLines = originalStdout.split("\n"); | ||
const pluggedLines = pluggedStdout.split("\n"); | ||
const differentLines = pluggedLines.filter((line) => | ||
!originalLines.includes(line)); | ||
expect(differentLines.join("\n")).toMatchSnapshot(); | ||
}); | ||
|
||
// Note (43081j): we don't currently support `--help {option}` | ||
describe.skip("show detailed external option with `--help foo-option`", () => { | ||
runCli("plugin-options", [ | ||
"--plugin=./plugin.cjs", | ||
"--help", | ||
"foo-option", | ||
]).test({ | ||
status: 0, | ||
}); | ||
}); | ||
|
||
// Note (43081j): we don't currently support `--help {option}` | ||
describe.skip("include plugin's parsers to the values of the `parser` option`", () => { | ||
runCli("plugin-options", ["--plugin=./plugin.cjs", "--help", "parser"]).test( | ||
{ | ||
status: 0, | ||
}, | ||
); | ||
}); | ||
|
||
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: [], | ||
}); | ||
}); |