Skip to content

Commit

Permalink
Fix chai usage for chai5/chaihttp5
Browse files Browse the repository at this point in the history
As chai only supports esm, not commjs since v5,
adjust the setup code to use dynamic imports.

See chaijs/chai#1578 for more.

Change-Id: I3c34043504bdf0c881eed4dabbe9e4fc8bb0b362
  • Loading branch information
bpedersen2 committed Nov 14, 2024
1 parent cc3afdb commit 9919544
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions test/config/pretest.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
/* eslint-disable @typescript-eslint/no-var-requires */
//NOTE: Here we load and initialize some global variables that are used throughout the tests
require("dotenv").config();
var chaiHttp = require("chai-http");
var chaiHttp;
var chai;

const { MongoClient } = require("mongodb");

const client = new MongoClient(process.env.MONGODB_URI);

async function loadChai() {
const { chai } = import("chai");
chai.use(chaiHttp);
chaiHttp = await import("chai-http");
await import("chai").then((result) => {
chai = result.use(chaiHttp);
});
await client.connect();
}

Expand Down

0 comments on commit 9919544

Please sign in to comment.