Skip to content

Commit 2e4df7e

Browse files
fix: bypass gulp for test scripts to fix Node 22 ESM compatibility
gulp-cli uses require() to load gulpfile.js which has an ESM top-level await (config/index.js), causing ERR_REQUIRE_ASYNC_MODULE on Node 22+. - Replace gulp test/testWatch/testCoverage with direct jest calls - Add scripts/jest.globalSetup.js to drop test DB before suite runs (replaces the gulp dropDB task) - Enable globalSetup in jest.config.js
1 parent ffa8319 commit 2e4df7e

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default {
5252
// forceCoverageMatch: [],
5353

5454
// A path to a module which exports an async function that is triggered once before all test suites
55-
// globalSetup: null,
55+
globalSetup: './scripts/jest.globalSetup.js',
5656

5757
// A path to a module which exports an async function that is triggered once after all test suites
5858
// globalTeardown: null,

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
"start": "node server.js",
2727
"debug": "nodemon --inspect server.js",
2828
"prod": "cross-env NODE_ENV=production node start server.js --name=node",
29-
"test": "cross-env NODE_ENV=test NODE_OPTIONS=--experimental-vm-modules gulp test",
30-
"test:watch": "cross-env NODE_ENV=test NODE_OPTIONS=--experimental-vm-modules gulp testWatch",
31-
"test:coverage": "cross-env NODE_ENV=test NODE_OPTIONS=--experimental-vm-modules gulp testCoverage",
32-
"test:coveralls": "cross-env NODE_ENV=test NODE_OPTIONS=--experimental-vm-modules gulp testCoverage && cat ./coverage/lcov.info | coveralls",
29+
"test": "cross-env NODE_ENV=test NODE_OPTIONS=--experimental-vm-modules jest",
30+
"test:watch": "cross-env NODE_ENV=test NODE_OPTIONS=--experimental-vm-modules jest --watch",
31+
"test:coverage": "cross-env NODE_ENV=test NODE_OPTIONS=--experimental-vm-modules jest --coverage",
32+
"test:coveralls": "cross-env NODE_ENV=test NODE_OPTIONS=--experimental-vm-modules jest --coverage && cat ./coverage/lcov.info | coveralls",
3333
"lint": "./node_modules/.bin/eslint ./modules ./lib ./config ./scripts",
3434
"seed:dev": "cross-env NODE_ENV=development gulp seed",
3535
"seed:prod": "cross-env NODE_ENV=production gulp seed",

scripts/jest.globalSetup.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Jest global setup - drops the test database before the test suite runs.
3+
* Replaces the gulp dropDB task that previously ran before jest.
4+
*/
5+
import mongoose from 'mongoose';
6+
7+
export default async () => {
8+
const config = (await import('../config/index.js')).default;
9+
await mongoose.connect(config.db.uri, config.db.options);
10+
await mongoose.connection.dropDatabase();
11+
await mongoose.disconnect();
12+
};

0 commit comments

Comments
 (0)