Skip to content

Commit

Permalink
PR upadtes
Browse files Browse the repository at this point in the history
  • Loading branch information
Amplifiyer committed Oct 12, 2023
1 parent 967f7a9 commit 7706134
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ExecaChildProcess } from 'execa';
*/
export enum ActionType {
SEND_INPUT_TO_PROCESS,
MAKE_CODE_CHANGES,
UPDATE_FILE_CONTENT,
ASSERT_ON_PROCESS_OUTPUT,
KILL_PROCESS,
}
Expand All @@ -18,8 +18,8 @@ type KillProcess = {
actionType: ActionType.KILL_PROCESS;
action: (execaProcess: ExecaChildProcess<string>) => Promise<void>;
};
type MakeCodeChangesAction = {
actionType: ActionType.MAKE_CODE_CHANGES;
type UpdateFileContentAction = {
actionType: ActionType.UPDATE_FILE_CONTENT;
action: () => Promise<void>;
};
type AssertOnProcessOutputAction = {
Expand All @@ -30,7 +30,7 @@ type AssertOnProcessOutputAction = {
export type Action =
| SendInputToProcessAction
| KillProcess
| MakeCodeChangesAction
| UpdateFileContentAction
| AssertOnProcessOutputAction;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { PredicatedActionBuilder } from './predicated_action_queue_builder.js';
/**
* Reusable predicates: Wait for sandbox to finish and emit "✨ Total time: xx.xxs"
*/
export const waitForSandboxDeployment = () =>
export const waitForSandboxDeploymentToPrintTotalTime = () =>
new PredicatedActionBuilder().waitForLineIncludes('Total time');

/**
Expand Down Expand Up @@ -44,8 +44,8 @@ export const rejectCleanupSandbox = () =>
* Reusable predicated action: Wait for sandbox to become idle and then update the
* backend code which should trigger sandbox again
*/
export const updateBackendCode = (from: URL, to: URL) => {
return waitForSandboxToBecomeIdle().updateBackendCode(from, to);
export const updateFileContent = (from: URL, to: URL) => {
return waitForSandboxToBecomeIdle().updateFileContent(from, to);
};

/**
Expand All @@ -58,5 +58,7 @@ export const interruptSandbox = () => waitForSandboxToBecomeIdle().sendCtrlC();
* than the threshold.
*/
export const ensureDeploymentTimeLessThan = (seconds: number) => {
return waitForSandboxDeployment().ensureDeploymentTimeLessThan(seconds);
return waitForSandboxDeploymentToPrintTotalTime().ensureDeploymentTimeLessThan(
seconds
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import os from 'os';
import fs from 'fs/promises';

import { killExecaProcess } from './execa_process_manager.js';
import { killExecaProcess } from './execa_process_killer.js';
import { ExecaChildProcess } from 'execa';

export const CONTROL_C = '\x03';
Expand Down Expand Up @@ -68,9 +68,9 @@ export class PredicatedActionBuilder {
* Update the last predicated action to update backend code by copying files from
* `from` location to `to` location.
*/
updateBackendCode = (from: URL, to: URL) => {
updateFileContent = (from: URL, to: URL) => {
this.getLastPredicatedAction().then = {
actionType: ActionType.MAKE_CODE_CHANGES,
actionType: ActionType.UPDATE_FILE_CONTENT,
action: async () => {
await fs.cp(from, to, {
recursive: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Options, execa } from 'execa';
import readline from 'readline';
import { PredicatedActionBuilder } from './predicated_action_queue_builder.js';
import { ActionType } from './predicated_action.js';
import { killExecaProcess } from './execa_process_manager.js';
import { killExecaProcess } from './execa_process_killer.js';
/**
* Provides an abstractions for sending and receiving data on stdin/out of a child process
*
Expand Down Expand Up @@ -79,7 +79,7 @@ export class ProcessController {
expectKilled = true;
await currentInteraction.then.action(execaProcess);
break;
case ActionType.MAKE_CODE_CHANGES:
case ActionType.UPDATE_FILE_CONTENT:
await currentInteraction.then.action();
break;
case ActionType.ASSERT_ON_PROCESS_OUTPUT:
Expand Down
10 changes: 5 additions & 5 deletions packages/integration-tests/src/test-e2e/deployment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
ensureDeploymentTimeLessThan,
interruptSandbox,
rejectCleanupSandbox,
updateBackendCode,
waitForSandboxDeployment,
updateFileContent,
waitForSandboxDeploymentToPrintTotalTime,
} from '../process-controller/predicated_action_macros.js';
import { createEmptyAmplifyProject } from '../create_empty_amplify_project.js';
import {
Expand Down Expand Up @@ -91,7 +91,7 @@ void describe('amplify deploys', () => {
});

await amplifyCli(['sandbox'], testProjectRoot)
.do(waitForSandboxDeployment())
.do(waitForSandboxDeploymentToPrintTotalTime())
.do(interruptSandbox())
.do(rejectCleanupSandbox())
.run();
Expand All @@ -109,7 +109,7 @@ void describe('amplify deploys', () => {
const processController = amplifyCli(
['sandbox', '--dirToWatch', 'amplify'],
testProjectRoot
).do(waitForSandboxDeployment());
).do(waitForSandboxDeploymentToPrintTotalTime());

for (const update of testProject.updates) {
const fileToUpdate = pathToFileURL(
Expand All @@ -120,7 +120,7 @@ void describe('amplify deploys', () => {
);

processController
.do(updateBackendCode(fileToUpdate, updateSource))
.do(updateFileContent(fileToUpdate, updateSource))
.do(
ensureDeploymentTimeLessThan(update.deploymentThresholdInSeconds)
);
Expand Down

0 comments on commit 7706134

Please sign in to comment.