diff --git a/tests/cli.js b/tests/cli.js index 0efab4a8..492e9df3 100644 --- a/tests/cli.js +++ b/tests/cli.js @@ -601,3 +601,79 @@ test('run `cli --check` on duplicate patterns without TTY', macro.testCLI, { message: 'Should not list `bad-1/package.json` more than once. Exit code 1', isTerminal: { stderr: false, stdout: false }, }) + +const badFormat = `{` + +test('run `cli --check` on 1 non-json file', macro.testCLI, { + fixtures: [ + { + file: 'notJson/package.json', + content: badFormat, + expect: badFormat, + }, + ], + args: ['*/package.json', '--check'], + message: 'Should fail to check, but not end execution.', +}) + +test('run `cli --check --quiet` on 1 non-json file', macro.testCLI, { + fixtures: [ + { + file: 'notJson/package.json', + content: badFormat, + expect: badFormat, + }, + ], + args: ['*/package.json', '--check', '--quiet'], + message: 'Should output error message, but not count.', +}) + +test('run `cli --check` on 1 non-json file without TTY', macro.testCLI, { + fixtures: [ + { + file: 'notJson/package.json', + content: badFormat, + expect: badFormat, + }, + ], + args: ['*/package.json', '--check'], + message: 'Should output filename on stderr.', + isTerminal: { stdout: false, stderr: false }, +}) + +test('run `cli` on 1 non-json file', macro.testCLI, { + fixtures: [ + { + file: 'notJson/package.json', + content: badFormat, + expect: badFormat, + }, + ], + args: ['*/package.json'], + message: 'Should fail to check, but not end execution.', +}) + +test('run `cli --quiet` on 1 non-json file', macro.testCLI, { + fixtures: [ + { + file: 'notJson/package.json', + content: badFormat, + expect: badFormat, + }, + ], + args: ['*/package.json', '--quiet'], + message: 'Should output error message', +}) + +test('run `cli` on 1 non-json file without TTY', macro.testCLI, { + fixtures: [ + { + file: 'notJson/package.json', + content: badFormat, + expect: badFormat, + }, + ], + args: ['*/package.json'], + message: 'Should output filename on stderr.', + isTerminal: { stdout: false, stderr: false }, +}) diff --git a/tests/snapshots/cli.js.md b/tests/snapshots/cli.js.md index ee2f5824..8fe722cc 100644 --- a/tests/snapshots/cli.js.md +++ b/tests/snapshots/cli.js.md @@ -1331,7 +1331,7 @@ Generated by [AVA](https://avajs.dev). ## run `cli --check` on 2 good files and 2 bad files without stdout TTY -> Should output bad files on stderr and exit code 2. +> Should output bad files on stdout and exit code 2. { args: [ @@ -1836,3 +1836,176 @@ Generated by [AVA](https://avajs.dev). `, }, } + +## run `cli --check` on 1 non-json file + +> Should fail to check, but not end execution. + + { + args: [ + '*/package.json', + '--check', + ], + fixtures: [ + { + expect: '{', + file: 'notJson/package.json', + original: '{', + }, + ], + isTerminal: { + stderr: true, + stdout: true, + }, + result: { + errorCode: 1, + stderr: `could not check notJson/package.json␊ + Expected property name or '}' in JSON at position 1␊ + `, + stdout: `␊ + 1 of 1 matched file is not sorted.␊ + `, + }, + } + +## run `cli --check --quiet` on 1 non-json file + +> Should output error message, but not count. + + { + args: [ + '*/package.json', + '--check', + '--quiet', + ], + fixtures: [ + { + expect: '{', + file: 'notJson/package.json', + original: '{', + }, + ], + isTerminal: { + stderr: true, + stdout: true, + }, + result: { + errorCode: 1, + stderr: `could not check notJson/package.json␊ + Expected property name or '}' in JSON at position 1␊ + `, + stdout: '', + }, + } + +## run `cli --check` on 1 non-json file without TTY + +> Should output filename on stderr. + + { + args: [ + '*/package.json', + '--check', + ], + fixtures: [ + { + expect: '{', + file: 'notJson/package.json', + original: '{', + }, + ], + isTerminal: { + stderr: false, + stdout: false, + }, + result: { + errorCode: 1, + stderr: `notJson/package.json␊ + `, + stdout: '', + }, + } + +## run `cli` on 1 non-json file + +> Should fail to check, but not end execution. + + { + args: [ + '*/package.json', + ], + fixtures: [ + { + expect: '{', + file: 'notJson/package.json', + original: '{', + }, + ], + isTerminal: { + stderr: true, + stdout: true, + }, + result: { + errorCode: 1, + stderr: `could not sort notJson/package.json␊ + Expected property name or '}' in JSON at position 1␊ + `, + stdout: '', + }, + } + +## run `cli --quiet` on 1 non-json file + +> Should output error message + + { + args: [ + '*/package.json', + '--quiet', + ], + fixtures: [ + { + expect: '{', + file: 'notJson/package.json', + original: '{', + }, + ], + isTerminal: { + stderr: true, + stdout: true, + }, + result: { + errorCode: 1, + stderr: `could not sort notJson/package.json␊ + Expected property name or '}' in JSON at position 1␊ + `, + stdout: '', + }, + } + +## run `cli` on 1 non-json file without TTY + +> Should output filename on stderr. + + { + args: [ + '*/package.json', + ], + fixtures: [ + { + expect: '{', + file: 'notJson/package.json', + original: '{', + }, + ], + isTerminal: { + stderr: false, + stdout: false, + }, + result: { + errorCode: 1, + stderr: `notJson/package.json␊ + `, + stdout: '', + }, + } diff --git a/tests/snapshots/cli.js.snap b/tests/snapshots/cli.js.snap index 76a99e98..24bd21e6 100644 Binary files a/tests/snapshots/cli.js.snap and b/tests/snapshots/cli.js.snap differ