From 11d32616dd5cc617a324e5737018fa7df5202a1c Mon Sep 17 00:00:00 2001 From: ehmicky Date: Fri, 17 May 2019 10:00:00 +0200 Subject: [PATCH] Split tests --- test/echo.js | 16 ++++++++++ test/exec.js | 8 +++++ test/helpers/snapshot.js | 2 +- test/{main.js => invalid.js} | 61 +++++++++++------------------------- test/stream.js | 22 +++++++++++++ test/task.js | 11 +++++++ test/verbose.js | 30 ++++++++++++++++++ 7 files changed, 106 insertions(+), 44 deletions(-) create mode 100644 test/echo.js create mode 100644 test/exec.js rename test/{main.js => invalid.js} (54%) create mode 100644 test/stream.js create mode 100644 test/task.js create mode 100644 test/verbose.js diff --git a/test/echo.js b/test/echo.js new file mode 100644 index 0000000..f375496 --- /dev/null +++ b/test/echo.js @@ -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 })), +) diff --git a/test/exec.js b/test/exec.js new file mode 100644 index 0000000..ade7fd9 --- /dev/null +++ b/test/exec.js @@ -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 })), +) diff --git a/test/helpers/snapshot.js b/test/helpers/snapshot.js index c49a76e..a43dcd6 100644 --- a/test/helpers/snapshot.js +++ b/test/helpers/snapshot.js @@ -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, diff --git a/test/main.js b/test/invalid.js similarity index 54% rename from test/main.js rename to test/invalid.js index fdc9a41..a4b5d2a 100644 --- a/test/main.js +++ b/test/invalid.js @@ -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 } }, @@ -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 })), ) diff --git a/test/stream.js b/test/stream.js new file mode 100644 index 0000000..66262a7 --- /dev/null +++ b/test/stream.js @@ -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 })), +) diff --git a/test/task.js b/test/task.js new file mode 100644 index 0000000..9ba2341 --- /dev/null +++ b/test/task.js @@ -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 })), +) diff --git a/test/verbose.js b/test/verbose.js new file mode 100644 index 0000000..442e249 --- /dev/null +++ b/test/verbose.js @@ -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 })), +)