Skip to content

Commit 9dcd092

Browse files
authored
add cleanup of generated env files to end of tests (#2234)
1 parent f57a758 commit 9dcd092

File tree

6 files changed

+54
-5
lines changed

6 files changed

+54
-5
lines changed

.changeset/ninety-trainers-flow.md

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

packages/backend-function/src/factory.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { beforeEach, describe, it, mock } from 'node:test';
1+
import { after, beforeEach, describe, it, mock } from 'node:test';
22
import { App, Stack } from 'aws-cdk-lib';
33
import {
44
ConstructFactoryGetInstanceProps,
@@ -17,6 +17,8 @@ import { NodeVersion, defineFunction } from './factory.js';
1717
import { lambdaWithDependencies } from './test-assets/lambda-with-dependencies/resource.js';
1818
import { Runtime } from 'aws-cdk-lib/aws-lambda';
1919
import { Policy, PolicyStatement } from 'aws-cdk-lib/aws-iam';
20+
import fsp from 'fs/promises';
21+
import path from 'node:path';
2022

2123
const createStackAndSetContext = (): Stack => {
2224
const app = new App();
@@ -52,6 +54,14 @@ void describe('AmplifyFunctionFactory', () => {
5254
};
5355
});
5456

57+
after(async () => {
58+
// clean up generated env files
59+
await fsp.rm(path.join(process.cwd(), '.amplify'), {
60+
recursive: true,
61+
force: true,
62+
});
63+
});
64+
5565
void it('creates singleton function instance', () => {
5666
const functionFactory = defaultLambda;
5767
const instance1 = functionFactory.getInstance(getInstanceProps);

packages/backend-function/src/function_env_translator.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Construct } from 'constructs';
2-
import { describe, it } from 'node:test';
2+
import { after, describe, it } from 'node:test';
33
import { FunctionEnvironmentTranslator } from './function_env_translator.js';
44
import {
55
BackendIdentifier,
@@ -13,6 +13,8 @@ import { ParameterPathConversions } from '@aws-amplify/platform-core';
1313
import { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda';
1414
import { Template } from 'aws-cdk-lib/assertions';
1515
import { FunctionEnvironmentTypeGenerator } from './function_env_type_generator.js';
16+
import path from 'node:path';
17+
import fsp from 'fs/promises';
1618

1719
const testStack = {} as Construct;
1820

@@ -55,6 +57,14 @@ class TestBackendSecret implements BackendSecret {
5557
void describe('FunctionEnvironmentTranslator', () => {
5658
const backendResolver = new TestBackendSecretResolver();
5759

60+
after(async () => {
61+
// clean up generated env files
62+
await fsp.rm(path.join(process.cwd(), '.amplify'), {
63+
recursive: true,
64+
force: true,
65+
});
66+
});
67+
5868
void it('translates env props that do not contain secrets', () => {
5969
const functionEnvProp = {
6070
TEST_VAR: 'testValue',

packages/backend-function/src/function_env_type_generator.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1-
import { describe, it, mock } from 'node:test';
1+
import { after, describe, it, mock } from 'node:test';
22
import fs from 'fs';
33
import fsp from 'fs/promises';
44
import { FunctionEnvironmentTypeGenerator } from './function_env_type_generator.js';
55
import assert from 'assert';
66
import { pathToFileURL } from 'url';
7+
import path from 'path';
78

89
void describe('FunctionEnvironmentTypeGenerator', () => {
10+
after(async () => {
11+
// clean up generated env files
12+
await fsp.rm(path.join(process.cwd(), '.amplify'), {
13+
recursive: true,
14+
force: true,
15+
});
16+
});
17+
918
void it('generates a type definition file', () => {
1019
const fsOpenSyncMock = mock.method(fs, 'openSync');
1120
const fsWriteFileSyncMock = mock.method(fs, 'writeFileSync', () => null);

packages/backend-function/src/layer_parser.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import {
1212
import { App, Stack } from 'aws-cdk-lib';
1313
import { Template } from 'aws-cdk-lib/assertions';
1414
import assert from 'node:assert';
15-
import { beforeEach, describe, it } from 'node:test';
15+
import { after, beforeEach, describe, it } from 'node:test';
1616
import { defineFunction } from './factory.js';
17+
import path from 'node:path';
18+
import fsp from 'fs/promises';
1719

1820
const createStackAndSetContext = (): Stack => {
1921
const app = new App();
@@ -49,6 +51,14 @@ void describe('AmplifyFunctionFactory - Layers', () => {
4951
};
5052
});
5153

54+
after(async () => {
55+
// clean up generated env files
56+
await fsp.rm(path.join(process.cwd(), '.amplify'), {
57+
recursive: true,
58+
force: true,
59+
});
60+
});
61+
5262
void it('sets a valid layer', () => {
5363
const layerArn = 'arn:aws:lambda:us-east-1:123456789012:layer:my-layer:1';
5464
const functionFactory = defineFunction({

packages/integration-tests/src/test-in-memory/data_storage_auth_with_triggers.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {
44
synthesizeBackendTemplates,
55
} from '../define_backend_template_harness.js';
66
import { dataStorageAuthWithTriggers } from '../test-projects/data-storage-auth-with-triggers-ts/amplify/test_factories.js';
7+
import path from 'node:path';
8+
import fsp from 'fs/promises';
79

810
/**
911
* This test suite is meant to provide a fast feedback loop to sanity check that different feature verticals are working properly together.
@@ -12,7 +14,7 @@ import { dataStorageAuthWithTriggers } from '../test-projects/data-storage-auth-
1214
* Critical path interactions should be exercised in a full e2e test.
1315
*/
1416

15-
void it('data storage auth with triggers', () => {
17+
void it('data storage auth with triggers', async () => {
1618
const templates = synthesizeBackendTemplates(dataStorageAuthWithTriggers);
1719

1820
assertExpectedLogicalIds(templates.root, 'AWS::CloudFormation::Stack', [
@@ -58,4 +60,10 @@ void it('data storage auth with triggers', () => {
5860
'onDeletelambda96BB6F15',
5961
]);
6062
/* eslint-enable spellcheck/spell-checker */
63+
64+
// clean up generated env files
65+
await fsp.rm(path.join(process.cwd(), '.amplify'), {
66+
recursive: true,
67+
force: true,
68+
});
6169
});

0 commit comments

Comments
 (0)