convert.js
This file
Path
test/helpers/convert.js
80 lines · 2.7 KiB · JavaScript
Last changed by
TweaksSindre Sorhusbefore adoption698a1b8
History of this fileTake it
The walk stopped after 200 commits: lines older than 9f65b86 point at it.
100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 1–2why, one step back1import {text} from 'node:stream/consumers';2import {finished} from 'node:stream/promises';TweaksSindre Sorhusbefore adoption698a1b8
line 3why, one step back3import assert from 'node:assert/strict';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 4–6why, one step back4import getStream from 'get-stream';5import isPlainObj from 'is-plain-obj';6import {execa} from '../../index.js';TweaksSindre Sorhusbefore adoption698a1b8
line 7why, one step back7import {assertRejects} from './assert.js';Require Node.js 22 (#1243)Sindre Sorhusbefore adoption04b4454
line 8why, one step back8import {foobarString} from './input.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 9–19why, one step back910export const arrayFromAsync = async (asyncIterable, lines = []) => {11 for await (const line of asyncIterable) {12 lines.push(line);13 }1415 return lines;16};1718export const finishedStream = stream => finished(stream, {cleanup: true});19TweaksSindre Sorhusbefore adoption698a1b8
lines 20–23why, one step back20export const assertWritableAborted = writable => {21 assert.equal(writable.writableEnded, false);22 assert.equal(writable.errored, null);23 assert.equal(writable.writable, false);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 24–25why, one step back24};25TweaksSindre Sorhusbefore adoption698a1b8
lines 26–29why, one step back26export const assertReadableAborted = readable => {27 assert.equal(readable.readableEnded, false);28 assert.equal(readable.errored, null);29 assert.equal(readable.readable, false);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 30–31why, one step back30};31TweaksSindre Sorhusbefore adoption698a1b8
lines 32–34why, one step back32export const assertProcessNormalExit = (error, exitCode = 0) => {33 assert.equal(error.exitCode, exitCode);34 assert.equal(error.signal, undefined);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 35–36why, one step back35};36TweaksSindre Sorhusbefore adoption698a1b8
lines 37–38why, one step back37export const assertStreamOutput = async (stream, expectedOutput = foobarString) => {38 assert.equal(await text(stream), expectedOutput);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 39–40why, one step back39};40TweaksSindre Sorhusbefore adoption698a1b8
lines 41–42why, one step back41export const assertStreamDataEvents = async (stream, expectedOutput = foobarString) => {42 assert.equal(await getStream(stream), expectedOutput);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 43–44why, one step back43};44TweaksSindre Sorhusbefore adoption698a1b8
lines 45–46why, one step back45export const assertIterableChunks = async (asyncIterable, expectedChunks) => {46 assert.deepEqual(await arrayFromAsync(asyncIterable), expectedChunks);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 47–48why, one step back47};48TweaksSindre Sorhusbefore adoption698a1b8
lines 49–50why, one step back49export const assertStreamChunks = async (stream, expectedOutput) => {50 assert.deepEqual(await stream.toArray(), expectedOutput);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 51–52why, one step back51};52TweaksSindre Sorhusbefore adoption698a1b8
line 53why, one step back53export const assertSubprocessOutput = async (subprocess, expectedOutput = foobarString, fdNumber = 1) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 54why, one step back54 const result = await subprocess;TweaksSindre Sorhusbefore adoption698a1b8
line 55why, one step back55 assert.deepEqual(result.stdio[fdNumber], expectedOutput);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 56–57why, one step back56};57TweaksSindre Sorhusbefore adoption698a1b8
line 58why, one step back58export const assertStreamError = (stream, error) => assertPromiseError(finishedStream(stream), error);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 59why, one step back59TweaksSindre Sorhusbefore adoption698a1b8
line 60why, one step back60export const assertStreamReadError = (stream, error) => assertPromiseError(text(stream), error);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 61why, one step back61TweaksSindre Sorhusbefore adoption698a1b8
line 62why, one step back62export const assertSubprocessError = (subprocess, error) => assertPromiseError(subprocess, error);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 63why, one step back63TweaksSindre Sorhusbefore adoption698a1b8
lines 64–65why, one step back64export const assertPromiseError = async (promise, error) => {65 const thrownError = await assertRejects(promise);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 66–67why, one step back6667 if (isPlainObj(error) && error.cause !== undefined) {TweaksSindre Sorhusbefore adoption698a1b8
line 68why, one step back68 assert.equal(thrownError.cause, error.cause);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 69why, one step back69 } else {TweaksSindre Sorhusbefore adoption698a1b8
line 70why, one step back70 assert.equal(thrownError, error);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 71–80why, one step back71 }7273 return thrownError;74};7576export const getReadableSubprocess = (output = foobarString, options = {}) => execa('noop-fd.js', ['1', output], options);7778export const getWritableSubprocess = () => execa('noop-stdin-fd.js', ['2']);7980export const getReadWriteSubprocess = options => execa('stdin.js', options);