From 5f103780a6d634da6ebe8804b0be688fce13b036 Mon Sep 17 00:00:00 2001 From: ehmicky Date: Fri, 17 May 2019 10:00:00 +0200 Subject: [PATCH] Add comments --- test/helpers/gulpfiles/stream.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/test/helpers/gulpfiles/stream.js b/test/helpers/gulpfiles/stream.js index 749bce1..89417a3 100644 --- a/test/helpers/gulpfiles/stream.js +++ b/test/helpers/gulpfiles/stream.js @@ -14,34 +14,41 @@ const { command, opts, buffer, read } = getInput() const DUMMY = `${__dirname}/dummy.txt` const DUMMY_TWO = `${__dirname}/dummy_two.txt` +// Task used in most tests export const main = () => src(DUMMY, { buffer }) .pipe(stream(() => command, opts)) .pipe(through.obj(execVinyl)) +// `input` should be an async function export const inputAsync = () => src(DUMMY, { buffer }) .pipe(stream(() => Promise.resolve(command), opts)) .pipe(through.obj(execVinyl)) +// `input` should be fired with the Vinyl file export const inputFile = () => src(DUMMY, { buffer }) .pipe(stream(({ path }) => `${command} ${path}`, opts)) .pipe(through.obj(execVinyl)) +// File should be skipped when returning a non-string export const inputUndefined = () => src(DUMMY, { buffer }) .pipe(stream(() => undefined, opts)) .pipe(through.obj(execVinyl)) +// Should allow several files export const severalFiles = () => src([DUMMY, DUMMY_TWO], { buffer }) .pipe(stream(() => command, opts)) .pipe(through.obj(execVinyl)) +// `input` should be a function export const inputNotFunc = () => src(DUMMY, { buffer }).pipe(stream(command, opts)) +// `input` exceptions should be propagated export const inputThrows = () => src(DUMMY, { buffer }).pipe( stream(() => { @@ -57,12 +64,16 @@ const cExecVinyl = async function(file) { return file } + // Prints `file.contents` so that unit test can snapshot it const string = await stringifyContents(file) // eslint-disable-next-line no-restricted-globals, no-console console.log(string) return file } +const execVinyl = callbackify(cExecVinyl) + +// Each method must be stringified differently const stringifyContents = function({ contents, execa }) { if (execa !== undefined) { return JSON.stringify(execa, null, 2) @@ -74,5 +85,3 @@ const stringifyContents = function({ contents, execa }) { return getStream(contents) } - -const execVinyl = callbackify(cExecVinyl)