diff --git a/.github/workflows/testLatestPublish.yml b/.github/workflows/testLatestPublish.yml index 9d3cbe65a..49252ade3 100644 --- a/.github/workflows/testLatestPublish.yml +++ b/.github/workflows/testLatestPublish.yml @@ -26,10 +26,11 @@ jobs: uses: actions/setup-node@v2 with: node-version: 16.x + - name: Install Deps + run: npm install - name: Test Latest CLI Release run: | - npx --yes --package=@hubspot/cli@latest --call='hs --help --use-env' - shell: bash + npm run test-cli --cliNPMVersion="latest" env: PORTAL_ID: ${{ secrets.ACCEPTANCE_TEST_PORTAL_ID }} PERSONAL_ACCESS_KEY: ${{ secrets.ACCEPTANCE_TEST_PERSONAL_ACCESS_KEY }} diff --git a/acceptance-tests/lib/env.js b/acceptance-tests/lib/env.js index d7c96f4e6..a9d1cc6e5 100644 --- a/acceptance-tests/lib/env.js +++ b/acceptance-tests/lib/env.js @@ -34,6 +34,7 @@ const getEnvValue = envVariable => { const setArgsOverrides = args => { args.portalId && (argsOverrides.portalId = args.portalId); args.cliPath && (argsOverrides.cliPath = args.cliPath); + args.cliNPMVersion && (argsOverrides.cliNPMVersion = args.cliNPMVersion); args.personalAccessKey && (argsOverrides.personalAccessKey = args.personalAccessKey); argsOverrides.qa = args.qa; @@ -45,6 +46,7 @@ const envOverrides = getTruthyValuesOnly({ portalId: getEnvValue('PORTAL_ID') || getEnvValue('ACCOUNT_ID'), cliPath: getEnvValue('CLI_PATH'), personalAccessKey: getEnvValue('PERSONAL_ACCESS_KEY'), + cliNPMVersion: getEnvValue('CLI_NPM_VERSION'), }); const getTestConfig = () => { @@ -57,7 +59,13 @@ const getTestConfig = () => { ); } - if (!config.cliPath) { + if (config.cliPath && config.cliNPMVersion) { + throw new Error( + 'You cannot specify both a cliPath and a cliNPMVersion. Remove one and try again.' + ); + } + + if (!config.cliPath && !config.cliNPMVersion) { const defaultPath = path.join(process.cwd(), DEFAULT_CLI_PATH); if (existsSync(defaultPath)) { diff --git a/acceptance-tests/run-tests b/acceptance-tests/run-tests index f38eb2012..a01cd32a7 100755 --- a/acceptance-tests/run-tests +++ b/acceptance-tests/run-tests @@ -18,12 +18,17 @@ setArgsOverrides( .option('accountId', { alias: ['p', 'portalId', 'a'], type: 'string', - description: 'Account ID', + description: 'The account ID to use', }) .option('cliPath', { alias: 'c', type: 'string', - description: 'CLI path', + description: 'The path to the CLI', + }) + .option('cliNPMVersion', { + alias: 'npm', + type: "string", + description: "The npm version of the CLI to download and run" }) .option('personalAccessKey', { alias: 'pak', @@ -33,7 +38,7 @@ setArgsOverrides( .option('qa', { type: 'boolean', default: false, - description: 'Set this if you are using a app.hubspotqa.com site', + description: 'Set this if you are using an app.hubspotqa.com account', }) .option('headless', { type: 'boolean', @@ -55,7 +60,7 @@ setArgsOverrides( testRunner.addReporter(reporter); global.config = getTestConfig(); - global.cli = cmd.createCli(global.config.cliPath); + global.cli = cmd.createCli(global.config.cliPath, global.config.cliNPMVersion); await global.cli.execute( ['init', `--c="${CONFIG_FILE_NAME}"`], diff --git a/acceptance-tests/tests/helpers/cmd.js b/acceptance-tests/tests/helpers/cmd.js index 20832d6c5..006b83fa1 100644 --- a/acceptance-tests/tests/helpers/cmd.js +++ b/acceptance-tests/tests/helpers/cmd.js @@ -12,21 +12,31 @@ const PATH = process.env.PATH; /** * Creates a child process with script path - * @param {string} processPath Path of the process to execute + * @param {string} cliPath Path of the CLI process to execute + * @param {string} cliNPMVersion NPM Version number * @param {Array} args Arguments to the command * @param {Object} env (optional) Environment variables */ -function createProcess(processPath, args = [], env = null) { - // Ensure that path exists - if (!processPath || !existsSync(processPath)) { - throw new Error('Invalid process path'); - } +function createProcess(cliPath, cliNPMVersion, args = [], env = null) { + let processCommand; - args = [processPath].concat(args); + if (cliNPMVersion) { + processCommand = 'npx'; + args = ['--yes', '--package', `@hubspot/cli@${cliNPMVersion}`, 'hs'].concat( + args + ); + } else { + // Ensure that path exists + if (!cliPath || !existsSync(cliPath)) { + throw new Error(`Invalid process path ${cliPath}`); + } + processCommand = 'node'; + args = [cliPath].concat(args); + } // This works for node based CLIs, but can easily be adjusted to // any other process installed in the system - return spawn('node', args, { + return spawn(processCommand, args, { env: Object.assign( { NODE_ENV: 'test', @@ -48,7 +58,13 @@ function createProcess(processPath, args = [], env = null) { * @param {Array} inputs (Optional) Array of inputs (user responses) * @param {Object} opts (optional) Environment variables */ -function executeWithInput(processPath, args = [], inputs = [], opts = {}) { +function executeWithInput( + cliPath, + cliNPMVersion, + args = [], + inputs = [], + opts = {} +) { if (!Array.isArray(inputs)) { opts = inputs; inputs = []; @@ -59,7 +75,7 @@ function executeWithInput(processPath, args = [], inputs = [], opts = {}) { } const { env = opts.env, timeout = 500, maxTimeout = 10000 } = opts; - const childProcess = createProcess(processPath, args, env); + const childProcess = createProcess(cliPath, cliNPMVersion, args, env); childProcess.stdin.setEncoding('utf-8'); let currentInputTimeout, killIOTimeout; @@ -171,8 +187,8 @@ function executeWithInput(processPath, args = [], inputs = [], opts = {}) { module.exports = { createProcess, - createCli: processPath => ({ - execute: (...args) => executeWithInput(processPath, ...args), + createCli: (cliPath, cliNPMVersion) => ({ + execute: (...args) => executeWithInput(cliPath, cliNPMVersion, ...args), }), DOWN: '\x1B\x5B\x42', UP: '\x1B\x5B\x41', diff --git a/acceptance-tests/tests/list.spec.js b/acceptance-tests/tests/list.spec.js index 6655c5372..0441505a4 100644 --- a/acceptance-tests/tests/list.spec.js +++ b/acceptance-tests/tests/list.spec.js @@ -5,7 +5,6 @@ describe('hs list', () => { it('should print the correct output', async () => { let val = await cli.execute(['list', `--c="${CONFIG_FILE_NAME}"`]); - console.log(val); expect(val).toContain('@marketplace'); }, 20000); });