Skip to content

Commit 2d39416

Browse files
committed
fix: import.meta usage with jest
1 parent 2385628 commit 2d39416

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

jest.config.cjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ module.exports = {
6060
'/src/cli.ts',
6161
'/src/command-line-arguments.ts',
6262
'/src/interactive-ui.ts',
63+
'/src/dirname.ts',
6364
],
6465

6566
// Indicates which provider should be used to instrument code for coverage
@@ -218,7 +219,7 @@ module.exports = {
218219

219220
// A map from regular expressions to paths to transformers
220221
transform: {
221-
"\\.[jt]sx?$": "babel-jest"
222+
'\\.[jt]sx?$': 'babel-jest',
222223
},
223224

224225
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation

src/dirname.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { fileURLToPath } from 'url';
2+
import { dirname } from 'path';
3+
4+
const __filename = fileURLToPath(import.meta.url);
5+
const __dirname = dirname(__filename);
6+
7+
/**
8+
* Get the current directory path.
9+
*
10+
* @returns The current directory path.
11+
*/
12+
export function getCurrentDirectoryPath() {
13+
return __dirname;
14+
}

src/interactive-ui.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { WriteStream } from 'fs';
2-
import { fileURLToPath } from 'url';
3-
import { dirname, join } from 'path';
2+
import { join } from 'path';
43
import express from 'express';
54
import {
65
restoreChangelogsForSkippedPackages,
@@ -25,11 +24,9 @@ import {
2524
updateYarnLockfile,
2625
} from './yarn-commands.js';
2726
import { readFile } from './fs.js';
27+
import { getCurrentDirectoryPath } from './dirname.js';
2828

29-
const __filename = fileURLToPath(import.meta.url);
30-
const __dirname = dirname(__filename);
31-
32-
const UI_BUILD_DIR = join(__dirname, 'ui');
29+
const UI_BUILD_DIR = join(getCurrentDirectoryPath(), 'ui');
3330

3431
type InteractiveUIOptions = {
3532
project: Project;

src/main.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import * as interactiveUi from './interactive-ui.js';
88
jest.mock('./initial-parameters');
99
jest.mock('./monorepo-workflow-operations');
1010
jest.mock('./interactive-ui');
11+
jest.mock('./dirname', () => ({
12+
getCurrentDirectoryPath: jest.fn().mockReturnValue('/path/to/somewhere'),
13+
}));
1114

1215
describe('main', () => {
1316
it('executes the monorepo workflow if the project is a monorepo', async () => {

0 commit comments

Comments
 (0)