From fc7a5fcc0602f407b92593fa56dd5a7ba03d4fd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Connor=20B=C3=A4r?= Date: Fri, 1 Dec 2023 14:56:48 +0100 Subject: [PATCH] Fix process.cwd mock --- .../eslint/__snapshots__/config.spec.ts.snap | 32 +++++++++---------- src/configs/eslint/config.spec.ts | 10 ++---- src/configs/eslint/config.ts | 4 +-- src/lib/files.spec.ts | 16 ++++------ 4 files changed, 27 insertions(+), 35 deletions(-) diff --git a/src/configs/eslint/__snapshots__/config.spec.ts.snap b/src/configs/eslint/__snapshots__/config.spec.ts.snap index 320af179..3f390966 100644 --- a/src/configs/eslint/__snapshots__/config.spec.ts.snap +++ b/src/configs/eslint/__snapshots__/config.spec.ts.snap @@ -2806,7 +2806,7 @@ exports[`eslint > with options > should return a config for { language: 'TypeScr "./tsconfig.json", ], "sourceType": "module", - "tsconfigRootDir": "/Users/connorbar/Projects/github.com/sumup-oss/foundry", + "tsconfigRootDir": "/project/dir", }, "plugins": [ "@typescript-eslint", @@ -3109,7 +3109,7 @@ exports[`eslint > with options > should return a config for { language: 'TypeScr "./tsconfig.json", ], "sourceType": "module", - "tsconfigRootDir": "/Users/connorbar/Projects/github.com/sumup-oss/foundry", + "tsconfigRootDir": "/project/dir", }, "plugins": [ "@typescript-eslint", @@ -3410,7 +3410,7 @@ exports[`eslint > with options > should return a config for { language: 'TypeScr "./tsconfig.json", ], "sourceType": "module", - "tsconfigRootDir": "/Users/connorbar/Projects/github.com/sumup-oss/foundry", + "tsconfigRootDir": "/project/dir", }, "plugins": [ "@typescript-eslint", @@ -3718,7 +3718,7 @@ exports[`eslint > with options > should return a config for { language: 'TypeScr "./tsconfig.json", ], "sourceType": "module", - "tsconfigRootDir": "/Users/connorbar/Projects/github.com/sumup-oss/foundry", + "tsconfigRootDir": "/project/dir", }, "plugins": [ "@typescript-eslint", @@ -4052,7 +4052,7 @@ exports[`eslint > with options > should return a config for { language: 'TypeScr "./tsconfig.json", ], "sourceType": "module", - "tsconfigRootDir": "/Users/connorbar/Projects/github.com/sumup-oss/foundry", + "tsconfigRootDir": "/project/dir", }, "plugins": [ "@typescript-eslint", @@ -4352,7 +4352,7 @@ exports[`eslint > with options > should return a config for { language: 'TypeScr "./tsconfig.json", ], "sourceType": "module", - "tsconfigRootDir": "/Users/connorbar/Projects/github.com/sumup-oss/foundry", + "tsconfigRootDir": "/project/dir", }, "plugins": [ "@typescript-eslint", @@ -4649,7 +4649,7 @@ exports[`eslint > with options > should return a config for { language: 'TypeScr "./tsconfig.json", ], "sourceType": "module", - "tsconfigRootDir": "/Users/connorbar/Projects/github.com/sumup-oss/foundry", + "tsconfigRootDir": "/project/dir", }, "plugins": [ "@typescript-eslint", @@ -4936,7 +4936,7 @@ exports[`eslint > with options > should return a config for { language: 'TypeScr "./tsconfig.json", ], "sourceType": "module", - "tsconfigRootDir": "/Users/connorbar/Projects/github.com/sumup-oss/foundry", + "tsconfigRootDir": "/project/dir", }, "plugins": [ "@typescript-eslint", @@ -5241,7 +5241,7 @@ exports[`eslint > with options > should return a config for { language: 'TypeScr "./tsconfig.json", ], "sourceType": "module", - "tsconfigRootDir": "/Users/connorbar/Projects/github.com/sumup-oss/foundry", + "tsconfigRootDir": "/project/dir", }, "plugins": [ "@typescript-eslint", @@ -5541,7 +5541,7 @@ exports[`eslint > with options > should return a config for { language: 'TypeScr "./tsconfig.json", ], "sourceType": "module", - "tsconfigRootDir": "/Users/connorbar/Projects/github.com/sumup-oss/foundry", + "tsconfigRootDir": "/project/dir", }, "plugins": [ "@typescript-eslint", @@ -5839,7 +5839,7 @@ exports[`eslint > with options > should return a config for { language: 'TypeScr "./tsconfig.json", ], "sourceType": "module", - "tsconfigRootDir": "/Users/connorbar/Projects/github.com/sumup-oss/foundry", + "tsconfigRootDir": "/project/dir", }, "plugins": [ "@typescript-eslint", @@ -6144,7 +6144,7 @@ exports[`eslint > with options > should return a config for { language: 'TypeScr "./tsconfig.json", ], "sourceType": "module", - "tsconfigRootDir": "/Users/connorbar/Projects/github.com/sumup-oss/foundry", + "tsconfigRootDir": "/project/dir", }, "plugins": [ "@typescript-eslint", @@ -6477,7 +6477,7 @@ exports[`eslint > with options > should return a config for { language: 'TypeScr "./tsconfig.json", ], "sourceType": "module", - "tsconfigRootDir": "/Users/connorbar/Projects/github.com/sumup-oss/foundry", + "tsconfigRootDir": "/project/dir", }, "plugins": [ "@typescript-eslint", @@ -6774,7 +6774,7 @@ exports[`eslint > with options > should return a config for { language: 'TypeScr "./tsconfig.json", ], "sourceType": "module", - "tsconfigRootDir": "/Users/connorbar/Projects/github.com/sumup-oss/foundry", + "tsconfigRootDir": "/project/dir", }, "plugins": [ "@typescript-eslint", @@ -7068,7 +7068,7 @@ exports[`eslint > with options > should return a config for { language: 'TypeScr "./tsconfig.json", ], "sourceType": "module", - "tsconfigRootDir": "/Users/connorbar/Projects/github.com/sumup-oss/foundry", + "tsconfigRootDir": "/project/dir", }, "plugins": [ "@typescript-eslint", @@ -7352,7 +7352,7 @@ exports[`eslint > with options > should return a config for { language: 'TypeScr "./tsconfig.json", ], "sourceType": "module", - "tsconfigRootDir": "/Users/connorbar/Projects/github.com/sumup-oss/foundry", + "tsconfigRootDir": "/project/dir", }, "plugins": [ "@typescript-eslint", diff --git a/src/configs/eslint/config.spec.ts b/src/configs/eslint/config.spec.ts index 5a9fe2da..52dee153 100644 --- a/src/configs/eslint/config.spec.ts +++ b/src/configs/eslint/config.spec.ts @@ -21,13 +21,9 @@ import { getOptions as getOptionsMock } from '../../lib/options'; import { customizeConfig, createConfig } from './config'; -vi.mock('process', async () => { - const actual = await vi.importActual('process'); - return { - ...actual, - cwd: (): string => '/project/dir', - }; -}); +vi.mock('process', () => ({ + cwd: (): string => '/project/dir', +})); vi.mock('../../lib/options', () => ({ getOptions: vi.fn(() => ({})), diff --git a/src/configs/eslint/config.ts b/src/configs/eslint/config.ts index e60e9913..18ad9fb7 100644 --- a/src/configs/eslint/config.ts +++ b/src/configs/eslint/config.ts @@ -13,7 +13,7 @@ * limitations under the License. */ -import process from 'process'; +import { cwd } from 'process'; import { flow, mergeWith, isArray, isObject, isEmpty, uniq } from 'lodash/fp'; @@ -166,7 +166,7 @@ function customizeLanguage(language?: Language) { plugins: ['@typescript-eslint'], parser: '@typescript-eslint/parser', parserOptions: { - tsconfigRootDir: process.cwd(), + tsconfigRootDir: cwd(), project: ['./tsconfig.json'], extraFileExtensions: ['.json'], sourceType: 'module', diff --git a/src/lib/files.spec.ts b/src/lib/files.spec.ts index b5d90d75..3d26afd9 100644 --- a/src/lib/files.spec.ts +++ b/src/lib/files.spec.ts @@ -21,16 +21,12 @@ import { PackageJson } from '../types/shared'; import { writeFile, addPackageScript, savePackageJson } from './files'; -vi.mock('fs', async () => { - const actual = await vi.importActual('fs'); - return { - ...actual, - // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call - writeFile: vi.fn((_file, _data, _options, callback) => callback()), - // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call - mkdir: vi.fn((_dir, _options, callback) => callback()), - }; -}); +vi.mock('fs', () => ({ + // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call + writeFile: vi.fn((_file, _data, _options, callback) => callback()), + // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call + mkdir: vi.fn((_dir, _options, callback) => callback()), +})); const content = 'module.exports = "Hello world"';