"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 async_1 = require("./async"); class TestProvider extends async_1.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 provider.read(task); } describe('Providers → ProviderAsync', () => { describe('Constructor', () => { it('should create instance of class', () => { const provider = getProvider(); assert.ok(provider instanceof async_1.default); }); }); describe('.read', () => { it('should return entries for dynamic task', async () => { const provider = getProvider(); const task = tests.task.builder().base('.').positive('*').build(); const entry = tests.entry.builder().path('root/file.txt').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 task', async () => { const provider = getProvider(); const task = tests.task.builder().base('.').static().positive('*').build(); const entry = tests.entry.builder().path('root/file.txt').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 throw error', async () => { 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); try { await provider.read(task); throw new Error('Wow'); } catch (error) { assert.strictEqual(error.code, 'ENOENT'); } }); }); });