Skip to content

Commit

Permalink
Fix process.cwd mock
Browse files Browse the repository at this point in the history
  • Loading branch information
connor-baer committed Dec 1, 2023
1 parent be4da0c commit fc7a5fc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 35 deletions.
32 changes: 16 additions & 16 deletions src/configs/eslint/__snapshots__/config.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
10 changes: 3 additions & 7 deletions src/configs/eslint/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof import('process')>('process');
return {
...actual,
cwd: (): string => '/project/dir',
};
});
vi.mock('process', () => ({
cwd: (): string => '/project/dir',
}));

vi.mock('../../lib/options', () => ({
getOptions: vi.fn(() => ({})),
Expand Down
4 changes: 2 additions & 2 deletions src/configs/eslint/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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',
Expand Down
16 changes: 6 additions & 10 deletions src/lib/files.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,12 @@ import { PackageJson } from '../types/shared';

import { writeFile, addPackageScript, savePackageJson } from './files';

vi.mock('fs', async () => {
const actual = await vi.importActual<typeof import('fs')>('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"';

Expand Down

0 comments on commit fc7a5fc

Please sign in to comment.