Skip to content

Commit

Permalink
add e2e test project reset and add reset to hotswap retries (#2380)
Browse files Browse the repository at this point in the history
  • Loading branch information
rtpascual authored Dec 31, 2024
1 parent b1c0f0d commit 866bc76
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .changeset/stale-pianos-marry.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
Expand Up @@ -86,8 +86,12 @@ export const defineSandboxTest = (testProjectCreator: TestProjectCreator) => {
if (updates.length > 0) {
// retry hotswapping resources if deployment time is higher than the threshold
await runWithRetry(
async () => {
// keeping initial deployment in retry loop to reset app state for each hotswap to be a non no-op
async (attempt) => {
if (attempt > 1) {
// reset test project to pre-update state to retry hotswap
await testProject.reset();
}

const processController = ampxCli(
['sandbox', '--dirToWatch', 'amplify'],
testProject.projectDirPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import path from 'path';
import { AmplifyClient } from '@aws-sdk/client-amplify';
import { pathToFileURL } from 'url';
import isMatch from 'lodash.ismatch';
import { setupDirAsEsmModule } from './setup_dir_as_esm_module.js';

export type PlatformDeploymentThresholds = {
onWindows: number;
Expand Down Expand Up @@ -247,4 +248,15 @@ export abstract class TestProjectBase {

assert.ok(isMatch(currentCodebaseOutputs, npmOutputs));
}

/**
* Resets the project to its initial state
*/
async reset() {
await fsp.rm(this.projectAmplifyDirPath, { recursive: true, force: true });
await fsp.cp(this.sourceProjectAmplifyDirURL, this.projectAmplifyDirPath, {
recursive: true,
});
await setupDirAsEsmModule(this.projectAmplifyDirPath);
}
}

0 comments on commit 866bc76

Please sign in to comment.