HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/share/nodejs/fast-glob/out/providers/stream.spec.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const assert = require("assert");
const stream_1 = require("stream");
const sinon = require("sinon");
const stream_2 = require("../readers/stream");
const settings_1 = require("../settings");
const tests = require("../tests");
const stream_3 = require("./stream");
class TestProvider extends stream_3.default {
    constructor(options) {
        super(new settings_1.default(options));
        this._reader = sinon.createStubInstance(stream_2.default);
    }
    get reader() {
        return this._reader;
    }
}
function getProvider(options) {
    return new TestProvider(options);
}
function getEntries(provider, task, entry) {
    const reader = new stream_1.PassThrough({ objectMode: true });
    provider.reader.dynamic.returns(reader);
    provider.reader.static.returns(reader);
    reader.push(entry);
    reader.push(null);
    return new Promise((resolve, reject) => {
        const items = [];
        const api = provider.read(task);
        api.on('data', (item) => items.push(item));
        api.once('error', reject);
        api.once('end', () => resolve(items));
    });
}
describe('Providers → ProviderStream', () => {
    describe('Constructor', () => {
        it('should create instance of class', () => {
            const provider = getProvider();
            assert.ok(provider instanceof stream_3.default);
        });
    });
    describe('.read', () => {
        it('should return entries for dynamic entries', async () => {
            const provider = getProvider();
            const task = tests.task.builder().base('.').positive('*').build();
            const entry = tests.entry.builder().path('root/file.txt').file().build();
            const expected = ['root/file.txt'];
            const actual = await getEntries(provider, task, entry);
            assert.strictEqual(provider.reader.dynamic.callCount, 1);
            assert.deepStrictEqual(actual, expected);
        });
        it('should return entries for static entries', async () => {
            const provider = getProvider();
            const task = tests.task.builder().base('.').static().positive('root/file.txt').build();
            const entry = tests.entry.builder().path('root/file.txt').file().build();
            const expected = ['root/file.txt'];
            const actual = await getEntries(provider, task, entry);
            assert.strictEqual(provider.reader.static.callCount, 1);
            assert.deepStrictEqual(actual, expected);
        });
        it('should emit error to the transform stream', (done) => {
            const provider = getProvider();
            const task = tests.task.builder().base('.').positive('*').build();
            const stream = new stream_1.PassThrough({
                read() {
                    stream.emit('error', tests.errno.getEnoent());
                }
            });
            provider.reader.dynamic.returns(stream);
            const actual = provider.read(task);
            actual.once('error', (error) => {
                assert.strictEqual(error.code, 'ENOENT');
                done();
            });
        });
        it('should destroy source stream when the destination stream is closed', (done) => {
            const provider = getProvider();
            const task = tests.task.builder().base('.').positive('*').build();
            const stream = new stream_1.PassThrough();
            provider.reader.dynamic.returns(stream);
            const actual = provider.read(task);
            actual.once('close', () => {
                assert.ok(stream.destroyed);
                done();
            });
            actual.emit('close');
        });
    });
});