Update
This commit is contained in:
@ -1,5 +1,8 @@
|
||||
import chai from "chai";
|
||||
import chaiAsPromised from "chai-as-promised";
|
||||
import sinonChai from "sinon-chai";
|
||||
|
||||
process.env.LOCALE = "en";
|
||||
|
||||
chai.use(chaiAsPromised);
|
||||
chai.use(sinonChai);
|
||||
|
@ -5,6 +5,7 @@ import { expect } from "chai";
|
||||
|
||||
import type { Vault } from "../src/index";
|
||||
import { OnePassword } from "../src/index";
|
||||
// import adapter from "../src/adapters/node";
|
||||
|
||||
describe("OnePassword", () => {
|
||||
const freddy = resolve(__dirname, "../freddy-2013-12-04.opvault");
|
||||
|
43
test/weakMap.test.ts
Normal file
43
test/weakMap.test.ts
Normal file
@ -0,0 +1,43 @@
|
||||
import { describe, it } from "mocha";
|
||||
import { expect } from "chai";
|
||||
|
||||
import { WeakValueMap } from "../src/weakMap";
|
||||
|
||||
declare const gc: () => void;
|
||||
|
||||
describe("WeakValueMap", () => {
|
||||
interface Value {
|
||||
value: number;
|
||||
}
|
||||
|
||||
it("covers base use cases", () => {
|
||||
const map = new WeakValueMap<string, Value>();
|
||||
const object = { value: 1 };
|
||||
map.set("key", object);
|
||||
expect(map.get("key")!.value).to.equal(1);
|
||||
expect(map.delete("key")).to.be.true;
|
||||
expect(!map.delete("key")).to.be.true;
|
||||
});
|
||||
|
||||
it("overrides previous value", () => {
|
||||
const map = new WeakValueMap<string, Value>();
|
||||
map.set("key", { value: 2 });
|
||||
map.set("key", { value: 3 });
|
||||
expect(map.get("key")!.value).to.equal(3);
|
||||
});
|
||||
|
||||
it("deletes garbage collected values", (done) => {
|
||||
const map = new WeakValueMap<string, Value>();
|
||||
map.set("key", { value: 1 });
|
||||
setTimeout(() => {
|
||||
gc();
|
||||
expect(map.has("key")).to.be.false;
|
||||
map.set("key", { value: 2 });
|
||||
|
||||
setTimeout(() => {
|
||||
gc();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user