-
-
Notifications
You must be signed in to change notification settings - Fork 10
test: add infer-parser tests #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
491e549
test: add infer-parser tests
43081j 50b7054
test: inline stderr since it contains paths
43081j 7f0d9c6
feat: add `dump` to error logging
43081j 5d792db
test: update fixture path in assertions
43081j 373147c
test: update snapshots
43081j File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
Empty file.
This file contains hidden or 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 @@ | ||
| foo ( ) |
This file contains hidden or 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,3 @@ | ||
| #!/usr/bin/env zx | ||
|
|
||
| await $`cat package.json | grep name` |
This file contains hidden or 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,2 @@ | ||
| hello( 'world' | ||
| ) |
This file contains hidden or 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 @@ | ||
| {"name": "Gilbert", "wins": [["straight", "7♣"], ["one pair", "10♥"]]} | ||
| {"name": "Alexa", "wins": [["two pair", "4♠"], ["two pair", "9♠"]]} | ||
| {"name": "May", "wins": []} | ||
| {"name": "Deloise", "wins": [["three of a kind", "5♣"]]} |
This file contains hidden or 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
This file contains hidden or 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,48 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`--check with unknown path and no parser multiple files (stdout) 1`] = `"Checking formatting..."`; | ||
|
|
||
| exports[`--check with unknown path and no parser specific file is ignored (stderr) 1`] = `""`; | ||
|
|
||
| exports[`--check with unknown path and no parser specific file is ignored (stdout) 1`] = ` | ||
| "Checking formatting... | ||
| All matched files use Prettier code style!" | ||
| `; | ||
|
|
||
| exports[`--list-different with unknown path and no parser multiple files (stderr) 1`] = `"FOO"`; | ||
|
|
||
| exports[`--list-different with unknown path and no parser specific file should be ignored (stderr) 1`] = `""`; | ||
|
|
||
| exports[`--write with unknown path and no parser multiple files (stdout) 1`] = `"foo.js"`; | ||
|
|
||
| exports[`--write with unknown path and no parser multiple files (write) 1`] = ` | ||
| [ | ||
| { | ||
| "content": "foo(); | ||
| ", | ||
| "filename": "foo.js", | ||
| }, | ||
| ] | ||
| `; | ||
|
|
||
| exports[`--write with unknown path and no parser specific file should be ignored (stderr) 1`] = `""`; | ||
|
|
||
| exports[`Known/Unknown (stdout) 1`] = `"known.js"`; | ||
|
|
||
| exports[`stdin no path and no parser --check logs error but exits with 1 (stderr) 1`] = `"[error] UndefinedParserError: No parser could be inferred for file "stdin"."`; | ||
|
|
||
| exports[`stdin no path and no parser --list-different logs error but exits with 1 (stderr) 1`] = `"[error] UndefinedParserError: No parser could be inferred for file "stdin"."`; | ||
|
|
||
| exports[`stdin no path and no parser logs error and exits with 2 (stderr) 1`] = `"[error] UndefinedParserError: No parser could be inferred for file "stdin"."`; | ||
|
|
||
| exports[`stdin with unknown path and no parser --check logs error but exits with 1 (stderr) 1`] = `"[error] UndefinedParserError: No parser could be inferred for file "foo"."`; | ||
|
|
||
| exports[`stdin with unknown path and no parser --list-different logs error but exits with 1 (stderr) 1`] = `"[error] UndefinedParserError: No parser could be inferred for file "foo"."`; | ||
|
|
||
| exports[`stdin with unknown path and no parser logs error and exits with 2 (stderr) 1`] = `"[error] UndefinedParserError: No parser could be inferred for file "foo"."`; | ||
|
|
||
| exports[`unknown path and no parser multiple files are ignored (stderr) 1`] = `"[error] FOO: UndefinedParserError: No parser could be inferred for file "$CWD/FOO"."`; | ||
|
|
||
| exports[`unknown path and no parser multiple files are ignored (stdout) 1`] = `"foo();"`; | ||
|
|
||
| exports[`unknown path and no parser specific file is ignored (stderr) 1`] = `""`; |
This file contains hidden or 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
This file contains hidden or 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,158 @@ | ||
| import { runCli } from "../utils"; | ||
| import { color } from "specialist"; | ||
|
|
||
| describe("stdin no path and no parser", () => { | ||
| describe("logs error and exits with 2", () => { | ||
| runCli("infer-parser/", [], { input: "foo" }).test({ | ||
| status: 1, | ||
| stdout: "", | ||
| write: [], | ||
| }); | ||
| }); | ||
|
|
||
| // TODO (43081j): in prettier, this tests that it exits with 0 for | ||
| // whatever reason. should we do the same? | ||
43081j marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| describe("--check logs error but exits with 1", () => { | ||
| runCli("infer-parser/", ["--check"], { | ||
| input: "foo", | ||
| }).test({ | ||
| status: 1, | ||
| stdout: "", | ||
| write: [], | ||
| }); | ||
| }); | ||
|
|
||
| // TODO (43081j): in prettier, this tests that it exits with 0 for | ||
| // whatever reason. should we do the same? | ||
| describe("--list-different logs error but exits with 1", () => { | ||
| runCli("infer-parser/", ["--list-different"], { | ||
| input: "foo", | ||
| }).test({ | ||
| status: 1, | ||
| stdout: "", | ||
| write: [], | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("stdin with unknown path and no parser", () => { | ||
| describe("logs error and exits with 2", () => { | ||
| runCli("infer-parser/", ["--stdin-filepath", "foo"], { | ||
| input: "foo", | ||
| }).test({ | ||
| status: 1, | ||
| stdout: "", | ||
| write: [], | ||
| }); | ||
| }); | ||
|
|
||
| // TODO (43081j): in prettier, this tests that it exits with 0 for | ||
| // whatever reason. should we do the same? | ||
| describe("--check logs error but exits with 1", () => { | ||
| runCli("infer-parser/", ["--check", "--stdin-filepath", "foo"], { | ||
| input: "foo", | ||
| }).test({ | ||
| status: 1, | ||
| stdout: "", | ||
| write: [], | ||
| }); | ||
| }); | ||
|
|
||
| // TODO (43081j): in prettier, this tests that it exits with 0 for | ||
| // whatever reason. should we do the same? | ||
| describe("--list-different logs error but exits with 1", () => { | ||
| runCli( | ||
| "infer-parser/", | ||
| ["--list-different", "--stdin-filepath", "foo"], | ||
| { input: "foo" }, | ||
| ).test({ | ||
| status: 1, | ||
| stdout: "", | ||
| write: [], | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("unknown path and no parser", () => { | ||
| describe("specific file is ignored", () => { | ||
| runCli("infer-parser/", ["--end-of-line", "lf", "FOO"]).test({ | ||
| status: 0, | ||
| stdout: "", | ||
| write: [], | ||
| }); | ||
| }); | ||
|
|
||
| describe("multiple files are ignored", () => { | ||
| runCli("infer-parser/", ["--end-of-line", "lf", "*"]).test({ | ||
| status: 1, | ||
| write: [], | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("--check with unknown path and no parser", () => { | ||
| describe("specific file is ignored", () => { | ||
| runCli("infer-parser/", ["--check", "FOO"]).test({ | ||
| status: 0, | ||
| write: [], | ||
| }); | ||
| }); | ||
|
|
||
| describe("multiple files", () => { | ||
| runCli("infer-parser/", ["--check", "*"]).test({ | ||
| status: 1, | ||
| write: [], | ||
| stderr: `[${color.red('error')}] FOO: UndefinedParserError: No parser could be inferred for file "$CWD/FOO". | ||
| [${color.yellow('warn')}] foo.js | ||
| [${color.yellow('warn')}] Code style issues found in 1 file. Run Prettier with --write to fix.` | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("--list-different with unknown path and no parser", () => { | ||
| describe("specific file should be ignored", () => { | ||
| runCli("infer-parser/", ["--list-different", "FOO"]).test({ | ||
| status: 0, | ||
| stdout: "", | ||
| write: [], | ||
| }); | ||
| }); | ||
|
|
||
| describe("multiple files", () => { | ||
| runCli("infer-parser/", ["--list-different", "*"]).test({ | ||
| status: 1, | ||
| stdout: "foo.js", | ||
| write: [], | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("--write with unknown path and no parser", () => { | ||
| describe("specific file should be ignored", () => { | ||
| runCli("infer-parser/", ["--write", "FOO"]).test({ | ||
| status: 0, | ||
| stdout: "", | ||
| write: [], | ||
| }); | ||
| }); | ||
|
|
||
| describe("multiple files", () => { | ||
| runCli("infer-parser/", ["--write", "*"]).test({ | ||
| status: 1, | ||
| stderr: `[${color.red('error')}] FOO: UndefinedParserError: No parser could be inferred for file "$CWD/FOO".`, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("Known/Unknown", () => { | ||
| runCli("infer-parser/known-unknown", [ | ||
| "--end-of-line", | ||
| "lf", | ||
| "--list-different", | ||
| ".", | ||
| ]).test({ | ||
| status: 1, | ||
| stderr: "", | ||
| write: [], | ||
| }); | ||
| }); | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
importantly , this changed
this is what makes errors now log out when you're in dump mode (the same as prettier)