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/readers/sync.spec.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const assert = require("assert");
const fs_macchiato_1 = require("@nodelib/fs.macchiato");
const sinon = require("sinon");
const settings_1 = require("../settings");
const tests = require("../tests");
const sync_1 = require("./sync");
class TestReader extends sync_1.default {
    constructor(options) {
        super(new settings_1.default(options));
        this._walkSync = sinon.stub();
        this._statSync = sinon.stub();
    }
    get walkSync() {
        return this._walkSync;
    }
    get statSync() {
        return this._statSync;
    }
}
function getReader(options) {
    return new TestReader(options);
}
function getReaderOptions(options = {}) {
    return Object.assign({}, options);
}
describe('Readers → ReaderSync', () => {
    describe('Constructor', () => {
        it('should create instance of class', () => {
            const reader = getReader();
            assert.ok(reader instanceof TestReader);
        });
    });
    describe('.dynamic', () => {
        it('should call fs.walk method', () => {
            const reader = getReader();
            const readerOptions = getReaderOptions();
            reader.dynamic('root', readerOptions);
            assert.ok(reader.walkSync.called);
        });
    });
    describe('.static', () => {
        it('should return entries', () => {
            const reader = getReader();
            const readerOptions = getReaderOptions({ entryFilter: () => true });
            reader.statSync.onFirstCall().returns(new fs_macchiato_1.Stats());
            reader.statSync.onSecondCall().returns(new fs_macchiato_1.Stats());
            const actual = reader.static(['a.txt', 'b.txt'], readerOptions);
            assert.strictEqual(actual[0].name, 'a.txt');
            assert.strictEqual(actual[1].name, 'b.txt');
        });
        it('should throw an error when the filter does not suppress the error', () => {
            const reader = getReader();
            const readerOptions = getReaderOptions({
                errorFilter: () => false,
                entryFilter: () => true
            });
            reader.statSync.onFirstCall().throws(tests.errno.getEperm());
            reader.statSync.onSecondCall().returns(new fs_macchiato_1.Stats());
            const expectedErrorMessageRe = /Error: EPERM: operation not permitted/;
            assert.throws(() => reader.static(['a.txt', 'b.txt'], readerOptions), expectedErrorMessageRe);
        });
        it('should do not throw an error when the filter suppress the error', () => {
            const reader = getReader();
            const readerOptions = getReaderOptions({
                errorFilter: () => true,
                entryFilter: () => true
            });
            reader.statSync.onFirstCall().throws(tests.errno.getEnoent());
            reader.statSync.onSecondCall().returns(new fs_macchiato_1.Stats());
            const actual = reader.static(['a.txt', 'b.txt'], readerOptions);
            assert.strictEqual(actual.length, 1);
            assert.strictEqual(actual[0].name, 'b.txt');
        });
        it('should do not include entry when the filter excludes it', () => {
            const reader = getReader();
            const readerOptions = getReaderOptions({ entryFilter: () => false });
            reader.statSync.returns(new fs_macchiato_1.Stats());
            const actual = reader.static(['a.txt'], readerOptions);
            assert.strictEqual(actual.length, 0);
        });
    });
});