From d387c301feb2fec4967fa034a22e63857faf1d26 Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Fri, 27 Oct 2023 11:38:33 -0600 Subject: [PATCH] fix: update bin/dev|run exec for when run.js exist --- SAMPLES.md | 63 +++++++++++++++++++++++++++++++++++++++++++--- src/testSession.ts | 16 ++++++++---- 2 files changed, 71 insertions(+), 8 deletions(-) diff --git a/SAMPLES.md b/SAMPLES.md index 9a1ba949..750a2ffc 100644 --- a/SAMPLES.md +++ b/SAMPLES.md @@ -102,6 +102,12 @@ describe('execCmd', () => { ```typescript import { execCmd } from '@salesforce/cli-plugins-testkit'; +/* + * 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 + */ describe('execCmd', () => { // This would actually be set in the shell or CI environment. @@ -168,6 +174,12 @@ A TestSession provides conveniences to testing plugin commands with options to a ```typescript import { execCmd, TestSession, TestProject } from '@salesforce/cli-plugins-testkit'; +/* + * 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 + */ describe('TestSession', () => { let testSession: TestSession; @@ -196,6 +208,12 @@ describe('TestSession', () => { ```typescript import { execCmd, TestSession, TestProject } from '@salesforce/cli-plugins-testkit'; +/* + * 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 + */ describe('TestSession', () => { let testSession: TestSession; @@ -282,6 +300,12 @@ describe('TestSession', () => { ```typescript import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit'; +/* + * 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 + */ describe('TestSession', () => { let testSession: TestSession; @@ -306,7 +330,12 @@ describe('TestSession', () => { ```typescript import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit'; - +/* + * 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 { tmpdir } from 'os'; import { expect } from 'chai'; @@ -388,6 +417,12 @@ describe('TestSession', () => { ```typescript import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit'; +/* + * 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 + */ describe('TestSession', () => { let testSession: TestSession; @@ -418,6 +453,12 @@ describe('TestSession', () => { ```typescript import { execCmd, TestSession, TestProject } from '@salesforce/cli-plugins-testkit'; +/* + * 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 + */ describe('TestSession', () => { let testSession: TestSession; @@ -450,6 +491,12 @@ describe('TestSession', () => { ```typescript import { execCmd, TestSession, TestProject } from '@salesforce/cli-plugins-testkit'; +/* + * 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 + */ describe('TestSession', () => { let testSession: TestSession; @@ -480,7 +527,12 @@ describe('TestSession', () => { ```typescript import { execCmd, TestSession, TestProject } from '@salesforce/cli-plugins-testkit'; - +/* + * 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 * as path from 'path'; describe('TestSession', () => { @@ -521,7 +573,12 @@ describe('TestSession', () => { ```typescript import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit'; - +/* + * 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 * as shelljs from 'shelljs'; /* diff --git a/src/testSession.ts b/src/testSession.ts index cf24b1c6..29aa8607 100644 --- a/src/testSession.ts +++ b/src/testSession.ts @@ -161,11 +161,17 @@ export class TestSession exte // TESTKIT_EXECUTABLE_PATH env var is not being used, then set it // to use the bin/dev from the cwd now. if (!env.getString('TESTKIT_EXECUTABLE_PATH')) { - const binDev = path.join(process.cwd(), 'bin', 'dev'); - env.setString( - 'TESTKIT_EXECUTABLE_PATH', - fs.existsSync(binDev) ? binDev : path.join(process.cwd(), 'bin', 'run') - ); + let binDev = path.join(process.cwd(), 'bin', 'dev'); + if (!fs.existsSync(binDev)) { + binDev += '.js'; + } + + // only used in the case when bin/run or bin/run.js doesn't exist + let binRun = path.join(process.cwd(), 'bin', 'run'); + if (!fs.existsSync(binRun)) { + binRun += '.js'; + } + env.setString('TESTKIT_EXECUTABLE_PATH', fs.existsSync(binDev) ? binDev : binRun); } this.stubCwd(projectDir);