switch to mocha for test latency improvements

Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
Arthur Lu 2022-11-08 00:00:15 +00:00
parent c7c395c832
commit 0f622d16de
2 changed files with 47 additions and 33 deletions

View File

@ -2,9 +2,9 @@
"name": "food-journal", "name": "food-journal",
"version": "1.0.0", "version": "1.0.0",
"scripts": { "scripts": {
"test": "jest" "test": "mocha --recursive **/*.test.js"
}, },
"dependencies": { "dependencies": {
"jest": "24" "mocha": "10"
} }
} }

View File

@ -1,4 +1,6 @@
const {environment} = require("./testenv.js"); const {environment} = require("./testenv.js");
var assert = require('assert');
var window;
function saveToLocal (k, v) { function saveToLocal (k, v) {
window.localStorage.setItem(k, v); window.localStorage.setItem(k, v);
@ -17,24 +19,35 @@ function clearLocal () {
} }
describe("test localStorage mock", () => { describe("test localStorage mock", () => {
test("test save and fetch", () => { it("test save and fetch", () => {
let window = environment(); window = environment();
saveToLocal("testkey1", "testvalue1"); saveToLocal("testkey1", "testvalue1");
saveToLocal("testkey2", "testvalue2"); saveToLocal("testkey2", "testvalue2");
saveToLocal("testkey3", "testvalue3"); saveToLocal("testkey3", "testvalue3");
saveToLocal("testkey4", "testvalue4"); saveToLocal("testkey4", "testvalue4");
expect(getFromLocal("testkey1")).toStrictEqual("testvalue1"); assert.equal(getFromLocal("testkey1"), "testvalue1");
expect(getFromLocal("testkey2")).toStrictEqual("testvalue2"); assert.equal(getFromLocal("testkey2"), "testvalue2");
expect(getFromLocal("testkey3")).toStrictEqual("testvalue3"); assert.equal(getFromLocal("testkey3"), "testvalue3");
expect(getFromLocal("testkey4")).toStrictEqual("testvalue4"); assert.equal(getFromLocal("testkey4"), "testvalue4");
saveToLocal("testkey6", "testvalue5"); saveToLocal("testkey6", "testvalue5");
expect(getFromLocal("testkey6")).toStrictEqual("testvalue5"); assert.equal(getFromLocal("testkey6"), "testvalue5");
}); });
test("test delete and fetch", () => { it("test window locality", () => {
let window = environment(); window = environment();
assert.equal(getFromLocal("testkey1"), null);
assert.equal(getFromLocal("testkey2"), null);
assert.equal(getFromLocal("testkey3"), null);
assert.equal(getFromLocal("testkey4"), null);
});
it("test delete and fetch", () => {
window = environment();
saveToLocal("testkey1", "testvalue1"); saveToLocal("testkey1", "testvalue1");
saveToLocal("testkey2", "testvalue2"); saveToLocal("testkey2", "testvalue2");
saveToLocal("testkey3", "testvalue3"); saveToLocal("testkey3", "testvalue3");
@ -42,35 +55,36 @@ describe("test localStorage mock", () => {
removeFromLocal("testkey3"); removeFromLocal("testkey3");
expect(getFromLocal("testkey1")).toStrictEqual("testvalue1"); assert.equal(getFromLocal("testkey1"), "testvalue1");
expect(getFromLocal("testkey2")).toStrictEqual("testvalue2"); assert.equal(getFromLocal("testkey2"), "testvalue2");
expect(getFromLocal("testkey3")).toStrictEqual(null); assert.equal(getFromLocal("testkey3"), null);
expect(getFromLocal("testkey4")).toStrictEqual("testvalue4"); assert.equal(getFromLocal("testkey4"), "testvalue4");
removeFromLocal("testkey1"); removeFromLocal("testkey1");
expect(getFromLocal("testkey1")).toStrictEqual(null); assert.equal(getFromLocal("testkey1"), null);
expect(getFromLocal("testkey2")).toStrictEqual("testvalue2"); assert.equal(getFromLocal("testkey2"), "testvalue2");
expect(getFromLocal("testkey3")).toStrictEqual(null); assert.equal(getFromLocal("testkey3"), null);
expect(getFromLocal("testkey4")).toStrictEqual("testvalue4"); assert.equal(getFromLocal("testkey4"), "testvalue4");
removeFromLocal("testkey4"); removeFromLocal("testkey4");
expect(getFromLocal("testkey1")).toStrictEqual(null); assert.equal(getFromLocal("testkey1"), null);
expect(getFromLocal("testkey2")).toStrictEqual("testvalue2"); assert.equal(getFromLocal("testkey2"), "testvalue2");
expect(getFromLocal("testkey3")).toStrictEqual(null); assert.equal(getFromLocal("testkey3"), null);
expect(getFromLocal("testkey4")).toStrictEqual(null); assert.equal(getFromLocal("testkey4"), null);
removeFromLocal("testkey2"); removeFromLocal("testkey2");
expect(getFromLocal("testkey1")).toStrictEqual(null); assert.equal(getFromLocal("testkey1"), null);
expect(getFromLocal("testkey2")).toStrictEqual(null); assert.equal(getFromLocal("testkey2"), null);
expect(getFromLocal("testkey3")).toStrictEqual(null); assert.equal(getFromLocal("testkey3"), null);
expect(getFromLocal("testkey4")).toStrictEqual(null); assert.equal(getFromLocal("testkey4"), null);
}); });
test("test clear and fetch", () => { it("test clear and fetch", () => {
let window = environment(); window = environment();
saveToLocal("testkey1", "testvalue1"); saveToLocal("testkey1", "testvalue1");
saveToLocal("testkey2", "testvalue2"); saveToLocal("testkey2", "testvalue2");
saveToLocal("testkey3", "testvalue3"); saveToLocal("testkey3", "testvalue3");
@ -78,9 +92,9 @@ describe("test localStorage mock", () => {
clearLocal(); clearLocal();
expect(getFromLocal("testkey1")).toStrictEqual(null); assert.equal(getFromLocal("testkey1"), null);
expect(getFromLocal("testkey2")).toStrictEqual(null); assert.equal(getFromLocal("testkey2"), null);
expect(getFromLocal("testkey3")).toStrictEqual(null); assert.equal(getFromLocal("testkey3"), null);
expect(getFromLocal("testkey4")).toStrictEqual(null); assert.equal(getFromLocal("testkey4"), null);
}); });
}); });