Skip to content

Commit

Permalink
add .mocharc.js to make NODE_ENV='test' work
Browse files Browse the repository at this point in the history
  • Loading branch information
gjf7 committed Oct 16, 2024
1 parent c562c62 commit 5352703
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
8 changes: 8 additions & 0 deletions packages/neovim/.mocharc.js
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion packages/neovim/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 0 additions & 2 deletions packages/neovim/src/testSetup.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
2 changes: 1 addition & 1 deletion packages/neovim/src/utils/findNvim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export function findNvim(opt: FindNvimOptions = {}): Readonly<FindNvimResult> {

// 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.
Expand Down
2 changes: 1 addition & 1 deletion packages/neovim/src/utils/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 5352703

Please sign in to comment.