From 500e304fea83af1d5468583d40692df1a039a174 Mon Sep 17 00:00:00 2001 From: Friedemann Sommer Date: Fri, 19 Apr 2024 23:55:49 +0200 Subject: [PATCH] updated mocha config to check whether to use `--import` or `--loader` --- .mocharc.cjs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.mocharc.cjs b/.mocharc.cjs index e8054c11..2adda7b4 100644 --- a/.mocharc.cjs +++ b/.mocharc.cjs @@ -1,5 +1,9 @@ +const nodeVersion = process.version +const nodeMajorVersion = Number.parseInt(nodeVersion.slice(1, nodeVersion.indexOf('.'))) + module.exports = { - 'node-option': [process.version.startsWith('v16.') ? 'require=ts-node/register' : 'import=./node/register.mjs'], + 'node-option': nodeMajorVersion > 16 ? ['import=./node/register.mjs'] : undefined, extension: ['ts'], - spec: 'src/tests/**/*.spec.ts' -} \ No newline at end of file + spec: 'src/tests/**/*.spec.ts', + loader: nodeMajorVersion <= 16 ? 'ts-node/esm' : undefined +}