fix and optimize tests

This commit is contained in:
fyears 2024-04-27 03:28:39 +08:00
parent 3bb7355db3
commit a9126e5947
5 changed files with 106 additions and 121 deletions

View File

@ -36,8 +36,6 @@
"@types/node": "^20.12.7", "@types/node": "^20.12.7",
"@types/qrcode": "^1.5.5", "@types/qrcode": "^1.5.5",
"builtin-modules": "^3.3.0", "builtin-modules": "^3.3.0",
"chai": "^4.4.1",
"chai-as-promised": "^7.1.1",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"dotenv": "^16.4.5", "dotenv": "^16.4.5",
"esbuild": "^0.20.2", "esbuild": "^0.20.2",

View File

@ -1,12 +1,8 @@
import * as chai from "chai"; import { strict as assert } from "assert";
import chaiAsPromised from "chai-as-promised";
import { RemotelySavePluginSettings } from "../src/baseTypes"; import { RemotelySavePluginSettings } from "../src/baseTypes";
import { messyConfigToNormal, normalConfigToMessy } from "../src/configPersist"; import { messyConfigToNormal, normalConfigToMessy } from "../src/configPersist";
chai.use(chaiAsPromised);
const expect = chai.expect;
const DEFAULT_SETTINGS: RemotelySavePluginSettings = { const DEFAULT_SETTINGS: RemotelySavePluginSettings = {
s3: { s3: {
s3AccessKeyID: "acc", s3AccessKeyID: "acc",
@ -32,6 +28,6 @@ describe("Config Persist tests", () => {
const k = DEFAULT_SETTINGS; const k = DEFAULT_SETTINGS;
const k2 = normalConfigToMessy(k); const k2 = normalConfigToMessy(k);
const k3 = messyConfigToNormal(k2); const k3 = messyConfigToNormal(k2);
expect(k3).to.deep.equal(k); assert.deepEqual(k3, k);
}); });
}); });

View File

