mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-25 01:46:14 -04:00
Moved path_exists and promises to es6
This commit is contained in:
parent
6ed711a4d8
commit
4ff00e278a
8 changed files with 59 additions and 31 deletions
22
src/tests/backend-new/specs/path_exists.ts
Normal file
22
src/tests/backend-new/specs/path_exists.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
import check from "../../../node/utils/path_exists";
|
||||
import {expect, describe, it} from "vitest";
|
||||
|
||||
describe('Test path exists', function () {
|
||||
it('should return true if the path exists - directory', function () {
|
||||
const path = './locales';
|
||||
const result = check(path);
|
||||
expect(result).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should return true if the path exists - file', function () {
|
||||
const path = './locales/en.json';
|
||||
const result = check(path);
|
||||
expect(result).toBeTruthy();
|
||||
})
|
||||
|
||||
it('should return false if the path does not exist', function () {
|
||||
const path = './path_not_exists.ts';
|
||||
const result = check(path);
|
||||
expect(result).toEqual(false);
|
||||
});
|
||||
})
|
|
@ -1,7 +1,7 @@
|
|||
import {MapArrayType} from "../../../node/types/MapType";
|
||||
|
||||
const assert = require('assert').strict;
|
||||
const promises = require('../../../node/utils/promises');
|
||||
import {timesLimit} from '../../../node/utils/promises';
|
||||
import {describe, it, expect} from "vitest";
|
||||
|
||||
describe(__filename, function () {
|
||||
describe('promises.timesLimit', function () {
|
||||
|
@ -15,7 +15,7 @@ describe(__filename, function () {
|
|||
const testPromises: TestPromise[] = [];
|
||||
const makePromise = (index: number) => {
|
||||
// Make sure index increases by one each time.
|
||||
assert.equal(index, wantIndex++);
|
||||
expect(index).toEqual(wantIndex++);
|
||||
// Save the resolve callback (so the test can trigger resolution)
|
||||
// and the promise itself (to wait for resolve to take effect).
|
||||
const p:TestPromise = {};
|
||||
|
@ -28,17 +28,17 @@ describe(__filename, function () {
|
|||
|
||||
const total = 11;
|
||||
const concurrency = 7;
|
||||
const timesLimitPromise = promises.timesLimit(total, concurrency, makePromise);
|
||||
const timesLimitPromise = timesLimit(total, concurrency, makePromise);
|
||||
|
||||
it('honors concurrency', async function () {
|
||||
assert.equal(wantIndex, concurrency);
|
||||
expect(wantIndex).toEqual(concurrency);
|
||||
});
|
||||
|
||||
it('creates another when one completes', async function () {
|
||||
const {promise, resolve} = testPromises.shift()!;
|
||||
resolve!();
|
||||
await promise;
|
||||
assert.equal(wantIndex, concurrency + 1);
|
||||
expect(wantIndex).toEqual(concurrency + 1);
|
||||
});
|
||||
|
||||
it('creates the expected total number of promises', async function () {
|
||||
|
@ -49,7 +49,7 @@ describe(__filename, function () {
|
|||
resolve!();
|
||||
await promise;
|
||||
}
|
||||
assert.equal(wantIndex, total);
|
||||
expect(wantIndex).toEqual(total);
|
||||
});
|
||||
|
||||
it('resolves', async function () {
|
||||
|
@ -58,35 +58,35 @@ describe(__filename, function () {
|
|||
|
||||
it('does not create too many promises if total < concurrency', async function () {
|
||||
wantIndex = 0;
|
||||
assert.equal(testPromises.length, 0);
|
||||
expect(testPromises.length).toEqual(0);
|
||||
const total = 7;
|
||||
const concurrency = 11;
|
||||
const timesLimitPromise = promises.timesLimit(total, concurrency, makePromise);
|
||||
const timesLimitPromise = timesLimit(total, concurrency, makePromise);
|
||||
while (testPromises.length > 0) {
|
||||
const {promise, resolve} = testPromises.pop()!;
|
||||
resolve!();
|
||||
await promise;
|
||||
}
|
||||
await timesLimitPromise;
|
||||
assert.equal(wantIndex, total);
|
||||
expect(wantIndex).toEqual(total);
|
||||
});
|
||||
|
||||
it('accepts total === 0, concurrency > 0', async function () {
|
||||
wantIndex = 0;
|
||||
assert.equal(testPromises.length, 0);
|
||||
await promises.timesLimit(0, concurrency, makePromise);
|
||||
assert.equal(wantIndex, 0);
|
||||
expect(testPromises.length).toEqual(0);
|
||||
await timesLimit(0, concurrency, makePromise);
|
||||
expect(wantIndex).toEqual(0);
|
||||
});
|
||||
|
||||
it('accepts total === 0, concurrency === 0', async function () {
|
||||
wantIndex = 0;
|
||||
assert.equal(testPromises.length, 0);
|
||||
await promises.timesLimit(0, 0, makePromise);
|
||||
assert.equal(wantIndex, 0);
|
||||
expect(testPromises.length).toEqual(0);
|
||||
await timesLimit(0, 0, makePromise);
|
||||
expect(wantIndex).toEqual(0);
|
||||
});
|
||||
|
||||
it('rejects total > 0, concurrency === 0', async function () {
|
||||
await assert.rejects(promises.timesLimit(total, 0, makePromise), RangeError);
|
||||
expect(timesLimit(total, 0, makePromise)).rejects.toThrow(RangeError);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue