Skip to content

Commit

Permalink
batching fix final, update to mocha hooks, fix tests, update tests to…
Browse files Browse the repository at this point in the history
… shared context
  • Loading branch information
patrick-rodgers committed Feb 1, 2022
1 parent 682d802 commit 29bebab
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .mocharc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function getAllPackageFolderNames() {
}

const basePath = "./build/testing/test/";
let paths = [`${basePath}main.js`];
let paths = [];

// handle package specific config
if (yargs.packages || yargs.p) {
Expand Down
2 changes: 1 addition & 1 deletion test/graph/calendars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ describe("Calendar", function () {
});

// Remove the test data we created
this.afterAll(async function () {
after(async function () {

if (!stringIsNullOrEmpty(testUserName) && !stringIsNullOrEmpty(testEventID)) {
await this.pnp.graph.users.getById(testUserName).calendar.events.getById(testEventID).delete();
Expand Down
4 changes: 2 additions & 2 deletions test/graph/outlook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe("Outlook", function () {
const testCategoryList: string[] = [];

// Ensure we have the data to test against
this.beforeAll(async function () {
before(async function () {

if (!this.pnp.settings.enableWebTests || stringIsNullOrEmpty(this.pnp.settings.testUser)) {
this.skip();
Expand All @@ -22,7 +22,7 @@ describe("Outlook", function () {
});

// Clean up testing categories
this.afterAll(async function () {
after(async function () {
if (!stringIsNullOrEmpty(testUserName) && testCategoryList.length > 0) {
for (let i = 0; i < testCategoryList.length; i++) {
await this.pnp.graph.users.getById(testUserName).outlook.masterCategories.getById(testCategoryList[i]).delete();
Expand Down
15 changes: 10 additions & 5 deletions test/mocha-root-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import { getSettings, ISettings } from "./load-settings.js";
import { Context } from "mocha";
import { extractWebUrl, SPFI, spfi } from "@pnp/sp";
import { graphfi, GraphFI } from "@pnp/graph";
import { GraphDefault, SPDefault } from "@pnp/nodejs";
import { GraphDefault, SPDefault, NodeFetch } from "@pnp/nodejs";
import { getGUID, delay } from "@pnp/core";
import { cleanUpAllSubsites } from "./clean-subsite.js";
import * as chai from "chai";
import chaiAsPromised from "chai-as-promised";
import "mocha";

declare module "mocha" {
interface Context {
Expand Down Expand Up @@ -33,6 +36,8 @@ export const mochaHooks = {
beforeAll: [
async function setup(this: Context) {

chai.use(chaiAsPromised);

// start a timer
testStart = Date.now();

Expand Down Expand Up @@ -66,7 +71,7 @@ export const mochaHooks = {
config: this.pnp.settings.sp.msal.init,
scopes: this.pnp.settings.sp.msal.scopes,
},
}));
}), NodeFetch({ replace: true }));

if (siteUsed) {
// we were given a site, so we don't need to create one
Expand All @@ -88,7 +93,7 @@ export const mochaHooks = {
config: this.pnp.settings.sp.msal.init,
scopes: this.pnp.settings.sp.msal.scopes,
},
}));
}), NodeFetch({ replace: true }));
} finally {
const setupEnd = Date.now();
console.log(`SP Setup completed in ${((setupEnd - setupStart) / 1000).toFixed(4)} seconds.`);
Expand All @@ -108,7 +113,7 @@ export const mochaHooks = {
config: this.pnp.settings.graph.msal.init,
scopes: this.pnp.settings.graph.msal.scopes,
},
}));
}), NodeFetch({ replace: true }));

} finally {
const setupEnd = Date.now();
Expand Down Expand Up @@ -160,7 +165,7 @@ export const mochaHooks = {
console.log(`SP Teardown completed in ${((teardownEnd - teardownStart) / 1000).toFixed(4)} seconds.`);
}

return null;
return Promise.resolve();
},
function graphTeardown(this: Context) {
const teardownStart = Date.now();
Expand Down

0 comments on commit 29bebab

Please sign in to comment.