@ -1,5 +1,4 @@
import * as chai from "chai"; import { strict as assert } from "assert";
import chaiAsPromised from "chai-as-promised";
import * as fs from "fs"; import * as fs from "fs";
import * as path from "path"; import * as path from "path";
import { import {
@ -13,9 +12,6 @@ import {
} from "../src/encryptOpenSSL"; } from "../src/encryptOpenSSL";
import { base64ToBase64url, bufferToArrayBuffer } from "../src/misc"; import { base64ToBase64url, bufferToArrayBuffer } from "../src/misc";
chai.use(chaiAsPromised);
const expect = chai.expect;
describe("Encryption OpenSSL tests", () => { describe("Encryption OpenSSL tests", () => {
beforeEach(function () { beforeEach(function () {
global.window = { global.window = {
@ -26,7 +22,7 @@ describe("Encryption OpenSSL tests", () => {
it("should encrypt string", async () => { it("should encrypt string", async () => {
const k = "dkjdhkfhdkjgsdklxxd"; const k = "dkjdhkfhdkjgsdklxxd";
const password = "hey"; const password = "hey";
expect(await encryptStringToBase32(k, password)).to.not.equal(k); assert.notEqual(await encryptStringToBase32(k, password), k);
}); });
it("should encrypt string and return different results each time", async () => { it("should encrypt string and return different results each time", async () => {
@ -34,7 +30,7 @@ describe("Encryption OpenSSL tests", () => {
const password = "hey"; const password = "hey";
const res1 = await encryptStringToBase32(k, password); const res1 = await encryptStringToBase32(k, password);
const res2 = await encryptStringToBase32(k, password); const res2 = await encryptStringToBase32(k, password);
expect(res1).to.not.equal(res2); assert.notEqual(res1, res2);
}); });
it("should raise error using different password", async () => { it("should raise error using different password", async () => {
@ -42,7 +38,7 @@ describe("Encryption OpenSSL tests", () => {
const password = "hey"; const password = "hey";
const password2 = "hey2"; const password2 = "hey2";
const enc = await encryptStringToBase32(k, password); const enc = await encryptStringToBase32(k, password);
await expect(decryptBase32ToString(enc, password2)).to.be.rejected; await assert.rejects(decryptBase32ToString(enc, password2));
}); });
it("should encrypt and decrypt string and get the same result returned", async () => { it("should encrypt and decrypt string and get the same result returned", async () => {
@ -52,7 +48,7 @@ describe("Encryption OpenSSL tests", () => {
// console.log(enc); // console.log(enc);
const dec = await decryptBase32ToString(enc, password); const dec = await decryptBase32ToString(enc, password);
// console.log(dec); // console.log(dec);
expect(dec).equal(k); assert.equal(dec, k);
}); });
it("should encrypt text file and get the same result as openssl", async () => { it("should encrypt text file and get the same result as openssl", async () => {
@ -78,7 +74,7 @@ describe("Encryption OpenSSL tests", () => {
// we output base32, so we need some transformation // we output base32, so we need some transformation
const opensslBase64urlRes = base64ToBase64url(opensslBase64Res); const opensslBase64urlRes = base64ToBase64url(opensslBase64Res);
expect(enc).equal(opensslBase64urlRes); assert.equal(enc, opensslBase64urlRes);
}); });
it("should encrypt binary file and get the same result as openssl", async () => { it("should encrypt binary file and get the same result as openssl", async () => {
@ -102,7 +98,7 @@ describe("Encryption OpenSSL tests", () => {
// openssl enc -p -aes-256-cbc -S 8302F586FAB491EC -pbkdf2 -iter 20000 -pass pass:somepassword -in mona_lisa/1374px-Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg -out mona_lisa/1374px-Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg.enc // openssl enc -p -aes-256-cbc -S 8302F586FAB491EC -pbkdf2 -iter 20000 -pass pass:somepassword -in mona_lisa/1374px-Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg -out mona_lisa/1374px-Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg.enc
expect(Buffer.from(enc).equals(Buffer.from(opensslArrBuf))).to.be.true; assert.ok(Buffer.from(enc).equals(Buffer.from(opensslArrBuf)));
}); });
it("should encrypt binary file not deterministically", async () => { it("should encrypt binary file not deterministically", async () => {
@ -116,7 +112,7 @@ describe("Encryption OpenSSL tests", () => {
const res1 = await encryptArrayBuffer(fileArrBuf, password); const res1 = await encryptArrayBuffer(fileArrBuf, password);
const res2 = await encryptArrayBuffer(fileArrBuf, password); const res2 = await encryptArrayBuffer(fileArrBuf, password);
expect(Buffer.from(res1).equals(Buffer.from(res2))).to.be.false; assert.ok(!Buffer.from(res1).equals(Buffer.from(res2)));
}); });
it("should decrypt binary file and get the same result as openssl", async () => { it("should decrypt binary file and get the same result as openssl", async () => {
@ -132,36 +128,36 @@ describe("Encryption OpenSSL tests", () => {
await fs.readFileSync(path.join(testFolder, testFileName)) await fs.readFileSync(path.join(testFolder, testFileName))
); );
expect(Buffer.from(dec).equals(Buffer.from(opensslArrBuf))).to.be.true; assert.deepEqual(Buffer.from(dec), Buffer.from(opensslArrBuf));
}); });
it("should get size from origin to encrypted correctly", () => { it("should get size from origin to encrypted correctly", () => {
expect(() => getSizeFromOrigToEnc(-1)).to.throw(); assert.throws(() => getSizeFromOrigToEnc(-1));
expect(() => getSizeFromOrigToEnc(0.5)).to.throw(); assert.throws(() => getSizeFromOrigToEnc(0.5));
expect(getSizeFromOrigToEnc(0)).equals(32); assert.equal(getSizeFromOrigToEnc(0), 32);
expect(getSizeFromOrigToEnc(15)).equals(32); assert.equal(getSizeFromOrigToEnc(15), 32);
expect(getSizeFromOrigToEnc(16)).equals(48); assert.equal(getSizeFromOrigToEnc(16), 48);
expect(getSizeFromOrigToEnc(31)).equals(48); assert.equal(getSizeFromOrigToEnc(31), 48);
expect(getSizeFromOrigToEnc(32)).equals(64); assert.equal(getSizeFromOrigToEnc(32), 64);
expect(getSizeFromOrigToEnc(14787203)).equals(14787232); assert.equal(getSizeFromOrigToEnc(14787203), 14787232);
}); });
it("should get size from encrypted to origin correctly", () => { it("should get size from encrypted to origin correctly", () => {
expect(() => getSizeFromEncToOrig(-1)).to.throw(); assert.throws(() => getSizeFromEncToOrig(-1));
expect(() => getSizeFromEncToOrig(30)).to.throw(); assert.throws(() => getSizeFromEncToOrig(30));
expect(getSizeFromEncToOrig(32)).to.deep.equal({ assert.deepEqual(getSizeFromEncToOrig(32), {
minSize: 0, minSize: 0,
maxSize: 15, maxSize: 15,
}); });
expect(getSizeFromEncToOrig(48)).to.deep.equal({ assert.deepEqual(getSizeFromEncToOrig(48), {
minSize: 16, minSize: 16,
maxSize: 31, maxSize: 31,
}); });
expect(() => getSizeFromEncToOrig(14787231)).to.throw(); assert.throws(() => getSizeFromEncToOrig(14787231));
let { minSize, maxSize } = getSizeFromEncToOrig(14787232); let { minSize, maxSize } = getSizeFromEncToOrig(14787232);
expect(minSize <= 14787203 && 14787203 <= maxSize).to.be.true; assert.ok(minSize <= 14787203 && 14787203 <= maxSize);
}); });
}); });

View File

@ -1,14 +1,9 @@
import * as chai from "chai"; import { strict as assert } from "assert";
import chaiAsPromised from "chai-as-promised";
import { import {
isEqualMetadataOnRemote, isEqualMetadataOnRemote,
MetadataOnRemote, MetadataOnRemote,
} from "../src/metadataOnRemote"; } from "../src/metadataOnRemote";
chai.use(chaiAsPromised);
const expect = chai.expect;
describe("Metadata operations tests", () => { describe("Metadata operations tests", () => {
it("should compare objects deeply", async () => { it("should compare objects deeply", async () => {
const a: MetadataOnRemote = { const a: MetadataOnRemote = {
@ -24,7 +19,7 @@ describe("Metadata operations tests", () => {
], ],
}; };
expect(isEqualMetadataOnRemote(a, b)); assert.ok(isEqualMetadataOnRemote(a, b));
}); });
it("should find diff", async () => { it("should find diff", async () => {
@ -41,7 +36,7 @@ describe("Metadata operations tests", () => {
], ],
}; };
expect(!isEqualMetadataOnRemote(a, b)); assert.ok(!isEqualMetadataOnRemote(a, b));
}); });
it("should treat undefined correctly", async () => { it("should treat undefined correctly", async () => {
@ -53,22 +48,22 @@ describe("Metadata operations tests", () => {
], ],
}; };
expect(!isEqualMetadataOnRemote(a, b)); assert.ok(!isEqualMetadataOnRemote(a, b));
b = { deletions: [] }; b = { deletions: [] };
expect(isEqualMetadataOnRemote(a, b)); assert.ok(isEqualMetadataOnRemote(a, b));
b = { deletions: undefined }; b = { deletions: undefined };
expect(isEqualMetadataOnRemote(a, b)); assert.ok(isEqualMetadataOnRemote(a, b));
b = undefined; b = undefined;
expect(isEqualMetadataOnRemote(a, b)); assert.ok(isEqualMetadataOnRemote(a, b));
}); });
it("should ignore generated at fields", async () => { it("should ignore generated at fields", async () => {
const a: MetadataOnRemote = { const a: MetadataOnRemote = {
deletions: [ deletions: [
{ key: "xxxx", actionWhen: 1 }, { key: "xxx", actionWhen: 1 },
{ key: "yyy", actionWhen: 2 }, { key: "yyy", actionWhen: 2 },
], ],
generatedWhen: 1, generatedWhen: 1,
@ -81,6 +76,6 @@ describe("Metadata operations tests", () => {
generatedWhen: 2, generatedWhen: 2,
}; };
expect(isEqualMetadataOnRemote(a, b)); assert.ok(isEqualMetadataOnRemote(a, b));
}); });
}); });

View File

@ -1,139 +1,139 @@
import { expect } from "chai"; import { strict as assert } from "assert";
import { JSDOM } from "jsdom"; import { JSDOM } from "jsdom";
import * as misc from "../src/misc"; import * as misc from "../src/misc";
describe("Misc: hidden file", () => { describe("Misc: hidden file", () => {
it("should find hidden file correctly", () => { it("should find hidden file correctly", () => {
let item = ""; let item = "";
expect(misc.isHiddenPath(item)).to.be.false; assert.ok(!misc.isHiddenPath(item));
item = "."; item = ".";
expect(misc.isHiddenPath(item)).to.be.false; assert.ok(!misc.isHiddenPath(item));
item = ".."; item = "..";
expect(misc.isHiddenPath(item)).to.be.false; assert.ok(!misc.isHiddenPath(item));
item = "/x/y/z/../././../a/b/c"; item = "/x/y/z/../././../a/b/c";
expect(misc.isHiddenPath(item)).to.be.false; assert.ok(!misc.isHiddenPath(item));
item = ".hidden"; item = ".hidden";
expect(misc.isHiddenPath(item)).to.be.true; assert.ok(misc.isHiddenPath(item));
item = "_hidden_loose"; item = "_hidden_loose";
expect(misc.isHiddenPath(item)).to.be.true; assert.ok(misc.isHiddenPath(item));
expect(misc.isHiddenPath(item, true, false)).to.be.false; assert.ok(!misc.isHiddenPath(item, true, false));
item = "/sdd/_hidden_loose"; item = "/sdd/_hidden_loose";
expect(misc.isHiddenPath(item)).to.be.true; assert.ok(misc.isHiddenPath(item));
item = "what/../_hidden_loose/what/what/what"; item = "what/../_hidden_loose/what/what/what";
expect(misc.isHiddenPath(item)).to.be.true; assert.ok(misc.isHiddenPath(item));
item = "what/../_hidden_loose/what/what/what"; item = "what/../_hidden_loose/what/what/what";
expect(misc.isHiddenPath(item, true, false)).to.be.false; assert.ok(!misc.isHiddenPath(item, true, false));
item = "what/../_hidden_loose/../.hidden/what/what/what"; item = "what/../_hidden_loose/../.hidden/what/what/what";
expect(misc.isHiddenPath(item, true, false)).to.be.true; assert.ok(misc.isHiddenPath(item, true, false));
item = "what/../_hidden_loose/../.hidden/what/what/what"; item = "what/../_hidden_loose/../.hidden/what/what/what";
expect(misc.isHiddenPath(item, false, true)).to.be.false; assert.ok(!misc.isHiddenPath(item, false, true));
item = "what/_hidden_loose/what/what/what"; item = "what/_hidden_loose/what/what/what";
expect(misc.isHiddenPath(item, false, true)).to.be.true; assert.ok(misc.isHiddenPath(item, false, true));
expect(misc.isHiddenPath(item, true, false)).to.be.false; assert.ok(!misc.isHiddenPath(item, true, false));
item = "what/.hidden/what/what/what"; item = "what/.hidden/what/what/what";
expect(misc.isHiddenPath(item, false, true)).to.be.false; assert.ok(!misc.isHiddenPath(item, false, true));
expect(misc.isHiddenPath(item, true, false)).to.be.true; assert.ok(misc.isHiddenPath(item, true, false));
}); });
}); });
describe("Misc: get folder levels", () => { describe("Misc: get folder levels", () => {
it("should ignore empty path", () => { it("should ignore empty path", () => {
const item = ""; const item = "";
expect(misc.getFolderLevels(item)).to.be.empty; assert.equal(misc.getFolderLevels(item).length, 0);
}); });
it("should ignore single file", () => { it("should ignore single file", () => {
const item = "xxx"; const item = "xxx";
expect(misc.getFolderLevels(item)).to.be.empty; assert.equal(misc.getFolderLevels(item).length, 0);
}); });
it("should detect path ending with /", () => { it("should detect path ending with /", () => {
const item = "xxx/"; const item = "xxx/";
const res = ["xxx"]; const res = ["xxx"];
expect(misc.getFolderLevels(item)).to.deep.equal(res); assert.deepEqual(misc.getFolderLevels(item), res);
}); });
it("should correctly split folders and files", () => { it("should correctly split folders and files", () => {
const item = "xxx/yyy/zzz.md"; const item = "xxx/yyy/zzz.md";
const res = ["xxx", "xxx/yyy"]; const res = ["xxx", "xxx/yyy"];
expect(misc.getFolderLevels(item)).to.deep.equal(res); assert.deepEqual(misc.getFolderLevels(item), res);
const item2 = "xxx/yyy/zzz"; const item2 = "xxx/yyy/zzz";
const res2 = ["xxx", "xxx/yyy"]; const res2 = ["xxx", "xxx/yyy"];
expect(misc.getFolderLevels(item2)).to.deep.equal(res2); assert.deepEqual(misc.getFolderLevels(item2), res2);
const item3 = "xxx/yyy/zzz/"; const item3 = "xxx/yyy/zzz/";
const res3 = ["xxx", "xxx/yyy", "xxx/yyy/zzz"]; const res3 = ["xxx", "xxx/yyy", "xxx/yyy/zzz"];
expect(misc.getFolderLevels(item3)).to.deep.equal(res3); assert.deepEqual(misc.getFolderLevels(item3), res3);
}); });
it("should correctly add ending slash if required", () => { it("should correctly add ending slash if required", () => {
const item = "xxx/yyy/zzz.md"; const item = "xxx/yyy/zzz.md";
const res = ["xxx/", "xxx/yyy/"]; const res = ["xxx/", "xxx/yyy/"];
expect(misc.getFolderLevels(item, true)).to.deep.equal(res); assert.deepEqual(misc.getFolderLevels(item, true), res);
const item2 = "xxx/yyy/zzz"; const item2 = "xxx/yyy/zzz";
const res2 = ["xxx/", "xxx/yyy/"]; const res2 = ["xxx/", "xxx/yyy/"];
expect(misc.getFolderLevels(item2, true)).to.deep.equal(res2); assert.deepEqual(misc.getFolderLevels(item2, true), res2);
const item3 = "xxx/yyy/zzz/"; const item3 = "xxx/yyy/zzz/";
const res3 = ["xxx/", "xxx/yyy/", "xxx/yyy/zzz/"]; const res3 = ["xxx/", "xxx/yyy/", "xxx/yyy/zzz/"];
expect(misc.getFolderLevels(item3, true)).to.deep.equal(res3); assert.deepEqual(misc.getFolderLevels(item3, true), res3);
}); });
it("should treat path starting with / correctly", () => { it("should treat path starting with / correctly", () => {
const item = "/xxx/yyy/zzz.md"; const item = "/xxx/yyy/zzz.md";
const res = ["/xxx", "/xxx/yyy"]; const res = ["/xxx", "/xxx/yyy"];
expect(misc.getFolderLevels(item)).to.deep.equal(res); assert.deepEqual(misc.getFolderLevels(item), res);
const item2 = "/xxx/yyy/zzz"; const item2 = "/xxx/yyy/zzz";
const res2 = ["/xxx", "/xxx/yyy"]; const res2 = ["/xxx", "/xxx/yyy"];
expect(misc.getFolderLevels(item2)).to.deep.equal(res2); assert.deepEqual(misc.getFolderLevels(item2), res2);
const item3 = "/xxx/yyy/zzz/"; const item3 = "/xxx/yyy/zzz/";
const res3 = ["/xxx", "/xxx/yyy", "/xxx/yyy/zzz"]; const res3 = ["/xxx", "/xxx/yyy", "/xxx/yyy/zzz"];
expect(misc.getFolderLevels(item3)).to.deep.equal(res3); assert.deepEqual(misc.getFolderLevels(item3), res3);
const item4 = "/xxx"; const item4 = "/xxx";
const res4 = [] as string[]; const res4 = [] as string[];
expect(misc.getFolderLevels(item4)).to.deep.equal(res4); assert.deepEqual(misc.getFolderLevels(item4), res4);
const item5 = "/"; const item5 = "/";
const res5 = [] as string[]; const res5 = [] as string[];
expect(misc.getFolderLevels(item5)).to.deep.equal(res5); assert.deepEqual(misc.getFolderLevels(item5), res5);
}); });
}); });
describe("Misc: get parent folder", () => { describe("Misc: get parent folder", () => {
it("should treat empty path correctly", () => { it("should treat empty path correctly", () => {
const item = ""; const item = "";
expect(misc.getParentFolder(item)).equals("/"); assert.equal(misc.getParentFolder(item), "/");
}); });
it("should treat one level path correctly", () => { it("should treat one level path correctly", () => {
let item = "abc/"; let item = "abc/";
expect(misc.getParentFolder(item)).equals("/"); assert.equal(misc.getParentFolder(item), "/");
item = "/efg/"; item = "/efg/";
expect(misc.getParentFolder(item)).equals("/"); assert.equal(misc.getParentFolder(item), "/");
}); });
it("should treat more levels path correctly", () => { it("should treat more levels path correctly", () => {
let item = "abc/efg"; let item = "abc/efg";
expect(misc.getParentFolder(item)).equals("abc/"); assert.equal(misc.getParentFolder(item), "abc/");
item = "/hij/klm/"; item = "/hij/klm/";
expect(misc.getParentFolder(item)).equals("/hij/"); assert.equal(misc.getParentFolder(item), "/hij/");
}); });
}); });
@ -141,18 +141,18 @@ describe("Misc: vaild file name tests", () => {
it("should treat no ascii correctly", async () => { it("should treat no ascii correctly", async () => {
const x = misc.isVaildText("😄🍎 apple 苹果"); const x = misc.isVaildText("😄🍎 apple 苹果");
// console.log(x) // console.log(x)
expect(x).to.be.true; assert.ok(x);
}); });
it("should find not-printable chars correctly", async () => { it("should find not-printable chars correctly", async () => {
const x = misc.isVaildText("😄🍎 apple 苹果\u0000"); const x = misc.isVaildText("😄🍎 apple 苹果\u0000");
// console.log(x) // console.log(x)
expect(x).to.be.false; assert.ok(!x);
}); });
it("should allow spaces/slashes/...", async () => { it("should allow spaces/slashes/...", async () => {
const x = misc.isVaildText("😄🍎 apple 苹果/-_=/\\*%^&@#$`"); const x = misc.isVaildText("😄🍎 apple 苹果/-_=/\\*%^&@#$`");
expect(x).to.be.true; assert.ok(x);
}); });
}); });
@ -160,21 +160,21 @@ describe("Misc: get dirname", () => {
it("should return itself for folder", async () => { it("should return itself for folder", async () => {
const x = misc.getPathFolder("ssss/"); const x = misc.getPathFolder("ssss/");
// console.log(x) // console.log(x)
expect(x).to.equal("ssss/"); assert.equal(x, "ssss/");
}); });
it("should return folder for file", async () => { it("should return folder for file", async () => {
const x = misc.getPathFolder("sss/yyy"); const x = misc.getPathFolder("sss/yyy");
// console.log(x) // console.log(x)
expect(x).to.equal("sss/"); assert.equal(x, "sss/");
}); });
it("should treat / specially", async () => { it("should treat / specially", async () => {
const x = misc.getPathFolder("/"); const x = misc.getPathFolder("/");
expect(x).to.equal("/"); assert.equal(x, "/");
const y = misc.getPathFolder("/abc"); const y = misc.getPathFolder("/abc");
expect(y).to.equal("/"); assert.equal(y, "/");
}); });
}); });
@ -188,7 +188,7 @@ describe("Misc: extract svg", () => {
const x = "<svg><rect/><g/></svg>"; const x = "<svg><rect/><g/></svg>";
const y = misc.extractSvgSub(x); const y = misc.extractSvgSub(x);
// console.log(x) // console.log(x)
expect(y).to.equal("<rect/><g/>"); assert.equal(y, "<rect/><g/>");
}); });
}); });
@ -202,7 +202,7 @@ describe("Misc: get split ranges", () => {
end: 10, end: 10,
}, },
]; ];
expect(k).to.deep.equal(k2); assert.deepEqual(k, k2);
}); });
it("should deal with 0 remainder", () => { it("should deal with 0 remainder", () => {
@ -219,7 +219,7 @@ describe("Misc: get split ranges", () => {
end: 20, end: 20,
}, },
]; ];
expect(k).to.deep.equal(k2); assert.deepEqual(k, k2);
}); });
it("should deal with not-0 remainder", () => { it("should deal with not-0 remainder", () => {
@ -241,55 +241,55 @@ describe("Misc: get split ranges", () => {
end: 25, end: 25,
}, },
]; ];
expect(k).to.deep.equal(k2); assert.deepEqual(k, k2);
}); });
}); });
describe("Misc: at which level", () => { describe("Misc: at which level", () => {
it("should throw error on some parameters", () => { it("should throw error on some parameters", () => {
expect(() => misc.atWhichLevel(undefined)).to.throw(); assert.throws(() => misc.atWhichLevel(undefined));
expect(() => misc.atWhichLevel("")).to.throw(); assert.throws(() => misc.atWhichLevel(""));
expect(() => misc.atWhichLevel("..")).to.throw(); assert.throws(() => misc.atWhichLevel(".."));
expect(() => misc.atWhichLevel(".")).to.throw(); assert.throws(() => misc.atWhichLevel("."));
expect(() => misc.atWhichLevel("/")).to.throw(); assert.throws(() => misc.atWhichLevel("/"));
expect(() => misc.atWhichLevel("/xxyy")).to.throw(); assert.throws(() => misc.atWhichLevel("/xxyy"));
}); });
it("should treat folders correctly", () => { it("should treat folders correctly", () => {
expect(misc.atWhichLevel("x/")).to.be.equal(1); assert.equal(misc.atWhichLevel("x/"), 1);
expect(misc.atWhichLevel("x/y/")).to.be.equal(2); assert.equal(misc.atWhichLevel("x/y/"), 2);
}); });
it("should treat files correctly", () => { it("should treat files correctly", () => {
expect(misc.atWhichLevel("x.md")).to.be.equal(1); assert.equal(misc.atWhichLevel("x.md"), 1);
expect(misc.atWhichLevel("x/y.md")).to.be.equal(2); assert.equal(misc.atWhichLevel("x/y.md"), 2);
expect(misc.atWhichLevel("x/y/z.md")).to.be.equal(3); assert.equal(misc.atWhichLevel("x/y/z.md"), 3);
}); });
}); });
describe("Misc: special char for dir", () => { describe("Misc: special char for dir", () => {
it("should return false for normal string", () => { it("should return false for normal string", () => {
expect(misc.checkHasSpecialCharForDir("")).to.be.false; assert.ok(!misc.checkHasSpecialCharForDir(""));
expect(misc.checkHasSpecialCharForDir("xxx")).to.be.false; assert.ok(!misc.checkHasSpecialCharForDir("xxx"));
expect(misc.checkHasSpecialCharForDir("yyy_xxx")).to.be.false; assert.ok(!misc.checkHasSpecialCharForDir("yyy_xxx"));
expect(misc.checkHasSpecialCharForDir("yyy.xxx")).to.be.false; assert.ok(!misc.checkHasSpecialCharForDir("yyy.xxx"));
expect(misc.checkHasSpecialCharForDir("yyyxxx")).to.be.false; assert.ok(!misc.checkHasSpecialCharForDir("yyyxxx"));
}); });
it("should return true for special cases", () => { it("should return true for special cases", () => {
expect(misc.checkHasSpecialCharForDir("?")).to.be.true; assert.ok(misc.checkHasSpecialCharForDir("?"));
expect(misc.checkHasSpecialCharForDir("/")).to.be.true; assert.ok(misc.checkHasSpecialCharForDir("/"));
expect(misc.checkHasSpecialCharForDir("\\")).to.be.true; assert.ok(misc.checkHasSpecialCharForDir("\\"));
expect(misc.checkHasSpecialCharForDir("xxx/yyy")).to.be.true; assert.ok(misc.checkHasSpecialCharForDir("xxx/yyy"));
expect(misc.checkHasSpecialCharForDir("xxx\\yyy")).to.be.true; assert.ok(misc.checkHasSpecialCharForDir("xxx\\yyy"));
expect(misc.checkHasSpecialCharForDir("xxx?yyy")).to.be.true; assert.ok(misc.checkHasSpecialCharForDir("xxx?yyy"));
}); });
}); });
describe("Misc: Dropbox: should fix the folder name cases", () => { describe("Misc: Dropbox: should fix the folder name cases", () => {
it("should do nothing on empty folders", () => { it("should do nothing on empty folders", () => {
const input: any[] = []; const input: any[] = [];
expect(misc.fixEntityListCasesInplace(input)).to.be.empty; assert.equal(misc.fixEntityListCasesInplace(input).length, 0);
}); });
it("should sort folders by length by side effect", () => { it("should sort folders by length by side effect", () => {
@ -306,7 +306,7 @@ describe("Misc: Dropbox: should fix the folder name cases", () => {
{ keyRaw: "bbb/" }, { keyRaw: "bbb/" },
{ keyRaw: "aaaa/" }, { keyRaw: "aaaa/" },
]; ];
expect(misc.fixEntityListCasesInplace(input)).to.deep.equal(output); assert.deepEqual(misc.fixEntityListCasesInplace(input), output);
}); });
it("should fix folder names", () => { it("should fix folder names", () => {
@ -335,6 +335,6 @@ describe("Misc: Dropbox: should fix the folder name cases", () => {
{ keyRaw: "ddd/eee/fff.md" }, { keyRaw: "ddd/eee/fff.md" },
{ keyRaw: "Ggg/Hhh你好/Fff世界.md" }, { keyRaw: "Ggg/Hhh你好/Fff世界.md" },
]; ];
expect(misc.fixEntityListCasesInplace(input)).to.deep.equal(output); assert.deepEqual(misc.fixEntityListCasesInplace(input), output);
}); });
}); });