Skip to content

Commit

Permalink
Split tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed May 17, 2019
1 parent 0197385 commit 11d3261
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 44 deletions.
16 changes: 16 additions & 0 deletions test/echo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import test from 'ava'

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

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

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

testEach([{ command: 'echo test' }], (suffix, data) =>
test(`exec() ${suffix}`, t => snapshotTest({ t, data })),
)
2 changes: 1 addition & 1 deletion test/helpers/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const GULPFILES_DIR = `${__dirname}/gulpfiles`
// Almost all unit tests follow the same principle by calling this helper:
// - `gulp --gulpfile GULPFILE TASK` is fired using `execa`
// - the exit code, stdout and stderr are snapshot
export const snapshotTest = async function({ t, methodProps, data }) {
export const snapshotTest = async function({ t, methodProps = {}, data }) {
const { exitCode, stdout, stderr } = await fireTask({
...methodProps,
...data,
Expand Down
61 changes: 18 additions & 43 deletions test/main.js → test/invalid.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ import test from 'ava'

import { testEach } from './helpers/test_each/main.js'
import { snapshotTest } from './helpers/snapshot.js'
import { METHODS, STREAM_METHODS } from './helpers/methods.js'
import { METHODS } from './helpers/methods.js'

testEach(
METHODS,
[{ command: true }, { command: ' ' }],
(suffix, methodProps, data) =>
test(`Invalid command ${suffix}`, t =>
snapshotTest({ t, methodProps, data })),
)

testEach(
METHODS,
[
{ command: true },
{ command: ' ' },
{ command: 'echo test', opts: false },
{ command: 'echo test', opts: { cwd: false } },
{ command: 'echo test', opts: { env: false } },
Expand Down Expand Up @@ -38,50 +44,19 @@ testEach(
{ command: 'echo test', opts: { invalid: false } },
{ command: 'echo test', opts: { result: 'invalid' } },
{ command: 'echo test', opts: { from: 'invalid' } },
{ command: 'echo test', opts: { encoding: 'invalid' } },
{ command: 'invalid', read: false },
{ command: 'echo test' },
{ command: 'echo test', execaOpts: { env: { CI: '1' } } },
{ command: 'echo test', opts: { echo: true } },
{ command: 'echo test', opts: { verbose: true } },
{ 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: 'echo test',
opts: { verbose: true, stdout: 'pipe', stderr: 'pipe' },
},
{ command: 'echo test', opts: { verbose: true, stdio: 'pipe' } },
{
command: 'echo test',
opts: { verbose: true, stdio: 'pipe', stdout: 'pipe', stderr: 'pipe' },
},
],
(suffix, methodProps, data) => {
test(`Dummy test ${suffix}`, t => snapshotTest({ t, methodProps, data }))
},
(suffix, methodProps, data) =>
test(`Invalid options ${suffix}`, t =>
snapshotTest({ t, methodProps, data })),
)

test('should use the command as task name', t =>
snapshotTest({
t,
methodProps: { method: 'task' },
data: { task: 'nested', command: 'echo test' },
}))

testEach(
STREAM_METHODS,
METHODS,
[
{ task: 'inputNotFunc', command: 'echo test' },
{ task: 'inputThrows' },
{ task: 'inputAsync', command: 'echo test' },
{ task: 'inputFile', command: 'echo' },
{ task: 'inputUndefined' },
{ task: 'severalFiles', command: 'echo test' },
{ command: 'echo test', opts: { encoding: 'utf8' } },
{ command: 'echo test', opts: { stripFinalNewline: true } },
{ command: 'echo test', opts: { encoding: 'invalid' } },
{ command: 'invalid', read: false },
],
(suffix, methodProps, data) => {
test(`Dummy test ${suffix}`, t => snapshotTest({ t, methodProps, data }))
},
(suffix, methodProps, data) =>
test(`Errored command ${suffix}`, t =>
snapshotTest({ t, methodProps, data })),
)
22 changes: 22 additions & 0 deletions test/stream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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'

testEach(
STREAM_METHODS,
[
{ task: 'inputNotFunc', command: 'echo test' },
{ task: 'inputThrows' },
{ task: 'inputAsync', command: 'echo test' },
{ 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 } },
],
(suffix, methodProps, data) =>
test(`stream() ${suffix}`, t => snapshotTest({ t, methodProps, data })),
)
11 changes: 11 additions & 0 deletions test/task.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import test from 'ava'

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

testEach(
[{ command: 'echo test' }, { task: 'nested', command: 'echo test' }],
(suffix, data) =>
test(`task() ${suffix}`, t =>
snapshotTest({ t, methodProps: { method: 'task' }, data })),
)
30 changes: 30 additions & 0 deletions test/verbose.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import test from 'ava'

import { testEach } from './helpers/test_each/main.js'
import { snapshotTest } from './helpers/snapshot.js'
import { METHODS } from './helpers/methods.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: 'echo test',
opts: { verbose: true, stdout: 'pipe', stderr: 'pipe' },
},
{ command: 'echo test', opts: { verbose: true, stdio: 'pipe' } },
{
command: 'echo test',
opts: { verbose: true, stdio: 'pipe', stdout: 'pipe', stderr: 'pipe' },
},
],
(suffix, methodProps, data) =>
test(`'verbose' option ${suffix}`, t =>
snapshotTest({ t, methodProps, data })),
)

0 comments on commit 11d3261

Please sign in to comment.