Skip to content
Myr

convert.js

This file

Path

test/helpers/convert.js

80 lines · 2.7 KiB · JavaScript

Last changed by

TweaksSindre Sorhusbefore adoption698a1b8

History of this file

Take 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 back
1import {text} from 'node:stream/consumers';
2import {finished} from 'node:stream/promises';

TweaksSindre Sorhusbefore adoption698a1b8

line 3why, one step back
3import assert from 'node:assert/strict';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 4–6why, one step back
4import getStream from 'get-stream';
5import isPlainObj from 'is-plain-obj';6import {execa} from '../../index.js';

TweaksSindre Sorhusbefore adoption698a1b8

line 7why, one step back
7import {assertRejects} from './assert.js';

Require Node.js 22 (#1243)Sindre Sorhusbefore adoption04b4454

line 8why, one step back
8import {foobarString} from './input.js';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 9–19why, one step back
9
10export 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});19

TweaksSindre Sorhusbefore adoption698a1b8

lines 20–23why, one step back
20export 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 back
24};
25

TweaksSindre Sorhusbefore adoption698a1b8

lines 26–29why, one step back
26export 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 back
30};
31

TweaksSindre Sorhusbefore adoption698a1b8

lines 32–34why, one step back
32export 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 back
35};
36

TweaksSindre Sorhusbefore adoption698a1b8

lines 37–38why, one step back
37export const assertStreamOutput = async (stream, expectedOutput = foobarString) => {
38 assert.equal(await text(stream), expectedOutput);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 39–40why, one step back
39};
40

TweaksSindre Sorhusbefore adoption698a1b8

lines 41–42why, one step back
41export const assertStreamDataEvents = async (stream, expectedOutput = foobarString) => {
42 assert.equal(await getStream(stream), expectedOutput);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 43–44why, one step back
43};
44

TweaksSindre Sorhusbefore adoption698a1b8

lines 45–46why, one step back
45export const assertIterableChunks = async (asyncIterable, expectedChunks) => {
46 assert.deepEqual(await arrayFromAsync(asyncIterable), expectedChunks);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 47–48why, one step back
47};
48

TweaksSindre Sorhusbefore adoption698a1b8

lines 49–50why, one step back
49export const assertStreamChunks = async (stream, expectedOutput) => {
50 assert.deepEqual(await stream.toArray(), expectedOutput);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 51–52why, one step back
51};
52

TweaksSindre Sorhusbefore adoption698a1b8

line 53why, one step back
53export const assertSubprocessOutput = async (subprocess, expectedOutput = foobarString, fdNumber = 1) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 54why, one step back
54 const result = await subprocess;

TweaksSindre Sorhusbefore adoption698a1b8

line 55why, one step back
55 assert.deepEqual(result.stdio[fdNumber], expectedOutput);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 56–57why, one step back
56};
57

TweaksSindre Sorhusbefore adoption698a1b8

line 58why, one step back
58export const assertStreamError = (stream, error) => assertPromiseError(finishedStream(stream), error);

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 59why, one step back
59

TweaksSindre Sorhusbefore adoption698a1b8

line 60why, one step back
60export const assertStreamReadError = (stream, error) => assertPromiseError(text(stream), error);

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 61why, one step back
61

TweaksSindre Sorhusbefore adoption698a1b8

line 62why, one step back
62export const assertSubprocessError = (subprocess, error) => assertPromiseError(subprocess, error);

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 63why, one step back
63

TweaksSindre Sorhusbefore adoption698a1b8

lines 64–65why, one step back
64export const assertPromiseError = async (promise, error) => {
65 const thrownError = await assertRejects(promise);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 66–67why, one step back
66
67 if (isPlainObj(error) && error.cause !== undefined) {

TweaksSindre Sorhusbefore adoption698a1b8

line 68why, one step back
68 assert.equal(thrownError.cause, error.cause);

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 69why, one step back
69 } else {

TweaksSindre Sorhusbefore adoption698a1b8

line 70why, one step back
70 assert.equal(thrownError, error);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 71–80why, one step back
71 }
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);