From b0606814f91243a21b08b7869e0505ea8b1bb646 Mon Sep 17 00:00:00 2001 From: Roger Qiu Date: Sun, 13 Aug 2023 00:35:17 +1000 Subject: [PATCH] fix: `npm test` now needs windows support for `NODE_OPTIONS` --- package.json | 6 +++--- scripts/test.mjs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 scripts/test.mjs diff --git a/package.json b/package.json index 4ec316c..82ca6c3 100644 --- a/package.json +++ b/package.json @@ -29,9 +29,9 @@ "build": "shx rm -rf ./dist && tsc -p ./tsconfig.build.json", "postversion": "npm install --package-lock-only --ignore-scripts --silent", "tsx": "tsx", - "test": "tsc -p ./tsconfig.build.json && NODE_OPTIONS=--experimental-vm-modules jest", - "lint": "eslint '{src,tests,scripts,benches}/**/*.{js,ts}'", - "lintfix": "eslint '{src,tests,scripts,benches}/**/*.{js,ts}' --fix", + "test": "node ./scripts/test.mjs", + "lint": "eslint '{src,tests,scripts,benches}/**/*.{js,mjs,ts,mts,jsx,tsx}'", + "lintfix": "eslint '{src,tests,scripts,benches}/**/*.{js,mjs,ts,mts,jsx,tsx}' --fix", "lint-shell": "find ./src ./tests ./scripts -type f -regextype posix-extended -regex '.*\\.(sh)' -exec shellcheck {} +", "docs": "shx rm -rf ./docs && typedoc --gitRevision master --tsconfig ./tsconfig.build.json --out ./docs src", "bench": "tsc -p ./tsconfig.build.json && shx rm -rf ./benches/results && tsx ./benches/index.ts" diff --git a/scripts/test.mjs b/scripts/test.mjs new file mode 100644 index 0000000..1b398da --- /dev/null +++ b/scripts/test.mjs @@ -0,0 +1,47 @@ +#!/usr/bin/env node + +import os from 'node:os'; +import path from 'node:path'; +import url from 'node:url'; +import process from 'node:process'; +import childProcess from 'node:child_process'; + +const projectPath = path.dirname( + path.dirname(url.fileURLToPath(import.meta.url)), +); + +const platform = os.platform(); + +/* eslint-disable no-console */ +async function main() { + const tscArgs = [`-p`, path.join(projectPath, 'tsconfig.build.json')]; + console.error('Running tsc:'); + console.error(['tsc', ...tscArgs].join(' ')); + childProcess.execFileSync('tsc', tscArgs, { + stdio: ['inherit', 'inherit', 'inherit'], + windowsHide: true, + encoding: 'utf-8', + shell: platform === 'win32' ? true : false, + }); + const jestArgs = []; + console.error('Running jest:'); + console.error(['jest', ...jestArgs].join(' ')); + childProcess.execFileSync('jest', jestArgs, { + env: { + ...process.env, + NODE_OPTIONS: '--experimental-vm-modules', + }, + stdio: ['inherit', 'inherit', 'inherit'], + windowsHide: true, + encoding: 'utf-8', + shell: platform === 'win32' ? true : false, + }); +} +/* eslint-enable no-console */ + +if (import.meta.url.startsWith('file:')) { + const modulePath = url.fileURLToPath(import.meta.url); + if (process.argv[1] === modulePath) { + void main(); + } +}