Skip to content

Commit 866bc76

Browse files
authored
add e2e test project reset and add reset to hotswap retries (#2380)
1 parent b1c0f0d commit 866bc76

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

.changeset/stale-pianos-marry.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

packages/integration-tests/src/test-e2e/sandbox/sandbox.test.template.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,12 @@ export const defineSandboxTest = (testProjectCreator: TestProjectCreator) => {
8686
if (updates.length > 0) {
8787
// retry hotswapping resources if deployment time is higher than the threshold
8888
await runWithRetry(
89-
async () => {
90-
// keeping initial deployment in retry loop to reset app state for each hotswap to be a non no-op
89+
async (attempt) => {
90+
if (attempt > 1) {
91+
// reset test project to pre-update state to retry hotswap
92+
await testProject.reset();
93+
}
94+
9195
const processController = ampxCli(
9296
['sandbox', '--dirToWatch', 'amplify'],
9397
testProject.projectDirPath,

packages/integration-tests/src/test-project-setup/test_project_base.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import path from 'path';
2626
import { AmplifyClient } from '@aws-sdk/client-amplify';
2727
import { pathToFileURL } from 'url';
2828
import isMatch from 'lodash.ismatch';
29+
import { setupDirAsEsmModule } from './setup_dir_as_esm_module.js';
2930

3031
export type PlatformDeploymentThresholds = {
3132
onWindows: number;
@@ -247,4 +248,15 @@ export abstract class TestProjectBase {
247248

248249
assert.ok(isMatch(currentCodebaseOutputs, npmOutputs));
249250
}
251+
252+
/**
253+
* Resets the project to its initial state
254+
*/
255+
async reset() {
256+
await fsp.rm(this.projectAmplifyDirPath, { recursive: true, force: true });
257+
await fsp.cp(this.sourceProjectAmplifyDirURL, this.projectAmplifyDirPath, {
258+
recursive: true,
259+
});
260+
await setupDirAsEsmModule(this.projectAmplifyDirPath);
261+
}
250262
}

0 commit comments

Comments
 (0)