From a5032157b72f4c7e265531a00851708a7c0b5f56 Mon Sep 17 00:00:00 2001 From: Joe Yeager Date: Wed, 9 Oct 2024 10:55:42 -0700 Subject: [PATCH] fix: Fix tests running on latest (#1199) --- .dockerignore | 12 ++++++++++++ .github/workflows/latestPublish.yml | 9 +++------ Dockerfile | 13 +++++++++++-- acceptance-tests/globalSetup.ts | 18 ++++++++++++------ acceptance-tests/lib/cmd.ts | 9 +++------ acceptance-tests/lib/env.ts | 8 ++++---- acceptance-tests/lib/types.ts | 2 +- acceptance-tests/tests/auth.spec.ts | 1 - acceptance-tests/tests/create.spec.ts | 26 +++++++++++++++----------- package.json | 2 +- 10 files changed, 62 insertions(+), 38 deletions(-) diff --git a/.dockerignore b/.dockerignore index 3c3629e64..5a6afe110 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,13 @@ node_modules +.github +.vscode +coverage +docs +tmp +.eslintignore +.eslintrc.js +.gitignore +*.md +jest.config.js +lerna.json +prettier.config.js diff --git a/.github/workflows/latestPublish.yml b/.github/workflows/latestPublish.yml index bf774a1ff..7584d65ba 100644 --- a/.github/workflows/latestPublish.yml +++ b/.github/workflows/latestPublish.yml @@ -7,9 +7,6 @@ on: schedule: - cron: '0 */5 * * *' # Run every 5 hours -env: - version: "latest" - jobs: build: runs-on: ubuntu-latest @@ -25,16 +22,16 @@ jobs: node-version: 18.x - name: Install Deps run: npm install - - name: Add package to npx cache + - name: Globally install the CLI run: | - npx --yes --package @hubspot/cli@${{ env.version }} hs + npm install -g @hubspot/cli@latest - name: Test Latest CLI Release run: | npm run test-cli env: PORTAL_ID: ${{ secrets.ACCEPTANCE_TEST_PORTAL_ID }} PERSONAL_ACCESS_KEY: ${{ secrets.ACCEPTANCE_TEST_PERSONAL_ACCESS_KEY }} - CLI_VERSION: ${{ env.version }} + USE_INSTALLED: true GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Release Failure Slack Report uses: ravsamhq/notify-slack-action@v2 diff --git a/Dockerfile b/Dockerfile index 54041ce2e..90733e2b1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,8 +4,17 @@ FROM node:18 # Create base directory WORKDIR /usr/src/hubspot-cli +RUN npm install -g @hubspot/cli@latest + # Get all the code needed to run the app locally -COPY . . +COPY . ./ + +# Expose the ports for UIE Local dev +EXPOSE 5173 +EXPOSE 5174 + +# Expose the port for the PortManager +EXPOSE 8080 # Install dependencies -RUN yarn +RUN yarn \ No newline at end of file diff --git a/acceptance-tests/globalSetup.ts b/acceptance-tests/globalSetup.ts index da563a894..126ae52fb 100644 --- a/acceptance-tests/globalSetup.ts +++ b/acceptance-tests/globalSetup.ts @@ -1,17 +1,23 @@ import { existsSync, mkdirSync, rmSync } from 'fs'; import { testOutputDir } from './lib/testState'; import type { GlobalSetupContext } from 'vitest/node' +import { getTestConfig } from "./lib/env"; + // Vitest docs on globalSetup modules https://vitest.dev/config/#globalsetup -export function setup({ provide }: GlobalSetupContext) { +export function setup(__context: GlobalSetupContext) { try { - if (!existsSync(testOutputDir)) { - console.log(`Setting up ${testOutputDir} directory\n`); - mkdirSync(testOutputDir); - } else { - console.log(`${testOutputDir} already exists, deleting it's contents\n`); + if(getTestConfig().useInstalled) { + console.log('Using installed version of the hs command') + } + + if(existsSync(testOutputDir)) { + console.log(`The directory ${testOutputDir} already exists, deleting it's contents\n`); rmSync(testOutputDir, { recursive: true, force: true }); } + + console.log(`Setting up ${testOutputDir} directory\n`); + mkdirSync(testOutputDir); } catch (e) { console.log(e) } diff --git a/acceptance-tests/lib/cmd.ts b/acceptance-tests/lib/cmd.ts index 0694ed4d5..d7d8daa9d 100644 --- a/acceptance-tests/lib/cmd.ts +++ b/acceptance-tests/lib/cmd.ts @@ -20,13 +20,10 @@ export function createProcess( env = null ) { let processCommand: string; - const { cliVersion, cliPath, debug } = config; + const { useInstalled, cliPath, debug } = config; - if (cliVersion) { - processCommand = 'npx'; - args = ['--yes', '--package', `@hubspot/cli@${cliVersion}`, 'hs'].concat( - args - ); + if (useInstalled) { + processCommand = 'hs'; } else { // Ensure that path exists if (!cliPath || !existsSync(cliPath)) { diff --git a/acceptance-tests/lib/env.ts b/acceptance-tests/lib/env.ts index 47dd403c8..917c3a080 100644 --- a/acceptance-tests/lib/env.ts +++ b/acceptance-tests/lib/env.ts @@ -29,7 +29,7 @@ const envOverrides: TestConfig = getTruthyValuesOnly({ portalId: getEnvValue('PORTAL_ID') || getEnvValue('ACCOUNT_ID'), cliPath: getEnvValue('CLI_PATH'), personalAccessKey: getEnvValue('PERSONAL_ACCESS_KEY'), - cliVersion: getEnvValue('CLI_VERSION'), + useInstalled: getEnvValue('USE_INSTALLED'), debug: getEnvValue('DEBUG'), qa: getEnvValue('QA'), githubToken: getEnvValue('GITHUB_TOKEN'), @@ -45,13 +45,13 @@ export const getTestConfig = (): TestConfig => { ); } - if (config.cliPath && config.cliVersion) { + if (config.cliPath && config.useInstalled) { throw new Error( - 'You cannot specify both a cliPath and a cliVersion. Remove one and try again.' + 'You cannot specify both a cliPath and useLatest. Remove one and try again.' ); } - if (!config.cliPath && !config.cliVersion) { + if (!config.cliPath && !config.useInstalled) { const defaultPath = path.join(process.cwd(), '../packages/cli/bin/hs'); if (existsSync(defaultPath)) { diff --git a/acceptance-tests/lib/types.ts b/acceptance-tests/lib/types.ts index 97efb4e52..abc835b8b 100644 --- a/acceptance-tests/lib/types.ts +++ b/acceptance-tests/lib/types.ts @@ -1,6 +1,6 @@ export interface TestConfig { debug: boolean; - cliVersion: string; + useInstalled: boolean; cliPath: string; personalAccessKey: string; portalId: string; diff --git a/acceptance-tests/tests/auth.spec.ts b/acceptance-tests/tests/auth.spec.ts index 8c9e0c5bd..43cfa00c5 100644 --- a/acceptance-tests/tests/auth.spec.ts +++ b/acceptance-tests/tests/auth.spec.ts @@ -1,4 +1,3 @@ -import { existsSync } from 'fs'; import { describe, beforeAll, it, expect, afterAll } from 'vitest'; import { ENTER } from '../lib/prompt'; diff --git a/acceptance-tests/tests/create.spec.ts b/acceptance-tests/tests/create.spec.ts index e33d156ad..ea115ef7a 100644 --- a/acceptance-tests/tests/create.spec.ts +++ b/acceptance-tests/tests/create.spec.ts @@ -1,6 +1,5 @@ import { ENTER } from '../lib/prompt'; -import { existsSync } from 'fs'; import { describe, beforeAll, afterAll, it, expect } from 'vitest'; import rimraf from 'rimraf'; import { TestState } from '../lib/testState'; @@ -16,15 +15,19 @@ const FOLDERS = { }, websiteTheme: { folder: 'website-theme', + name: 'website-theme', }, reactApp: { folder: 'react-app', + name: 'react-app', }, vueApp: { folder: 'vue-app', + name: 'vue-app', }, webpackServerless: { folder: 'webpack-serverless', + name: 'webpack-serverless', }, apiSample: { name: 'api-sample', @@ -32,6 +35,7 @@ const FOLDERS = { }, app: { folder: 'app', + name: 'app', }, function: { folder: 'function.functions', @@ -87,46 +91,46 @@ describe('hs create', () => { }); it('website-theme', async () => { - await testState.cli.execute(['create', 'website-theme']); + await testState.cli.execute(['create', FOLDERS.websiteTheme.name]); expect( testState.existsInTestOutputDirectory(FOLDERS.websiteTheme.folder) ).toBe(true); }); it('react-app', async () => { - await testState.cli.execute(['create', 'react-app']); + await testState.cli.execute(['create', FOLDERS.reactApp.name]); expect(testState.existsInTestOutputDirectory(FOLDERS.reactApp.folder)).toBe( true ); }); it('vue-app', async () => { - await testState.cli.execute(['create', 'vue-app']); + await testState.cli.execute(['create', FOLDERS.vueApp.name]); expect(testState.existsInTestOutputDirectory(FOLDERS.vueApp.folder)).toBe( true ); }); it('webpack-serverless', async () => { - await testState.cli.execute(['create', 'webpack-serverless']); + await testState.cli.execute(['create', FOLDERS.webpackServerless.name]); expect( testState.existsInTestOutputDirectory(FOLDERS.webpackServerless.folder) ).toBe(true); }); - // For some reason, this test is getting tripped up on the creation. - // I verified it's just the test though, not the code, so - // instead we just check for some output to make sure the command runs it('api-sample', async () => { const out = await testState.cli.execute( - ['create', 'api-sample', 'api-sample'], + ['create', FOLDERS.apiSample.name, FOLDERS.apiSample.name], [ENTER, ENTER] ); - expect(out).toContain('node'); + + expect( + testState.existsInTestOutputDirectory(FOLDERS.apiSample.folder) + ).toBe(true); }); it('app', async () => { - await testState.cli.execute(['create', 'app']); + await testState.cli.execute(['create', FOLDERS.app.name]); expect(testState.existsInTestOutputDirectory(FOLDERS.app.folder)).toBe( true ); diff --git a/package.json b/package.json index 8686c53ef..2530a7933 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "test-cli": "yarn --cwd 'acceptance-tests' test-ci", "test-cli-debug": "yarn --cwd 'acceptance-tests' test-debug", "test-cli-qa": "yarn --cwd 'acceptance-tests' test-qa", - "test-docker": "yarn build-docker && docker container run -it --rm --name=hs-cli-container hs-cli-image yarn test", + "test-cli-latest": "yarn build-docker && docker container run -it --rm --name=hs-cli-container hs-cli-image yarn test-cli", "build-docker": "docker image build --tag hs-cli-image . && docker image prune -f", "circular-deps": "yarn madge --circular packages" },