From: Jérôme Benoit Date: Mon, 20 Mar 2023 01:13:36 +0000 (+0100) Subject: test: fix ts-node configuration with ESM and mocha X-Git-Tag: v1.2.0-0~44 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=92ce54736c01dd6ba96450355dbbcca450337da7;p=e-mobility-charging-stations-simulator.git test: fix ts-node configuration with ESM and mocha Signed-off-by: Jérôme Benoit --- diff --git a/.eslintrc.json b/.eslintrc.json index 9227eed5..c6ce61da 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -167,7 +167,7 @@ } }, { - "files": ["**/*.js", "**/*.mjs"], + "files": ["**/*.js", "**/*.cjs", "**/*.mjs"], "plugins": ["jsdoc"], "extends": ["plugin:jsdoc/recommended", "plugin:n/recommended"], "rules": { diff --git a/.husky/commit-msg b/.husky/commit-msg index c160a771..e526e551 100755 --- a/.husky/commit-msg +++ b/.husky/commit-msg @@ -1,4 +1,4 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" -npx --no -- commitlint --edit ${1} +npx --no -- commitlint --config commitlint.config.cjs --edit ${1} diff --git a/.mocharc.json b/.mocharc.json index 922eb321..dd2d1062 100644 --- a/.mocharc.json +++ b/.mocharc.json @@ -13,5 +13,6 @@ "full-trace": true, "enable-source-maps": true, "exit": true, - "require": ["ts-node/register/transpile-only", "mochawesome/register"] + "node-option": ["experimental-specifier-resolution=node", "loader=ts-node/esm"], + "require": ["mochawesome/register"] } diff --git a/commitlint.config.js b/commitlint.config.cjs similarity index 100% rename from commitlint.config.js rename to commitlint.config.cjs diff --git a/docker/Dockerfile b/docker/Dockerfile index 1921770c..cc86f95d 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -2,7 +2,7 @@ FROM node:lts-alpine as builder # Build simulator WORKDIR /usr/builder -COPY .npmrc package.json package-lock.json tsconfig.json rollup.config.mjs prepare.js build-requirements.mjs ./ +COPY .npmrc package.json package-lock.json tsconfig.json rollup.config.mjs prepare.cjs build-requirements.mjs ./ COPY src ./src COPY docker/config.json ./src/assets/config.json COPY docker/authorization-tags.json ./src/assets/authorization-tags.json diff --git a/package.json b/package.json index b5d24c3e..ea0e84b7 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "url": "http://www.apache.org/licenses/LICENSE-2.0" } ], + "type": "module", "exports": [ "./dist/start.mjs" ], @@ -39,7 +40,7 @@ "useTsNode": true }, "scripts": { - "prepare": "node prepare.js", + "prepare": "node prepare.cjs", "build-requirements": "node --no-warnings build-requirements.mjs", "start": "npm run build && cross-env NODE_ENV=production node -r source-map-support/register dist/start.mjs", "start:dev": "npm run build:dev && cross-env NODE_ENV=development node -r source-map-support/register dist/start.mjs", @@ -53,8 +54,8 @@ "build": "npm run rollup", "build:dev": "npm run rollup -- --environment BUILD:development", "build:dev:watch": "npm run rollup -- --environment BUILD:development --watch", - "lint": "cross-env TIMING=1 eslint --cache --ext .js,.mjs,.ts src", - "lint:fix": "cross-env TIMING=1 eslint --cache --fix --ext .js,.mjs,.ts src", + "lint": "cross-env TIMING=1 eslint --cache --ext .js,.cjs,.mjs,.ts src", + "lint:fix": "cross-env TIMING=1 eslint --cache --fix --ext .js,.cjs,.mjs,.ts src", "format": "prettier --cache --write .", "test": "c8 mocha test/**/*Test.ts", "test:debug": "mocha --no-parallel --inspect test/**/*Test.ts", diff --git a/prepare.js b/prepare.cjs similarity index 100% rename from prepare.js rename to prepare.cjs diff --git a/src/scripts/deleteChargingStations.js b/src/scripts/deleteChargingStations.cjs similarity index 100% rename from src/scripts/deleteChargingStations.js rename to src/scripts/deleteChargingStations.cjs diff --git a/src/scripts/setCSPublicFlag.js b/src/scripts/setCSPublicFlag.cjs similarity index 100% rename from src/scripts/setCSPublicFlag.js rename to src/scripts/setCSPublicFlag.cjs diff --git a/tsconfig.json b/tsconfig.json index 11eb8e2a..f30d942d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -68,11 +68,5 @@ // "skipLibCheck": true, /* Skip type checking of declaration files. */ "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ }, - "exclude": ["ui/web/**/*.ts"], - "ts-node": { - "compilerOptions": { - "module": "commonjs", - "verbatimModuleSyntax": false, - } - } + "exclude": ["ui/web/**/*.ts"] }