import { pathToFileURL } from 'node:url';
import { ReadableStream, DecompressionStream, TextDecoderStream } from 'node:stream/web';
-import { csvStreamEqualWritable, csvStreamNotEqualWritable, createCSVMockStream, createTempFile } from './utils.js';
+import { csvStreamEqualWritable, createCSVMockStream, createTempFile } from './utils.js';
import { parsePathLike, createFileStream, CSVReader, CSVTransformer, CSVWriter } from '../src/core.js';
suite('CSVWriter.arrayToCSVString', { concurrency: true }, () => {
input: './data/blank.csv',
output: [
['']
- ],
- negativeOutput: [
- ['a']
]
}
];
- for (const { name, input, options = {}, output, negativeOutput } of vectors) {
+ for (const { name, input, options = {}, output } of vectors) {
test(name, { concurrency: true }, async () => {
const path = new URL(input, import.meta.url); // Makes the path relative to this file, not the command's execution directory
await new CSVReader(path, options).pipeTo(csvStreamEqualWritable(output));
- if (negativeOutput !== undefined) {
- await new CSVReader(path, options).pipeTo(csvStreamNotEqualWritable(negativeOutput));
- }
});
}
test('can cancel', { concurrency: true }, async () => {
});
}
-/**
- * Negative version of `csvStreamEqualWritable`. Tests that the piped stream is NOT equal to the given CSV.
- *
- * @param {Array<Array<string>>} csv A 2-D array representing the CSV file, where each inner array
- * is a row of the CSV.
- * @returns {WritableStream} A `WritableStream` sink of a CSV stream that will be compared against the given array.
- */
-export function csvStreamNotEqualWritable(csv) {
- let i = 0;
- return new WritableStream({
- write(chunk) {
- for (let j = 0; j < csv[i].length; j++) {
- notStrictEqual(chunk[j], csv[i][j]);
- }
- i++;
- }
- });
-}
-
/**
* @typedef AssertConsoleCounts Object containing the total number of times `console.log`, `console.info`, `console.warn`,
* and `console.error` are expected to be called.