"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var chai_1 = require("chai");
var implementation_suite_1 = require("./implementation-suite");
var slow_fs_1 = require("../test-kit/drivers/slow-fs");
var universal_1 = require("../src/universal");
describe('the timeout file system implementation', function () {
    var timeout = 200;
    implementation_suite_1.assertFileSystemContract(function () {
        return Promise.resolve(new universal_1.TimeoutFileSystem(timeout, new universal_1.MemoryFileSystem(undefined, [implementation_suite_1.ignoredDir, implementation_suite_1.ignoredFile])));
    }, { retries: 15, interval: 2, timeout: 40, noExtraEventsGrace: 10 });
    describe("delayed timeout test", function () {
        var fs;
        var startTimestamp;
        var delay = timeout * 2;
        beforeEach(function () {
            startTimestamp = Date.now();
            fs = new universal_1.TimeoutFileSystem(timeout, new slow_fs_1.SlowFs(delay));
        });
        it("ensureDirectory exit before delay is over", function () {
            return chai_1.expect(fs.ensureDirectory(implementation_suite_1.dirName)).to.eventually.be.rejectedWith('timed out')
                .then(function () { return chai_1.expect(startTimestamp - Date.now()).to.be.below(delay); });
        });
        it("saveFile exit before delay is over", function () {
            return chai_1.expect(fs.saveFile(implementation_suite_1.dirName + "\\" + implementation_suite_1.fileName, '#goodnessSquad')).to.eventually.be.rejectedWith('timed out')
                .then(function () { return chai_1.expect(startTimestamp - Date.now()).to.be.below(delay); });
        });
        it("deleteFile exit before delay is over", function () {
            return chai_1.expect(fs.deleteFile(implementation_suite_1.dirName + "\\" + implementation_suite_1.fileName)).to.eventually.be.rejectedWith('timed out')
                .then(function () { return chai_1.expect(startTimestamp - Date.now()).to.be.below(delay); });
        });
        it("deleteDirectory exit before delay is over", function () {
            return chai_1.expect(fs.deleteDirectory(implementation_suite_1.dirName)).to.eventually.be.rejectedWith('timed out')
                .then(function () { return chai_1.expect(startTimestamp - Date.now()).to.be.below(delay); });
        });
        it("loadTextFile exit before delay is over", function () {
            return chai_1.expect(fs.loadTextFile(implementation_suite_1.dirName)).to.eventually.be.rejectedWith('timed out')
                .then(function () { return chai_1.expect(startTimestamp - Date.now()).to.be.below(delay); });
        });
        it("loadDirectoryTree exit before delay is over", function () {
            return chai_1.expect(fs.loadDirectoryTree()).to.eventually.be.rejectedWith('timed out')
                .then(function () { return chai_1.expect(startTimestamp - Date.now()).to.be.below(delay); });
        });
    });
});
//# sourceMappingURL=timeout-fs.spec.js.map