Skip to content

Commit

Permalink
renaming things
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardfoyle committed Sep 6, 2023
1 parent 0e5173b commit 3f0d9eb
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 29 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
"passthrough",
"pathname",
"readdir",
"readline",
"readonly",
"repo",
"resolvers",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Contains a predicate that the process controller should wait for, then strings that should be sent after the predicate matches
*/
export type ControllerAction = {
predicate: (line: string) => boolean;
thenSend: string[];
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LineActionQueueBuilder } from './line_action_queue_builder.js';
import { ControllerActionQueueBuilder } from './controller_action_queue_builder.js';

export const CONTROL_C = '\x03';

Expand All @@ -7,21 +7,21 @@ export const CONTROL_C = '\x03';
* By composing flows from reusable macros we will hopefully avoid the situation in the classic CLI E2E tests where changing one CLI prompt requires updates to 97742 different E2E prompts
*/

export const confirmDeleteSandbox = new LineActionQueueBuilder()
export const confirmDeleteSandbox = new ControllerActionQueueBuilder()
.waitForLineIncludes(
'Are you sure you want to delete all the resources in your sandbox environment'
)
.sendYes();

export const rejectCleanupSandbox = new LineActionQueueBuilder()
export const rejectCleanupSandbox = new ControllerActionQueueBuilder()
.waitForLineIncludes(
'Would you like to delete all the resources in your sandbox environment'
)
.sendNo();

export const waitForSandboxDeployment =
new LineActionQueueBuilder().waitForLineIncludes('Total time');
new ControllerActionQueueBuilder().waitForLineIncludes('Total time');

export const interruptSandbox = new LineActionQueueBuilder()
export const interruptSandbox = new ControllerActionQueueBuilder()
.waitForLineIncludes('[Sandbox] Watching for file changes')
.sendCtrlC();
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { LineAction } from './expected_line_action.js';
import { ControllerAction } from './controller_action.js';
import os from 'os';
import { CONTROL_C } from './command_macros.js';
import { CONTROL_C } from './controller_action_macros.js';

/**
* Builder for a queue of LineActions
*/
export class LineActionQueueBuilder {
private readonly lineActionQueue: LineAction[] = [];
export class ControllerActionQueueBuilder {
private readonly controllerActionQueue: ControllerAction[] = [];

/**
* Append the action queue from another builder to this builder
*/
append = (builder: LineActionQueueBuilder) => {
this.lineActionQueue.push(...builder.getLineActionQueue());
append = (builder: ControllerActionQueueBuilder) => {
this.controllerActionQueue.push(...builder.getLineActionQueue());
return this;
};

/**
* Add a new action to the queue to wait for a line that includes str
*/
waitForLineIncludes = (str: string) => {
this.lineActionQueue.push({
this.controllerActionQueue.push({
predicate: (line) => line.includes(str),
thenSend: [],
});
Expand All @@ -31,10 +31,10 @@ export class LineActionQueueBuilder {
* Send str with no newline
*/
send = (str: string) => {
if (this.lineActionQueue.length === 0) {
if (this.controllerActionQueue.length === 0) {
throw new Error('Must wait for a line before sending');
}
this.lineActionQueue.at(-1)?.thenSend.push(str);
this.controllerActionQueue.at(-1)?.thenSend.push(str);
return this;
};

Expand Down Expand Up @@ -73,7 +73,7 @@ export class LineActionQueueBuilder {
/**
* Get the currently queued actions
*/
getLineActionQueue = (): LineAction[] => {
return this.lineActionQueue;
getLineActionQueue = (): ControllerAction[] => {
return this.controllerActionQueue;
};
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Options, execa } from 'execa';
import readline from 'readline';
import { CONTROL_C } from './command_macros.js';
import { LineActionQueueBuilder } from './line_action_queue_builder.js';
import { CONTROL_C } from './controller_action_macros.js';
import { ControllerActionQueueBuilder } from './controller_action_queue_builder.js';

/**
* Provides an abstractions for sending and receiving data on stdin/out of a child process
Expand All @@ -17,8 +17,8 @@ import { LineActionQueueBuilder } from './line_action_queue_builder.js';
* then send "yes" on stdin of the process
*/
export class ProcessController {
private readonly actions: LineActionQueueBuilder =
new LineActionQueueBuilder();
private readonly actions: ControllerActionQueueBuilder =
new ControllerActionQueueBuilder();
/**
* Private ctor that initializes a readline interface around the execa process
*/
Expand All @@ -28,7 +28,7 @@ export class ProcessController {
private readonly options?: Pick<Options, 'cwd'>
) {}

do = (actions: LineActionQueueBuilder) => {
do = (actions: ControllerActionQueueBuilder) => {
this.actions.append(actions);
return this;
};
Expand Down
2 changes: 1 addition & 1 deletion packages/integration-tests/src/test-e2e/sandbox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
interruptSandbox,
rejectCleanupSandbox,
waitForSandboxDeployment,
} from '../process-controller/command_macros.js';
} from '../process-controller/controller_action_macros.js';
import { createEmptyAmplifyProject } from '../create_empty_amplify_project.js';
import {
createTestDirectoryBeforeAndCleanupAfter,
Expand Down

0 comments on commit 3f0d9eb

Please sign in to comment.