From 535270329eb6d807c981002b69841aeeda8fbf49 Mon Sep 17 00:00:00 2001 From: Hao Chen <501018786@qq.com> Date: Thu, 17 Oct 2024 01:01:17 +0800 Subject: [PATCH] add .mocharc.js to make NODE_ENV='test' work --- packages/neovim/.mocharc.js | 8 ++++++++ packages/neovim/package.json | 2 +- packages/neovim/src/testSetup.ts | 2 -- packages/neovim/src/utils/findNvim.ts | 2 +- packages/neovim/src/utils/transport.ts | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 packages/neovim/.mocharc.js diff --git a/packages/neovim/.mocharc.js b/packages/neovim/.mocharc.js new file mode 100644 index 00000000..c0193d41 --- /dev/null +++ b/packages/neovim/.mocharc.js @@ -0,0 +1,8 @@ +process.env.NODE_ENV = 'test'; + +module.exports = { + require: ['ts-node/register', 'src/testSetup.ts'], + extension: ['ts'], + spec: ['src/**/*.test.ts'], + exit: true +} \ No newline at end of file diff --git a/packages/neovim/package.json b/packages/neovim/package.json index 6312987d..33606ac0 100644 --- a/packages/neovim/package.json +++ b/packages/neovim/package.json @@ -71,7 +71,7 @@ "scripts": { "doc": "typedoc --out doc --exclude '**/*.test.ts' src", "prepublishOnly": "npm run build", - "test": "NODE_ENV=test mocha --exit --require ts-node/register --require src/testSetup.ts src/**/*.test.ts", + "test": "mocha", "test-coverage": "c8 --reporter=json --reporter=html npm test", "test-staged": "npm test --bail", "test-missing-apis": "npm run build && node scripts/findMissingApi", diff --git a/packages/neovim/src/testSetup.ts b/packages/neovim/src/testSetup.ts index e7d16de9..5679d9e3 100644 --- a/packages/neovim/src/testSetup.ts +++ b/packages/neovim/src/testSetup.ts @@ -1,8 +1,6 @@ // Global test setup. Runs before each test. import { startNvim, stopNvim } from './testUtil'; -process.env.NODE_ENV = 'test'; - export const mochaHooks = { beforeAll: async () => { startNvim(); diff --git a/packages/neovim/src/utils/findNvim.ts b/packages/neovim/src/utils/findNvim.ts index cf6a4422..abca031e 100644 --- a/packages/neovim/src/utils/findNvim.ts +++ b/packages/neovim/src/utils/findNvim.ts @@ -276,7 +276,7 @@ export function findNvim(opt: FindNvimOptions = {}): Readonly { // eslint-disable-next-line import/no-mutable-exports export let exportsForTesting: any; -// 'NODE_ENV=test' is being set in testSetup.ts +// .mocharc.js sets NODE_ENV=test. if (process.env.NODE_ENV === 'test') { // These functions are intentionally not exported. After `nvim` is found, clients can use Nvim's // own `vim.version` module, so node-client shouldn't expose a half-baked "semver" implementation. diff --git a/packages/neovim/src/utils/transport.ts b/packages/neovim/src/utils/transport.ts index d40886af..681c4f1c 100644 --- a/packages/neovim/src/utils/transport.ts +++ b/packages/neovim/src/utils/transport.ts @@ -14,7 +14,7 @@ import { import { Metadata } from '../api/types'; export let exportsForTesting: any; // eslint-disable-line import/no-mutable-exports -// 'NODE_ENV=test' is being set in testSetup.ts +// .mocharc.js sets NODE_ENV=test. if (process.env.NODE_ENV === 'test') { exportsForTesting = { onTransportFail: new EventEmitter(),