Skip to content

Commit

Permalink
test: add tests for improper usage
Browse files Browse the repository at this point in the history
  • Loading branch information
aarondill committed Jan 30, 2023
1 parent f425764 commit aae2cdb
Show file tree
Hide file tree
Showing 3 changed files with 250 additions and 1 deletion.
76 changes: 76 additions & 0 deletions tests/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
})
175 changes: 174 additions & 1 deletion tests/snapshots/cli.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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: '',
},
}
Binary file modified tests/snapshots/cli.js.snap
Binary file not shown.

0 comments on commit aae2cdb

Please sign in to comment.