Skip to content

Commit

Permalink
adding pnpTest WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-rodgers committed Jul 26, 2023
1 parent 50fe177 commit f33d47c
Show file tree
Hide file tree
Showing 14 changed files with 447 additions and 283 deletions.
9 changes: 5 additions & 4 deletions test/core/assumptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
// our assumptions remain correct

import { expect } from "chai";
import { pnpTest } from "../pnp-test.js";

describe("Assumptions", function () {

it("JS should merge objects how we expect", function () {
it("JS should merge objects how we expect", pnpTest("3576d9bf-aa31-4b3f-8400-104513956328", function () {

const o = {};

Expand Down Expand Up @@ -58,9 +59,9 @@ describe("Assumptions", function () {

expect(test5, "test 5").to.eql({});

});
}));

it("should destructure how we assume", function () {
it("should destructure how we assume", pnpTest("67a889c9-a45a-4978-a181-91d5d096edeb", function () {

const props = {
yes: false,
Expand Down Expand Up @@ -95,5 +96,5 @@ describe("Assumptions", function () {
expect(title).to.eq("hello");

expect(another).to.eq("something");
});
}));
});
29 changes: 15 additions & 14 deletions test/core/storage.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,61 @@
import { expect } from "chai";
import { PnPClientStorage } from "@pnp/core";
import { pnpTest } from "../pnp-test.js";

describe("Storage", function () {

describe("PnPClientStorageWrapper", function () {

let storage: PnPClientStorage;

beforeEach(function () {
beforeEach(pnpTest("71bacb4d-2a28-4da3-a09b-7b8625345586", function () {
storage = new PnPClientStorage();
});
}));

it("Add and Get a value (local)", function () {
it("Add and Get a value (local)", pnpTest("4986f3f6-3b31-4ac5-9746-62384a108ae1", function () {
storage.local.put("test", "value");
const ret = storage.local.get("test");
expect(ret).to.eq("value");
});
}));

it("Add two values, remove one and still return the other (local)", function () {
it("Add two values, remove one and still return the other (local)", pnpTest("b370742a-0eb9-40f5-bb75-43b667f51181", function () {
storage.local.put("test1", "value1");
storage.local.put("test2", "value2");
storage.local.delete("test1");
const ret = storage.local.get("test2");
expect(ret).to.eq("value2");
});
}));

it("Use getOrPut to add a value using a getter function and return it (local)", function () {
it("Use getOrPut to add a value using a getter function and return it (local)", pnpTest("6f8a3a57-6e1e-4e26-9c86-2bfb05085c5e", function () {
storage.local.getOrPut("test", function () {
return new Promise(() => "value");
}).then(function () {
const ret = storage.local.get("test");
expect(ret).to.eq("value");
});
});
}));

it("Add and Get a value (session)", function () {
it("Add and Get a value (session)", pnpTest("71cc7886-18d7-4362-b232-07afd7d6b750", function () {
storage.session.put("test", "value");
const ret = storage.session.get("test");
expect(ret).to.eq("value");
});
}));

it("Add two values, remove one and still return the other (session)", function () {
it("Add two values, remove one and still return the other (session)", pnpTest("8c570f93-d6aa-49f3-a740-d884f1832b59", function () {
storage.session.put("test1", "value1");
storage.session.put("test2", "value2");
storage.session.delete("test1");
const ret = storage.session.get("test2");
expect(ret).to.eq("value2");
});
}));

it("Use getOrPut to add a value using a getter function and return it (session)", function () {
it("Use getOrPut to add a value using a getter function and return it (session)", pnpTest("0c25edf5-120e-48d3-b6cd-e2da49391d21", function () {
storage.session.getOrPut("test", function () {
return new Promise(() => "value");
}).then(function () {
const ret = storage.session.get("test");
expect(ret).to.eq("value");
});
});
}));
});
});
25 changes: 13 additions & 12 deletions test/core/timeline.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Timeline, asyncReduce } from "@pnp/core";
import { expect } from "chai";
import { pnpTest } from "../pnp-test.js";

const TestingMoments = {
first: asyncReduce<(a: number) => Promise<[number]>>(),
Expand Down Expand Up @@ -62,7 +63,7 @@ describe("Timeline", function () {
return expect(h).to.eq(2);
});

it("Should process moments 2", async function () {
it("Should process moments 2", pnpTest("8267d3af-554d-44d8-8b00-e33ce7d93f1d", async function () {

const tl = new TestTimeline();

Expand All @@ -78,9 +79,9 @@ describe("Timeline", function () {
const h = await tl.go(0);

return expect(h).to.eq(7);
});
}));

it("Prepend works as expected", function () {
it("Prepend works as expected", pnpTest("890664f0-0e7f-4aa5-bc73-55fa4b05b27b", function () {

const tl = new TestTimeline();

Expand All @@ -97,9 +98,9 @@ describe("Timeline", function () {
expect(observers[0]).to.eq(f3);
expect(observers[1]).to.eq(f1);
expect(observers[2]).to.eq(f2);
});
}));

it("Clear works as expected", function () {
it("Clear works as expected", pnpTest("66b43d34-7e34-4506-abc9-4d12b8286937", function () {

const tl = new TestTimeline();

Expand All @@ -120,9 +121,9 @@ describe("Timeline", function () {
const observers2 = tl.on.first.toArray();

expect(observers2).length(0);
});
}));

it("Replace works as expected", function () {
it("Replace works as expected", pnpTest("b162d48e-2ddd-4b36-8fee-fc3c9ef18838", function () {

const tl = new TestTimeline();

Expand All @@ -144,9 +145,9 @@ describe("Timeline", function () {

expect(observers2).length(1);
expect(observers2[0]).to.eq(f1);
});
}));

it("Logging works as expected", function () {
it("Logging works as expected", pnpTest("0506ad5a-7d00-4f0e-b436-46c90faadd9d", function () {

const tl = new TestTimeline();

Expand All @@ -161,9 +162,9 @@ describe("Timeline", function () {
tl.log("Test 2", 0);

expect(messages.length).to.eq(2);
});
}));

it("Lifecycle works as expected", async function () {
it("Lifecycle works as expected", pnpTest("a7dda9ad-cb00-4ad8-b717-4de294e02ad2", async function () {

const tl = new TestTimeline();

Expand Down Expand Up @@ -201,5 +202,5 @@ describe("Timeline", function () {
expect(tracker[1]).to.eq(2);
expect(tracker[2]).to.eq(3);
expect(tracker[3]).to.eq(4);
});
}));
});
Loading

0 comments on commit f33d47c

Please sign in to comment.