Skip to content

Commit eab9036

Browse files
authored
chore(gen2-migration): some QoL improvements (#14732)
fix(cli-internal): update snapshot docs and clean up compare side effect Update migration-apps README to reference renamed test files (generate.test.ts, refactor.test.ts), simplify snapshot update commands, and add a note about the two-pass update behavior. Remove the .actual.* copy side effect from Snapshot.compare() and add node_modules ignore pattern to Snapshot.update(). Add a completion log line to update(). --- Prompt: commit what i did
1 parent c48d878 commit eab9036

2 files changed

Lines changed: 14 additions & 15 deletions

File tree

  • amplify-migration-apps
  • packages/amplify-cli/src/__tests__/commands/gen2-migration/_framework

amplify-migration-apps/README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ are needed, and adding a new app automatically gets correct mocks without extra
283283
### Adding a Snapshot Test | `generate`
284284

285285
To add a snapshot test that validates the `gen2-migration generate` command for a new app,
286-
add a new test to [`command-handlers.test.ts`](../packages/amplify-cli/src/__tests__/commands/gen2-migration/generate/codegen-head/command-handlers.test.ts):
286+
add a new test to [`generate.test.ts`](../packages/amplify-cli/src/__tests__/commands/gen2-migration/generate.test.ts):
287287

288288
```typescript
289289
// For apps WITH Amplify Hosting:
@@ -312,8 +312,8 @@ test('<app-name> snapshot', async () => {
312312

313313
```console
314314
cd packages/amplify-cli
315-
npx jest --no-coverage src/__tests__/commands/gen2-migration/generate/codegen-head/command-handlers.test.ts -t '<app-name> snapshot'
316-
npx jest --no-coverage src/__tests__/commands/gen2-migration/refactor/refactor.test.ts -t '<app-name> snapshot'
315+
npx jest --no-coverage src/__tests__/commands/gen2-migration/generate.test.ts -t '<app-name> snapshot'
316+
npx jest --no-coverage src/__tests__/commands/gen2-migration/refactor.test.ts -t '<app-name> snapshot'
317317
```
318318

319319
The tests should pass with no differences. They could fail for two reasons:
@@ -333,14 +333,20 @@ When the migration tool code changes and you need to update expected snapshots:
333333
334334
```console
335335
cd packages/amplify-cli
336-
npx jest --no-coverage src/__tests__/commands/gen2-migration/generate/codegen-head/command-handlers.test.ts --updateSnapshot
336+
npx jest --no-coverage src/__tests__/commands/gen2-migration/generate.test.ts --updateSnapshot
337337
```
338338

339339
This updates all snapshots. You can also target a specific app:
340340

341341
```console
342-
npx jest --no-coverage src/__tests__/commands/gen2-migration/generate/codegen-head/command-handlers.test.ts \
343-
-t '<app-name> snapshot' --updateSnapshot
342+
npx jest --no-coverage src/__tests__/commands/gen2-migration/generate.test.ts -t '<app-name> snapshot' --updateSnapshot
344343
```
345344

346345
Always review the diff after updating to make sure the changes are intentional.
346+
347+
348+
> [!NOTE]
349+
> When updating snapshots, the first run with `--updateSnapshot` will still report a failure
350+
> because it detects the diff before writing the updated files. Run the tests a second time
351+
> (without `--updateSnapshot`) to verify the snapshots are now correct.
352+

packages/amplify-cli/src/__tests__/commands/gen2-migration/_framework/snapshot.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,6 @@ export class Snapshot {
8181
public async compare(actualDir: string, ignorePatterns?: RegExp[]): Promise<Report> {
8282
const fullIgnorePatterns = [...(ignorePatterns ?? []), /node_modules/];
8383
const differences = await diff({ expectedDir: this.props.expectedPath, actualDir, ignorePatterns: fullIgnorePatterns });
84-
85-
// copy the temporary actual path to repo (ignored) for easy manual comparison
86-
const ignoredActualPath = `${this.props.expectedPath}.actual.${Date.now()}`;
87-
if (fs.existsSync(ignoredActualPath)) {
88-
fs.rmSync(ignoredActualPath, { recursive: true, force: true });
89-
}
90-
copySync({ src: actualDir, dest: ignoredActualPath, ignorePatterns: fullIgnorePatterns });
91-
9284
return new Report({
9385
app: this.props.app,
9486
expectedPath: this.props.expectedPath,
@@ -109,6 +101,7 @@ export class Snapshot {
109101
public update(actualDir: string) {
110102
console.log(`Updating snapshot: ${this.props.expectedPath}`);
111103
fs.rmSync(this.props.expectedPath, { recursive: true });
112-
copySync({ src: actualDir, dest: this.props.expectedPath });
104+
copySync({ src: actualDir, dest: this.props.expectedPath, ignorePatterns: [/node_modules/] });
105+
console.log(`Finished updating snapshot: ${this.props.expectedPath}`);
113106
}
114107
}

0 commit comments

Comments
 (0)