Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: include sandbox in canary tests #612

Merged
merged 8 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/wet-tips-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Options, execa } from 'execa';
import { Options, execa, execaSync } from 'execa';
import readline from 'readline';
import { PredicatedActionBuilder } from './predicated_action_queue_builder.js';
import { ActionType } from './predicated_action.js';
Expand Down Expand Up @@ -117,16 +117,18 @@ export const amplifyCli = (
args: string[] = [],
dir: string,
options?: {
installationType?: 'global' | 'local';
env?: Record<string, string>;
}
): ProcessController => {
let command: string;
if (options?.installationType === 'local') {
command = 'npx';
args = ['amplify'].concat(args);
} else {
command = 'amplify';
// TODO This is a workaround to lookup locally installed binary as seen by npx
// We're using binary directly because signals (Ctrl+C) don't propagate
// to child processes without TTY emulator.
// See: https://github.com/aws-amplify/amplify-backend/issues/582
const command = execaSync('npx', ['which', 'amplify'], {
cwd: dir,
}).stdout.trim();
if (!command) {
throw new Error('Unable to locate amplify binary');
}
return new ProcessController(command, args, {
cwd: dir,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import {
CloudFormationClient,
DeleteStackCommand,
} from '@aws-sdk/client-cloudformation';
import {
confirmDeleteSandbox,
interruptSandbox,
rejectCleanupSandbox,
waitForSandboxDeploymentToPrintTotalTime,
} from '../process-controller/predicated_action_macros.js';

const cfnClient = new CloudFormationClient();

Expand All @@ -21,10 +27,7 @@ const cfnClient = new CloudFormationClient();
*
* These tests intentionally do not use local npm registry (verdaccio).
*/
void describe('Live dependency health checks', () => {
let tempDir: string;
let testBranch: TestBranch;

void describe('Live dependency health checks', { concurrency: true }, () => {
before(async () => {
// nuke the npx cache to ensure we are installing latest versions of packages from the npm
const { stdout } = await execa('npm', ['config', 'get', 'cache']);
Expand All @@ -35,50 +38,86 @@ void describe('Live dependency health checks', () => {
}
});

beforeEach(async () => {
tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'test-amplify'));
testBranch = await amplifyAppPool.createTestBranch();
});
void describe('pipeline deployment', () => {
let tempDir: string;
let testBranch: TestBranch;
Comment on lines +41 to +43
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enabling parallelization requires nesting of these variables

beforeEach(async () => {
tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'test-amplify'));
testBranch = await amplifyAppPool.createTestBranch();
});

afterEach(async () => {
await fs.rm(tempDir, { recursive: true });
const stackName = `amplify-${testBranch.appId}-${testBranch.branchName}`;
try {
await cfnClient.send(
new DeleteStackCommand({
StackName: stackName,
})
);
} catch (e) {
console.log(`Failed to delete ${stackName}`);
console.log(e);
}
});

void it('end to end flow', async () => {
await execa('npm', ['create', 'amplify', '--yes'], {
cwd: tempDir,
stdio: 'inherit',
});

await amplifyCli(
[
'pipeline-deploy',
'--branch',
testBranch.branchName,
'--appId',
testBranch.appId,
],
tempDir,
{
env: { CI: 'true' },
}
).run();

afterEach(async () => {
await fs.rm(tempDir, { recursive: true });
const stackName = `amplify-${testBranch.appId}-${testBranch.branchName}`;
try {
await cfnClient.send(
new DeleteStackCommand({
StackName: stackName,
})
const clientConfigStats = await fs.stat(
path.join(tempDir, 'amplifyconfiguration.json')
);
} catch (e) {
console.log(`Failed to delete ${stackName}`);
console.log(e);
}
assert.ok(clientConfigStats.isFile());
});
});

void it('end to end flow with pipeline deployment', async () => {
await execa('npm', ['create', 'amplify', '--yes'], {
cwd: tempDir,
stdio: 'inherit',
void describe('sandbox deployment', () => {
let tempDir: string;
beforeEach(async () => {
tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'test-amplify'));
});

await amplifyCli(
[
'pipeline-deploy',
'--branch',
testBranch.branchName,
'--appId',
testBranch.appId,
],
tempDir,
{
installationType: 'local',
env: { CI: 'true' },
}
).run();
afterEach(async () => {
await fs.rm(tempDir, { recursive: true });
});

void it('end to end flow', async () => {
await execa('npm', ['create', 'amplify', '--yes'], {
cwd: tempDir,
stdio: 'inherit',
});

const clientConfigStats = await fs.stat(
path.join(tempDir, 'amplifyconfiguration.json')
);
assert.ok(clientConfigStats.isFile());
await amplifyCli(['sandbox'], tempDir)
.do(waitForSandboxDeploymentToPrintTotalTime())
.do(interruptSandbox())
.do(rejectCleanupSandbox())
.run();

const clientConfigStats = await fs.stat(
path.join(tempDir, 'amplifyconfiguration.json')
);
assert.ok(clientConfigStats.isFile());

await amplifyCli(['sandbox', 'delete'], tempDir)
.do(confirmDeleteSandbox())
.run();
});
});
});
Loading