Skip to content

Commit

Permalink
Merge pull request #1315 from HubSpot/next
Browse files Browse the repository at this point in the history
Next branch changes
  • Loading branch information
brandenrodgers authored Jan 7, 2025
2 parents 41797ee + 99b9b37 commit 9735bca
Show file tree
Hide file tree
Showing 175 changed files with 6,322 additions and 4,809 deletions.
2 changes: 1 addition & 1 deletion acceptance-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This project tests our CLI's `hs <*>` commands as if they were being used by an

The main test execution is kicked off by running `yarn test-cli` from the root of `hubspot-cli`. This will run the test suites defined in the `tests` directory.

Note that if you are testing against a QA portal, not a PROD one, you'll need to run `yarn test-qa`. There is still an outstanding issue with this because we attempt to add the `--qa` flag to all `hs` commands, however it is not available for all commands.
Note that if you are testing against a QA account, not a PROD one, you'll need to run `yarn test-qa`. There is still an outstanding issue with this because we attempt to add the `--qa` flag to all `hs` commands, however it is not available for all commands.

### Setup

Expand Down
2 changes: 1 addition & 1 deletion acceptance-tests/lib/TestState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class TestState {
async initializeAuth() {
try {
await this.cli.executeWithTestConfig(
['init'],
['init', '--disable-tracking'],
getInitPromptSequence(this.getPAK())
);

Expand Down
19 changes: 9 additions & 10 deletions acceptance-tests/lib/cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function executeWithInput(
const { env, timeout = 1000, maxTimeout = 30000 } = opts;

const childProcess = createProcess(config, args, env);
childProcess.stdin.setEncoding('utf-8');
childProcess.stdin!.setEncoding('utf-8');

let currentInputTimeout: NodeJS.Timeout;
let killIOTimeout: NodeJS.Timeout;
Expand All @@ -78,7 +78,7 @@ function executeWithInput(
}

if (!inputs.length) {
childProcess.stdin.end();
childProcess.stdin!.end();

// Set a timeout to wait for CLI response. If CLI takes longer than
// maxTimeout to respond, kill the childProcess and notify user
Expand All @@ -94,7 +94,7 @@ function executeWithInput(
if (typeof inputs[0] === 'function') {
await inputs[0]();
} else {
childProcess.stdin.write(inputs[0]);
childProcess.stdin!.write(inputs[0]);
}

if (config.debug) {
Expand All @@ -106,14 +106,14 @@ function executeWithInput(
};

// Get errors from CLI for debugging
childProcess.stderr.on('data', (err: unknown) => {
childProcess.stderr!.on('data', (err: unknown) => {
if (config.debug) {
console.log('error:', String(err));
}
});

// Get output from CLI for debugging
childProcess.stdout.on('data', (data: unknown) => {
childProcess.stdout!.on('data', (data: unknown) => {
if (config.debug) {
console.log('output:', String(data));
}
Expand All @@ -123,7 +123,6 @@ function executeWithInput(
const handleStderr = (err: unknown) => {
// Ignore any allowed errors so tests can continue
const allowedErrors = [
'DeprecationWarning', // Ignore package deprecation warnings.
'[WARNING]', // Ignore our own CLI warning messages
];

Expand All @@ -134,12 +133,12 @@ function executeWithInput(
}

// Resubscribe if we ignored this error
childProcess.stderr.once('data', handleStderr);
childProcess.stderr!.once('data', handleStderr);
return;
}

// If the childProcess errors out, stop all the pending inputs
childProcess.stdin.end();
childProcess.stdin!.end();

if (currentInputTimeout) {
clearTimeout(currentInputTimeout);
Expand All @@ -149,10 +148,10 @@ function executeWithInput(
reject(error);
};

childProcess.stderr.once('data', handleStderr);
childProcess.stderr!.once('data', handleStderr);
childProcess.on('error', reject);

childProcess.stdout.pipe(
childProcess.stdout!.pipe(
concat((result: unknown) => {
if (killIOTimeout) {
clearTimeout(killIOTimeout);
Expand Down
4 changes: 2 additions & 2 deletions acceptance-tests/tests/commands/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ describe('hs config', () => {
});

describe('hs config set', () => {
it('should set the default mode to draft', async () => {
it('should set the default CMS publish mode to draft', async () => {
await testState.cli.executeWithTestConfig(
['config', 'set'],
[ENTER, DOWN, ENTER]
);

const parsedConfig = testState.getParsedConfig();

expect(parsedConfig.defaultMode).toEqual('draft');
expect(parsedConfig.defaultCmsPublishMode).toEqual('draft');
});
});
});
29 changes: 19 additions & 10 deletions acceptance-tests/tests/commands/create.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ describe('hs create', () => {
});

it('creates a module', async () => {
await testState.cli.execute(
await testState.cli.executeWithTestConfig(
['create', 'module', FOLDERS.module.name],
['label', ENTER, ENTER, ENTER, 'y', ENTER]
['label', ENTER, ENTER, ENTER, 'y', ENTER, ENTER]
);

expect(testState.existsInTestOutputDirectory(FOLDERS.module.folder)).toBe(
Expand All @@ -80,7 +80,7 @@ describe('hs create', () => {
});

it('creates a template', async () => {
await testState.cli.execute(
await testState.cli.executeWithTestConfig(
['create', 'template', FOLDERS.template.name],
[ENTER]
);
Expand All @@ -90,35 +90,44 @@ describe('hs create', () => {
});

it('website-theme', async () => {
await testState.cli.execute(['create', FOLDERS.websiteTheme.name]);
await testState.cli.executeWithTestConfig([
'create',
FOLDERS.websiteTheme.name,
]);
expect(
testState.existsInTestOutputDirectory(FOLDERS.websiteTheme.folder)
).toBe(true);
});

it('react-app', async () => {
await testState.cli.execute(['create', FOLDERS.reactApp.name]);
await testState.cli.executeWithTestConfig([
'create',
FOLDERS.reactApp.name,
]);
expect(testState.existsInTestOutputDirectory(FOLDERS.reactApp.folder)).toBe(
true
);
});

it('vue-app', async () => {
await testState.cli.execute(['create', FOLDERS.vueApp.name]);
await testState.cli.executeWithTestConfig(['create', FOLDERS.vueApp.name]);
expect(testState.existsInTestOutputDirectory(FOLDERS.vueApp.folder)).toBe(
true
);
});

it('webpack-serverless', async () => {
await testState.cli.execute(['create', FOLDERS.webpackServerless.name]);
await testState.cli.executeWithTestConfig([
'create',
FOLDERS.webpackServerless.name,
]);
expect(
testState.existsInTestOutputDirectory(FOLDERS.webpackServerless.folder)
).toBe(true);
});

it('api-sample', async () => {
await testState.cli.execute(
await testState.cli.executeWithTestConfig(
['create', FOLDERS.apiSample.name, FOLDERS.apiSample.name],
[ENTER, ENTER]
);
Expand All @@ -129,14 +138,14 @@ describe('hs create', () => {
});

it('app', async () => {
await testState.cli.execute(['create', FOLDERS.app.name]);
await testState.cli.executeWithTestConfig(['create', FOLDERS.app.name]);
expect(testState.existsInTestOutputDirectory(FOLDERS.app.folder)).toBe(
true
);
});

it('function', async () => {
await testState.cli.execute(
await testState.cli.executeWithTestConfig(
['create', 'function'],
[
FOLDERS.function.name,
Expand Down
36 changes: 36 additions & 0 deletions acceptance-tests/tests/commands/hs.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { describe, beforeAll, it, expect, afterAll } from 'vitest';
import { TestState } from '../../lib/TestState';

describe('hs', () => {
let testState: TestState;

beforeAll(async () => {
testState = new TestState();
});

afterAll(() => {
testState.cleanup();
});

describe('hs', () => {
it('should log out the help message', async () => {
const output = await testState.cli.executeWithTestConfig([]);

expect(output).toContain(
'The command line interface to interact with HubSpot'
);
});

it('should log out the help message when --help is passed', async () => {
const output = await testState.cli.executeWithTestConfig(['--help']);

expect(output).toContain(
'The command line interface to interact with HubSpot'
);
});

it('should not throw when --version is passed', async () => {
await testState.cli.executeWithTestConfig(['--version']);
});
});
});
2 changes: 1 addition & 1 deletion acceptance-tests/tests/commands/projectCreate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('hs project create', () => {
'project',
'create',
`--name="${PROJECT_FOLDER}"`,
`--location="${PROJECT_FOLDER}"`,
`--dest="${PROJECT_FOLDER}"`,
'--template="getting-started-private-app"',
]);
expect(testState.existsInTestOutputDirectory(PROJECT_FOLDER)).toBe(true);
Expand Down
13 changes: 6 additions & 7 deletions acceptance-tests/tests/workflows/accountManagementFlow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Account Management Flow', () => {
describe('hs init', () => {
it('should generate a config file', async () => {
await testState.cli.executeWithTestConfig(
['init'],
['init', '--disable-tracking'],
getInitPromptSequence(testState.getPAK(), accountName)
);

Expand Down Expand Up @@ -73,12 +73,11 @@ describe('Account Management Flow', () => {

describe('hs accounts list', () => {
it('should not list the removed authenticated account', async () => {
const output = await testState.cli.executeWithTestConfig([
'accounts',
'list',
]);

expect(output).not.toContain(accountName);
await expect(() =>
testState.cli.executeWithTestConfig(['accounts', 'list'])
).rejects.toThrow(
/There are no accounts defined in the configuration file/
);
});
});

Expand Down
2 changes: 1 addition & 1 deletion acceptance-tests/tests/workflows/cmsTemplateFlow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('CMS Template Flow', () => {

describe('hs create', () => {
it('should create a CMS template', async () => {
await testState.cli.execute(
await testState.cli.executeWithTestConfig(
['create', 'template', TEMPLATE_NAME],
[ENTER]
);
Expand Down
52 changes: 29 additions & 23 deletions acceptance-tests/tests/workflows/secretsFlow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ const SECRET = {
value: 'an initial secret value',
};

const secretPollingOptions = {
interval: 5000,
timeout: 60000,
};

async function waitForSecretsListToContainSecret(testState: TestState) {
await expect
.poll(
() => testState.cli.executeWithTestConfig(['secrets', 'list']),
secretPollingOptions
)
.toContain(SECRET.name);
}

describe('Secrets Flow', () => {
let testState: TestState;

Expand All @@ -29,22 +43,16 @@ describe('Secrets Flow', () => {
['secrets', 'add', SECRET.name],
[SECRET.value, ENTER]
);
});
});

describe('hs secrets list', () => {
it('should list the secret', async () => {
await expect
.poll(() => testState.cli.executeWithTestConfig(['secrets', 'list']), {
interval: 1000,
timeout: 10000,
})
.toContain(SECRET.name);
await waitForSecretsListToContainSecret(testState);
});
});

describe('hs secrets update', () => {
it('should update the existing secret', async () => {
// Wait for the secret to exist before updating it
await waitForSecretsListToContainSecret(testState);

await testState.cli.executeWithTestConfig(
['secrets', 'update', SECRET.name],
['a different secret value', ENTER]
Expand All @@ -54,21 +62,19 @@ describe('Secrets Flow', () => {

describe('hs secrets delete', () => {
it('should delete the secret', async () => {
await testState.cli.executeWithTestConfig([
'secrets',
'delete',
SECRET.name,
]);
});
});
// Wait for the secret to exist before deleting it
await waitForSecretsListToContainSecret(testState);

await testState.cli.executeWithTestConfig(
['secrets', 'delete', SECRET.name],
['Y', ENTER]
);

describe('hs secrets list', () => {
it('should not list the secret', async () => {
await expect
.poll(() => testState.cli.executeWithTestConfig(['secrets', 'list']), {
interval: 1000,
timeout: 10000,
})
.poll(
() => testState.cli.executeWithTestConfig(['secrets', 'list']),
secretPollingOptions
)
.not.toContain(SECRET.name);
});
});
Expand Down
Loading

0 comments on commit 9735bca

Please sign in to comment.