Skip to content

Commit

Permalink
fix: correct log file name formatting error (#5316)
Browse files Browse the repository at this point in the history
@ W-13682486@
fix logfile name formatting error
ensure the directory to the logfiles is present
  • Loading branch information
peternhale authored Jan 4, 2024
1 parent e795f26 commit dcafddc
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/salesforcedx-utils-vscode/src/date/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const getYYYYMMddHHmmssDateFormat = (localUTCDate: Date): string => {
};

export const makeDoubleDigit = (currentDigit: number): string => {
return format('%02d', currentDigit);
return format('%d', currentDigit).padStart(2, '0');
};

export const optionYYYYMMddHHmmss: Intl.DateTimeFormatOptions = {
Expand Down
65 changes: 65 additions & 0 deletions packages/salesforcedx-utils-vscode/test/jest/date/format.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2023, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import {
getYYYYMMddHHmmssDateFormat,
makeDoubleDigit,
optionYYYYMMddHHmmss,
optionHHmm,
optionMMddYYYY
} from '../../../src/date/format';

describe('getYYYYMMddHHmmssDateFormat', () => {
it('should return the correct date format', () => {
const date = new Date('2022-01-01T12:34:56');
const formattedDate = getYYYYMMddHHmmssDateFormat(date);
expect(formattedDate).toBe('20220101123456');
});
});

describe('makeDoubleDigit', () => {
it('should return the double digit format for single digit numbers', () => {
const doubleDigit = makeDoubleDigit(5);
expect(doubleDigit).toBe('05');
});

it('should return the same number for double digit numbers', () => {
const doubleDigit = makeDoubleDigit(12);
expect(doubleDigit).toBe('12');
});
});

describe('optionYYYYMMddHHmmss', () => {
it('should have the correct options', () => {
expect(optionYYYYMMddHHmmss).toEqual({
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
});
});
});

describe('optionHHmm', () => {
it('should have the correct options', () => {
expect(optionHHmm).toEqual({
hour: '2-digit',
minute: '2-digit'
});
});
});

describe('optionMMddYYYY', () => {
it('should have the correct options', () => {
expect(optionMMddYYYY).toEqual({
month: '2-digit',
day: '2-digit',
year: 'numeric'
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ interface ApexExecuteParameters {
}

export class AnonApexGatherer
implements ParametersGatherer<ApexExecuteParameters> {
implements ParametersGatherer<ApexExecuteParameters>
{
public async gather(): Promise<
CancelResponse | ContinueResponse<ApexExecuteParameters>
> {
Expand Down Expand Up @@ -70,12 +71,9 @@ export class AnonApexGatherer
}
}

export class AnonApexLibraryExecuteExecutor extends LibraryCommandletExecutor<
ApexExecuteParameters
> {
public static diagnostics = vscode.languages.createDiagnosticCollection(
'apex-errors'
);
export class AnonApexLibraryExecuteExecutor extends LibraryCommandletExecutor<ApexExecuteParameters> {
public static diagnostics =
vscode.languages.createDiagnosticCollection('apex-errors');

private isDebugging: boolean;

Expand Down Expand Up @@ -168,6 +166,7 @@ export class AnonApexLibraryExecuteExecutor extends LibraryCommandletExecutor<
return false;
}

fs.mkdirSync(path.dirname(logFilePath), { recursive: true });
fs.writeFileSync(logFilePath, logs);

return true;
Expand Down Expand Up @@ -203,12 +202,8 @@ export class AnonApexLibraryExecuteExecutor extends LibraryCommandletExecutor<
AnonApexLibraryExecuteExecutor.diagnostics.clear();

if (response.diagnostic) {
const {
compileProblem,
exceptionMessage,
lineNumber,
columnNumber
} = response.diagnostic[0];
const { compileProblem, exceptionMessage, lineNumber, columnNumber } =
response.diagnostic[0];
let message;
if (compileProblem && compileProblem !== '') {
message = compileProblem;
Expand Down Expand Up @@ -254,7 +249,7 @@ export class AnonApexLibraryExecuteExecutor extends LibraryCommandletExecutor<
}
}

export const forceAnonApexExecute = async () => {
export const forceAnonApexExecute = async () => {
const commandlet = new SfdxCommandlet(
new SfdxWorkspaceChecker(),
new AnonApexGatherer(),
Expand Down

0 comments on commit dcafddc

Please sign in to comment.