Skip to content

Commit

Permalink
Upgrade xo (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky authored Jul 21, 2024
1 parent ee6de5c commit cd27167
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@
"precise-now": "^3.0.0",
"stream-json": "^1.8.0",
"tsd": "^0.31.0",
"xo": "^0.58.0"
"xo": "^0.59.0"
}
}
1 change: 1 addition & 0 deletions source/array-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const resizeArrayBuffer = (contents, length) => {
return contents;
}

// eslint-disable-next-line n/no-unsupported-features/es-syntax
const arrayBuffer = new ArrayBuffer(length, {maxByteLength: getNewContentsLength(length)});
new Uint8Array(arrayBuffer).set(new Uint8Array(contents), 0);
return arrayBuffer;
Expand Down
1 change: 1 addition & 0 deletions source/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export class MaxBufferError extends Error {

// eslint-disable-next-line @typescript-eslint/ban-types
type TextStreamItem = string | Buffer | ArrayBuffer | ArrayBufferView;
// eslint-disable-next-line n/no-unsupported-features/node-builtins
export type AnyStream<SteamItem = TextStreamItem> = Readable | ReadableStream<SteamItem> | AsyncIterable<SteamItem>;

export type Options = {
Expand Down
1 change: 1 addition & 0 deletions source/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ expectError(await getStreamAsArrayBuffer(nodeStream, {maxBuffer: 10}, {}));
expectType<any[]>(await getStreamAsArray(nodeStream));
expectType<any[]>(await getStreamAsArray(nodeStream, {maxBuffer: 10}));
expectType<any[]>(await getStreamAsArray(readableStream));
// eslint-disable-next-line n/no-unsupported-features/node-builtins
expectType<Uint8Array[]>(await getStreamAsArray(readableStream as ReadableStream<Uint8Array>));
expectType<string[]>(await getStreamAsArray(stringAsyncIterable));
// eslint-disable-next-line @typescript-eslint/ban-types
Expand Down
4 changes: 2 additions & 2 deletions test/browser.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {execFile} from 'node:child_process';
import {dirname} from 'node:path';
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import {promisify} from 'node:util';
import test from 'ava';
import {fixtureString} from './fixtures/index.js';

const pExecFile = promisify(execFile);
const cwd = dirname(fileURLToPath(import.meta.url));
const cwd = path.dirname(fileURLToPath(import.meta.url));
const nodeStreamFixture = './fixtures/node-stream.js';
const webStreamFixture = './fixtures/web-stream.js';
const iterableFixture = './fixtures/iterable.js';
Expand Down
1 change: 1 addition & 0 deletions test/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {finished} from 'node:stream/promises';
export {fromAnyIterable as readableStreamFrom} from '@sec-ant/readable-stream/ponyfill';

export const createStream = streamDefinition => typeof streamDefinition === 'function'
// eslint-disable-next-line n/no-unsupported-features/node-builtins
? Duplex.from(streamDefinition)
: Readable.from(streamDefinition);

Expand Down
3 changes: 3 additions & 0 deletions test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {fixtureString, fixtureBuffer, fixtureUtf16} from './fixtures/index.js';

const TEST_URL = 'https://nodejs.org/dist/index.json';

// eslint-disable-next-line n/no-unsupported-features/node-builtins
const createReadableStream = streamDefinition => Duplex.toWeb(Duplex.from(streamDefinition)).readable;

test('works with opendir()', async t => {
Expand Down Expand Up @@ -63,13 +64,15 @@ if (!nodeVersion.startsWith('v16.')) {
test('works with readableWebStream({ type: "bytes" })', readableWebStream, 'bytes');

test('works with fetch()', async t => {
// eslint-disable-next-line n/no-unsupported-features/node-builtins
const {body} = await fetch(TEST_URL);
const result = await getStream(body);
const parsedResult = JSON.parse(result);
t.true(Array.isArray(parsedResult));
});

test('can use TextDecoderStream', async t => {
// eslint-disable-next-line n/no-unsupported-features/node-builtins
const textDecoderStream = new TextDecoderStream('utf-16le');
const result = await getStream(
createReadableStream(fixtureUtf16).pipeThrough(textDecoderStream),
Expand Down
1 change: 1 addition & 0 deletions test/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ const testMultipleReads = async (t, wait) => {
assertSuccess(t, stream, Readable);
};

// eslint-disable-next-line n/no-unsupported-features/node-builtins
test('Handles multiple successive fast reads', testMultipleReads, () => scheduler.yield());
test('Handles multiple successive slow reads', testMultipleReads, () => pSetTimeout(100));

Expand Down
4 changes: 4 additions & 0 deletions test/web-stream-ponyfill.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import test from 'ava';

// Emulate browsers that do not support those methods
// eslint-disable-next-line n/no-unsupported-features/node-builtins
delete ReadableStream.prototype.values;
// eslint-disable-next-line n/no-unsupported-features/node-builtins
delete ReadableStream.prototype[Symbol.asyncIterator];

// Run those tests, but emulating browsers
await import('./web-stream.js');

test('Should not polyfill ReadableStream', t => {
// eslint-disable-next-line n/no-unsupported-features/node-builtins
t.is(ReadableStream.prototype.values, undefined);
// eslint-disable-next-line n/no-unsupported-features/node-builtins
t.is(ReadableStream.prototype[Symbol.asyncIterator], undefined);
});
3 changes: 3 additions & 0 deletions test/web-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ test('Can use already ended ReadableStream', async t => {

test('Can use already canceled ReadableStream', async t => {
let canceledValue;
// eslint-disable-next-line n/no-unsupported-features/node-builtins
const stream = new ReadableStream({
cancel(canceledError) {
canceledValue = canceledError;
Expand All @@ -32,6 +33,7 @@ test('Can use already canceled ReadableStream', async t => {

test('Can use already errored ReadableStream', async t => {
const error = new Error('test');
// eslint-disable-next-line n/no-unsupported-features/node-builtins
const stream = new ReadableStream({
start(controller) {
controller.error(error);
Expand All @@ -43,6 +45,7 @@ test('Can use already errored ReadableStream', async t => {

test('Cancel ReadableStream when maxBuffer is hit', async t => {
let canceled = false;
// eslint-disable-next-line n/no-unsupported-features/node-builtins
const stream = new ReadableStream({
start(controller) {
controller.enqueue(fixtureString);
Expand Down

0 comments on commit cd27167

Please sign in to comment.