Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Commit

Permalink
fix: INT-2324 fix the broken CEN tests (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
grzpab authored Dec 13, 2023
1 parent 99f7d50 commit 6111436
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/executeMainThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
NoTelemetryService,
} from './telemetryService.js';
import { APP_INSIGHTS_INSTRUMENTATION_STRING } from './constants.js';
import { readFile } from 'node:fs/promises';

// the build script contains the version
declare const __INTUITA_CLI_VERSION__: string;
Expand Down Expand Up @@ -214,6 +215,9 @@ export const executeMainThread = async () => {
tarService,
);

const getCodemodSource = (path: string) =>
readFile(path, { encoding: 'utf8' });

const runner = new Runner(
fs as unknown as IFs,
printer,
Expand All @@ -226,6 +230,7 @@ export const executeMainThread = async () => {
argumentRecord,
nameOrPath,
process.cwd(),
getCodemodSource,
homedir(),
);

Expand Down
8 changes: 4 additions & 4 deletions src/runCodemod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { SafeArgumentRecord } from './safeArgumentRecord.js';
import { FlowSettings } from './schemata/flowSettingsSchema.js';
import { WorkerThreadMessage } from './workerThreadMessages.js';
import { RunSettings } from './runSettings.js';
import { readFile } from 'node:fs/promises';

const TERMINATE_IDLE_THREADS_TIMEOUT = 30 * 1000;

Expand Down Expand Up @@ -156,6 +155,7 @@ export const runCodemod = async (
) => void,
safeArgumentRecord: SafeArgumentRecord,
currentWorkingDirectory: string,
getCodemodSource: (path: string) => Promise<string>,
): Promise<void> => {
const name = 'name' in codemod ? codemod.name : codemod.indexPath;

Expand Down Expand Up @@ -191,6 +191,7 @@ export const runCodemod = async (
},
safeArgumentRecord,
currentWorkingDirectory,
getCodemodSource,
);

for (const command of commands) {
Expand Down Expand Up @@ -266,6 +267,7 @@ export const runCodemod = async (
},
safeArgumentRecord,
currentWorkingDirectory,
getCodemodSource,
);

for (const command of commands) {
Expand Down Expand Up @@ -338,9 +340,7 @@ export const runCodemod = async (
return;
}

const codemodSource = await readFile(codemod.indexPath, {
encoding: 'utf8',
});
const codemodSource = await getCodemodSource(codemod.indexPath);

const transpiledSource = codemod.indexPath.endsWith('.ts')
? transpile(codemodSource.toString())
Expand Down
4 changes: 4 additions & 0 deletions src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class Runner {
protected readonly _argumentRecord: ArgumentRecord,
protected readonly _name: string | null,
protected readonly _currentWorkingDirectory: string,
protected readonly _getCodemodSource: (path: string) => Promise<string>,
homeDirectoryPath: string,
) {
this.__caseHashDigest = randomBytes(20);
Expand Down Expand Up @@ -125,6 +126,7 @@ export class Runner {
(message) => this._printer.printMessage(message),
safeArgumentRecord,
this._currentWorkingDirectory,
this._getCodemodSource,
);

await surfaceAgnosticCaseService.emitPostamble();
Expand Down Expand Up @@ -172,6 +174,7 @@ export class Runner {
(message) => this._printer.printMessage(message),
safeArgumentRecord,
this._currentWorkingDirectory,
this._getCodemodSource,
);

this._telemetry.sendEvent({
Expand Down Expand Up @@ -240,6 +243,7 @@ export class Runner {
(message) => this._printer.printMessage(message),
safeArgumentRecord,
this._currentWorkingDirectory,
this._getCodemodSource,
);

await surfaceAgnosticCaseService.emitPostamble();
Expand Down
13 changes: 12 additions & 1 deletion test/runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function transform(file, api, options) {
}
`;

describe('Runner', function (this) {
describe('Runner', function () {
it('should transform staged files using the pre-commit codemods', async () => {
const volume = Volume.fromJSON({
'/code/a.ts': 'unchanged',
Expand Down Expand Up @@ -105,6 +105,16 @@ describe('Runner', function (this) {
const currentWorkingDirectory = '/';
const homedir = '/home/abc';

const getCodemodSource = async (path: string) => {
const data = await ifs.promises.readFile(path);

if (typeof data === 'string') {
return data;
}

return data.toString('utf8');
};

const runner = new Runner(
ifs,
printer,
Expand All @@ -119,6 +129,7 @@ describe('Runner', function (this) {
{},
null,
currentWorkingDirectory,
getCodemodSource,
homedir,
);

Expand Down

0 comments on commit 6111436

Please sign in to comment.