Skip to content

Commit

Permalink
Refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed May 17, 2019
1 parent 11d3261 commit edadd69
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 50 deletions.
5 changes: 3 additions & 2 deletions test/echo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import test from 'ava'
import { testEach } from './helpers/test_each/main.js'
import { snapshotTest } from './helpers/snapshot.js'
import { METHODS } from './helpers/methods.js'
import { command } from './helpers/command.js'

testEach(
METHODS,
[
{ command: 'echo test', opts: { echo: false } },
{ command: 'echo test', opts: { echo: true } },
{ command, opts: { echo: false } },
{ command, opts: { echo: true } },
],
(suffix, methodProps, data) =>
test(`'echo' option ${suffix}`, t =>
Expand Down
3 changes: 2 additions & 1 deletion test/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import test from 'ava'

import { testEach } from './helpers/test_each/main.js'
import { snapshotTest } from './helpers/snapshot.js'
import { command } from './helpers/command.js'

testEach([{ command: 'echo test' }], (suffix, data) =>
testEach([{ command }], (suffix, data) =>
test(`exec() ${suffix}`, t => snapshotTest({ t, data })),
)
2 changes: 2 additions & 0 deletions test/helpers/command.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Command used by most tests
export const command = 'echo test'
61 changes: 31 additions & 30 deletions test/invalid.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import test from 'ava'
import { testEach } from './helpers/test_each/main.js'
import { snapshotTest } from './helpers/snapshot.js'
import { METHODS } from './helpers/methods.js'
import { command } from './helpers/command.js'

testEach(
METHODS,
Expand All @@ -15,35 +16,35 @@ testEach(
testEach(
METHODS,
[
{ command: 'echo test', opts: false },
{ command: 'echo test', opts: { cwd: false } },
{ command: 'echo test', opts: { env: false } },
{ command: 'echo test', opts: { argv0: false } },
{ command: 'echo test', opts: { stdio: false } },
{ command: 'echo test', opts: { detached: '' } },
{ command: 'echo test', opts: { uid: false } },
{ command: 'echo test', opts: { gid: false } },
{ command: 'echo test', opts: { shell: 0 } },
{ command: 'echo test', opts: { windowsVerbatimArguments: '' } },
{ command: 'echo test', opts: { windowsHide: '' } },
{ command: 'echo test', opts: { encoding: false } },
{ command: 'echo test', opts: { extendEnv: '' } },
{ command: 'echo test', opts: { stripFinalNewline: '' } },
{ command: 'echo test', opts: { preferLocal: '' } },
{ command: 'echo test', opts: { localDir: false } },
{ command: 'echo test', opts: { input: false } },
{ command: 'echo test', opts: { reject: '' } },
{ command: 'echo test', opts: { cleanup: '' } },
{ command: 'echo test', opts: { timeout: false } },
{ command: 'echo test', opts: { buffer: '' } },
{ command: 'echo test', opts: { maxBuffer: false } },
{ command: 'echo test', opts: { killSignal: false } },
{ command: 'echo test', opts: { stdin: false } },
{ command: 'echo test', opts: { stdout: false } },
{ command: 'echo test', opts: { stderr: false } },
{ command: 'echo test', opts: { invalid: false } },
{ command: 'echo test', opts: { result: 'invalid' } },
{ command: 'echo test', opts: { from: 'invalid' } },
{ command, opts: false },
{ command, opts: { cwd: false } },
{ command, opts: { env: false } },
{ command, opts: { argv0: false } },
{ command, opts: { stdio: false } },
{ command, opts: { detached: '' } },
{ command, opts: { uid: false } },
{ command, opts: { gid: false } },
{ command, opts: { shell: 0 } },
{ command, opts: { windowsVerbatimArguments: '' } },
{ command, opts: { windowsHide: '' } },
{ command, opts: { encoding: false } },
{ command, opts: { extendEnv: '' } },
{ command, opts: { stripFinalNewline: '' } },
{ command, opts: { preferLocal: '' } },
{ command, opts: { localDir: false } },
{ command, opts: { input: false } },
{ command, opts: { reject: '' } },
{ command, opts: { cleanup: '' } },
{ command, opts: { timeout: false } },
{ command, opts: { buffer: '' } },
{ command, opts: { maxBuffer: false } },
{ command, opts: { killSignal: false } },
{ command, opts: { stdin: false } },
{ command, opts: { stdout: false } },
{ command, opts: { stderr: false } },
{ command, opts: { invalid: false } },
{ command, opts: { result: 'invalid' } },
{ command, opts: { from: 'invalid' } },
],
(suffix, methodProps, data) =>
test(`Invalid options ${suffix}`, t =>
Expand All @@ -53,7 +54,7 @@ testEach(
testEach(
METHODS,
[
{ command: 'echo test', opts: { encoding: 'invalid' } },
{ command, opts: { encoding: 'invalid' } },
{ command: 'invalid', read: false },
],
(suffix, methodProps, data) =>
Expand Down
13 changes: 7 additions & 6 deletions test/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ import test from 'ava'
import { testEach } from './helpers/test_each/main.js'
import { snapshotTest } from './helpers/snapshot.js'
import { STREAM_METHODS } from './helpers/methods.js'
import { command } from './helpers/command.js'

testEach(
STREAM_METHODS,
[
{ task: 'inputNotFunc', command: 'echo test' },
{ task: 'inputNotFunc', command },
{ task: 'inputThrows' },
{ task: 'inputAsync', command: 'echo test' },
{ task: 'inputAsync', command },
{ task: 'inputFile', command: 'echo' },
{ task: 'inputUndefined' },
{ task: 'severalFiles', command: 'echo test' },
{ command: 'echo test' },
{ command: 'echo test', opts: { encoding: 'utf8' } },
{ command: 'echo test', opts: { stripFinalNewline: true } },
{ task: 'severalFiles', command },
{ command },
{ command, opts: { encoding: 'utf8' } },
{ command, opts: { stripFinalNewline: true } },
],
(suffix, methodProps, data) =>
test(`stream() ${suffix}`, t => snapshotTest({ t, methodProps, data })),
Expand Down
3 changes: 2 additions & 1 deletion test/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import test from 'ava'

import { testEach } from './helpers/test_each/main.js'
import { snapshotTest } from './helpers/snapshot.js'
import { command } from './helpers/command.js'

testEach(
[{ command: 'echo test' }, { task: 'nested', command: 'echo test' }],
[{ command }, { task: 'nested', command }],
(suffix, data) =>
test(`task() ${suffix}`, t =>
snapshotTest({ t, methodProps: { method: 'task' }, data })),
Expand Down
21 changes: 11 additions & 10 deletions test/verbose.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@ import test from 'ava'
import { testEach } from './helpers/test_each/main.js'
import { snapshotTest } from './helpers/snapshot.js'
import { METHODS } from './helpers/methods.js'
import { command } from './helpers/command.js'

testEach(
METHODS,
[
{ command: 'echo test', execaOpts: { env: { CI: '1' } } },
{ command: 'echo test', opts: { verbose: false } },
{ command: 'echo test', opts: { verbose: true } },
{ command: 'echo test', opts: { echo: false, verbose: false } },
{ command: 'echo test', opts: { echo: false, verbose: true } },
{ command: 'echo test', opts: { echo: true, verbose: false } },
{ command: 'echo test', opts: { echo: true, verbose: true } },
{ command, execaOpts: { env: { CI: '1' } } },
{ command, opts: { verbose: false } },
{ command, opts: { verbose: true } },
{ command, opts: { echo: false, verbose: false } },
{ command, opts: { echo: false, verbose: true } },
{ command, opts: { echo: true, verbose: false } },
{ command, opts: { echo: true, verbose: true } },
{
command: 'echo test',
command,
opts: { verbose: true, stdout: 'pipe', stderr: 'pipe' },
},
{ command: 'echo test', opts: { verbose: true, stdio: 'pipe' } },
{ command, opts: { verbose: true, stdio: 'pipe' } },
{
command: 'echo test',
command,
opts: { verbose: true, stdio: 'pipe', stdout: 'pipe', stderr: 'pipe' },
},
],
Expand Down

0 comments on commit edadd69

Please sign in to comment.