Skip to content

Commit d78e4de

Browse files
authored
chore: update nexpect to latest (#831)
* chore: update nexpect to latest * fix: lint rules * fix: revert build spec change * fix: replace with regex * test: add log * fix: amplify configure * fix: nexpect uses correct CLI path * fix: add initial delay * fix: return * fix: remove debug log
1 parent 5eb0aa8 commit d78e4de

File tree

4 files changed

+423
-303
lines changed

4 files changed

+423
-303
lines changed

packages/amplify-codegen-e2e-core/src/asciinema-recorder.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export type RecordingHeader = {
99
title: string;
1010
env: any;
1111
};
12+
1213
export type RecordingFrame = [number, 'o' | 'i', string];
1314
export type Recording = {
1415
header: RecordingHeader;
@@ -17,13 +18,21 @@ export type Recording = {
1718

1819
export class Recorder {
1920
private isPaused: boolean = false;
21+
2022
private childProcess: pty.IPty;
23+
2124
private onDataHandlers: ((data: string) => void)[] = [];
25+
2226
private onExitHandlers: ((exitCode: number, signal: string | number) => void)[] = [];
27+
2328
private startTime: number;
29+
2430
private recording: Recording;
31+
2532
private cwd: string;
33+
2634
private exitCode: number | undefined;
35+
2736
constructor(
2837
private cmd: string,
2938
private args: string[],
@@ -41,7 +50,7 @@ export class Recorder {
4150
height: rows,
4251
timestamp: null,
4352
title: 'Recording',
44-
env: options,
53+
env: {},
4554
},
4655
frames: [],
4756
};
@@ -57,6 +66,9 @@ export class Recorder {
5766
cols: this.cols,
5867
rows: this.rows,
5968
cwd: this.cwd,
69+
shell: true,
70+
// Do not set useConpty. node-pty is smart enough to set it to true only on versions of Windows that support it.
71+
// useConpty: true,
6072
...this.options,
6173
});
6274
this.addFrame(this.renderPrompt(this.cwd, this.cmd, this.args));
@@ -79,6 +91,7 @@ export class Recorder {
7991
addOnExitHandlers(fn: (code: number, signal: string | number) => void) {
8092
this.onExitHandlers.push(fn);
8193
}
94+
8295
removeOnExitHandlers(fn: (code: number, signal: string | number) => void): boolean {
8396
const idx = this.onExitHandlers.indexOf(fn);
8497
if (idx === -1) {
@@ -89,7 +102,11 @@ export class Recorder {
89102
}
90103

91104
getRecording(): string {
92-
return [JSON.stringify(this.recording.header), ...this.recording.frames.map(frame => JSON.stringify(frame))].join('\n');
105+
return [JSON.stringify(this.recording.header), ...this.recording.frames.map((frame) => JSON.stringify(frame))].join('\n');
106+
}
107+
108+
getRecordingFrames(): Readonly<RecordingFrame[]> {
109+
return [...this.recording.frames];
93110
}
94111

95112
pauseRecording(): void {

packages/amplify-codegen-e2e-core/src/configure/index.ts

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -56,40 +56,32 @@ const MANDATORY_PARAMS = ['accessKeyId', 'secretAccessKey', 'region'];
5656

5757
export function amplifyConfigure(settings: AmplifyConfiguration): Promise<void> {
5858
const s = { ...defaultSettings, ...settings };
59-
const missingParam = MANDATORY_PARAMS.filter(p => !Object.keys(s).includes(p));
59+
const missingParam = MANDATORY_PARAMS.filter((p) => !Object.keys(s).includes(p));
6060
if (missingParam.length) {
6161
throw new Error(`mandatory params ${missingParam.join(' ')} are missing`);
6262
}
6363

64-
return new Promise((resolve, reject) => {
65-
const chain = spawn(getCLIPath(), ['configure'], { stripColors: true })
66-
.wait('Sign in to your AWS administrator account:')
67-
.wait('Press Enter to continue')
68-
.sendCarriageReturn()
69-
.wait('Specify the AWS Region');
70-
71-
singleSelect(chain, s.region, amplifyRegions);
72-
73-
chain
74-
.wait('Press Enter to continue')
75-
.sendCarriageReturn()
76-
.wait('accessKeyId')
77-
.pauseRecording()
78-
.sendLine(s.accessKeyId)
79-
.wait('secretAccessKey')
80-
.sendLine(s.secretAccessKey)
81-
.resumeRecording()
82-
.wait('Profile Name:')
83-
.sendLine(s.profileName)
84-
.wait('Successfully set up the new user.')
85-
.run((err: Error) => {
86-
if (!err) {
87-
resolve();
88-
} else {
89-
reject(err);
90-
}
91-
});
92-
});
64+
const chain = spawn(getCLIPath(), ['configure'], { stripColors: true })
65+
.wait('Sign in to your AWS administrator account:')
66+
.wait('Press Enter to continue')
67+
.sendCarriageReturn()
68+
.wait('Specify the AWS Region');
69+
70+
singleSelect(chain, s.region, amplifyRegions);
71+
72+
return chain
73+
.wait('Press Enter to continue')
74+
.sendCarriageReturn()
75+
.wait('accessKeyId')
76+
.pauseRecording()
77+
.sendLine(s.accessKeyId)
78+
.wait('secretAccessKey')
79+
.sendLine(s.secretAccessKey)
80+
.resumeRecording()
81+
.wait('Profile Name:')
82+
.sendLine(s.profileName)
83+
.wait('Successfully set up the new user.')
84+
.runAsync();
9385
}
9486

9587
export function amplifyConfigureProject(settings: {

packages/amplify-codegen-e2e-core/src/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { spawnSync, execSync } from 'child_process';
55
import { v4 as uuid } from 'uuid';
66
import * as ini from 'ini';
77
import { pathManager } from '@aws-amplify/amplify-cli-core';
8-
import { getCommandPath } from './utils';
8+
import { getCommandPath, sleep } from './utils';
99

1010
export * from './configure/';
1111
export * from './init/';
@@ -70,6 +70,15 @@ export async function createNewProjectDir(
7070
} while (fs.existsSync(projectDir));
7171

7272
fs.ensureDirSync(projectDir);
73+
if (!process.env.SKIP_CREATE_PROJECT_DIR_INITIAL_DELAY) {
74+
// createProjectDir(..) is something that nearly every test uses
75+
// Commands like 'init' would collide with each other if they occurred too close to one another.
76+
// Especially for nexpect output waiting
77+
// This makes it a perfect candidate for staggering test start times
78+
const initialDelay = Math.floor(Math.random() * 180 * 1000); // between 0 to 3 min
79+
console.log(`Waiting for ${initialDelay} ms`);
80+
await sleep(initialDelay);
81+
}
7382
console.log(projectDir);
7483
return projectDir;
7584
}

0 commit comments

Comments
 (0)