Skip to content

Commit

Permalink
fix: Fix tests running on latest (#1199)
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-yeager authored Oct 9, 2024
1 parent bca108b commit a503215
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 38 deletions.
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
node_modules
.github
.vscode
coverage
docs
tmp
.eslintignore
.eslintrc.js
.gitignore
*.md
jest.config.js
lerna.json
prettier.config.js
9 changes: 3 additions & 6 deletions .github/workflows/latestPublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ on:
schedule:
- cron: '0 */5 * * *' # Run every 5 hours

env:
version: "latest"

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -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
Expand Down
13 changes: 11 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 12 additions & 6 deletions acceptance-tests/globalSetup.ts
Original file line number Diff line number Diff line change
@@ -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)
}
Expand Down
9 changes: 3 additions & 6 deletions acceptance-tests/lib/cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
8 changes: 4 additions & 4 deletions acceptance-tests/lib/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion acceptance-tests/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export interface TestConfig {
debug: boolean;
cliVersion: string;
useInstalled: boolean;
cliPath: string;
personalAccessKey: string;
portalId: string;
Expand Down
1 change: 0 additions & 1 deletion acceptance-tests/tests/auth.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { existsSync } from 'fs';
import { describe, beforeAll, it, expect, afterAll } from 'vitest';
import { ENTER } from '../lib/prompt';

Expand Down
26 changes: 15 additions & 11 deletions acceptance-tests/tests/create.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -16,22 +15,27 @@ 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',
folder: 'api-sample',
},
app: {
folder: 'app',
name: 'app',
},
function: {
folder: 'function.functions',
Expand Down Expand Up @@ -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
);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down

0 comments on commit a503215

Please sign in to comment.