@wise/wds-codemods 0.0.1-experimental-8e7ee6c → 0.0.1-experimental-d9053f9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wise/wds-codemods",
3
- "version": "0.0.1-experimental-8e7ee6c",
3
+ "version": "0.0.1-experimental-d9053f9",
4
4
  "license": "UNLICENSED",
5
5
  "author": "Wise Payments Ltd.",
6
6
  "type": "module",
@@ -5,7 +5,7 @@ import path from 'path';
5
5
 
6
6
  import { runCodemod } from '../runCodemod';
7
7
  import * as utils from '../utils';
8
- import { hasPackageVersionFromPath } from '../utils/hasPackageVersion';
8
+ import { findClosestGitignore, hasPackageVersionFromPath } from '../utils/hasPackageVersion';
9
9
 
10
10
  // Mock dynamic import - only define once
11
11
  const mockImport = jest.fn();
@@ -22,6 +22,7 @@ jest.mock('child_process', () => ({
22
22
 
23
23
  jest.mock('../utils/hasPackageVersion', () => ({
24
24
  hasPackageVersionFromPath: jest.fn(),
25
+ findClosestGitignore: jest.fn(() => null), // Return null to simulate no gitignore found
25
26
  }));
26
27
 
27
28
  jest.mock('path', () => ({
@@ -55,32 +56,32 @@ describe('runCodemod', () => {
55
56
  jest.clearAllMocks();
56
57
  });
57
58
 
58
- // it('should run jscodeshift with correct command using mock transformsDir', async () => {
59
- // const mockTransformsDir = '/mock/dist/transforms';
60
-
61
- // (path.resolve as jest.Mock).mockImplementation((...args: string[]) => args.join('/'));
62
- // (utils.loadTransformModules as jest.Mock).mockResolvedValue({
63
- // transformFiles: ['transformA', 'transformB'],
64
- // });
65
- // (utils.getOptions as jest.Mock).mockResolvedValue({
66
- // transformFile: 'transformA',
67
- // targetPath: 'src/',
68
- // dry: true,
69
- // print: false,
70
- // gitignore: true,
71
- // ignorePattern: undefined,
72
- // isMonorepo: false,
73
- // });
74
-
75
- // await runCodemod(mockTransformsDir);
76
-
77
- // expect(utils.loadTransformModules).toHaveBeenCalledWith(mockTransformsDir);
78
- // expect(utils.getOptions).toHaveBeenCalledWith(['transformA', 'transformB']);
79
- // expect(execSync).toHaveBeenCalledWith(
80
- // 'npx jscodeshift -t /mock/dist/transforms/transformA.js src/ --extensions=tsx,ts,jsx,js --dry --gitignore',
81
- // { stdio: 'inherit' },
82
- // );
83
- // });
59
+ it('should run jscodeshift with correct command using mock transformsDir', async () => {
60
+ const mockTransformsDir = '/mock/dist/transforms';
61
+
62
+ (path.resolve as jest.Mock).mockImplementation((...args: string[]) => args.join('/'));
63
+ (utils.loadTransformModules as jest.Mock).mockResolvedValue({
64
+ transformFiles: [Promise.resolve('transformA'), Promise.resolve('transformB')],
65
+ });
66
+ (utils.getOptions as jest.Mock).mockResolvedValue({
67
+ transformFile: 'transformA',
68
+ targetPath: 'src/',
69
+ dry: true,
70
+ print: false,
71
+ gitignore: true,
72
+ ignorePattern: undefined,
73
+ isMonorepo: false,
74
+ });
75
+
76
+ await runCodemod(mockTransformsDir);
77
+
78
+ expect(utils.loadTransformModules).toHaveBeenCalledWith(mockTransformsDir);
79
+ expect(utils.getOptions).toHaveBeenCalledWith(['transformA', 'transformB']);
80
+ expect(execSync).toHaveBeenCalledWith(
81
+ 'npx jscodeshift -t /mock/dist/transforms/transformA.js src/ --extensions=tsx,ts,jsx,js --ignore-pattern=**/node_modules/** --ignore-pattern=**/dist/** --ignore-pattern=**/*.d.ts --dry',
82
+ { stdio: 'inherit' },
83
+ );
84
+ });
84
85
 
85
86
  it('should log error if no transform scripts found', async () => {
86
87
  (path.resolve as jest.Mock).mockReturnValue('/mock/dist/transforms');
@@ -106,4 +107,32 @@ describe('runCodemod', () => {
106
107
 
107
108
  expect(consoleErrorSpy).toHaveBeenCalledWith('Error running codemod:', testError.message);
108
109
  });
110
+
111
+ // Add a test for when gitignore is found
112
+ it('should include gitignore flag when gitignore file is found', async () => {
113
+ const mockTransformsDir = '/mock/dist/transforms';
114
+ const mockGitignorePath = '/path/to/.gitignore';
115
+
116
+ (findClosestGitignore as jest.Mock).mockReturnValueOnce(mockGitignorePath);
117
+ (path.resolve as jest.Mock).mockImplementation((...args: string[]) => args.join('/'));
118
+ (utils.loadTransformModules as jest.Mock).mockResolvedValue({
119
+ transformFiles: [Promise.resolve('transformA'), Promise.resolve('transformB')],
120
+ });
121
+ (utils.getOptions as jest.Mock).mockResolvedValue({
122
+ transformFile: 'transformA',
123
+ targetPath: 'src/',
124
+ dry: true,
125
+ print: false,
126
+ gitignore: true,
127
+ ignorePattern: undefined,
128
+ isMonorepo: false,
129
+ });
130
+
131
+ await runCodemod(mockTransformsDir);
132
+
133
+ expect(execSync).toHaveBeenCalledWith(
134
+ `npx jscodeshift -t /mock/dist/transforms/transformA.js src/ --extensions=tsx,ts,jsx,js --ignore-pattern=**/node_modules/** --ignore-pattern=**/dist/** --ignore-pattern=**/*.d.ts --dry --ignore-config=${mockGitignorePath}`,
135
+ { stdio: 'inherit' },
136
+ );
137
+ });
109
138
  });