Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add cleanup of generated env files to end of tests #2234

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/ninety-trainers-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
12 changes: 11 additions & 1 deletion packages/backend-function/src/factory.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { beforeEach, describe, it, mock } from 'node:test';
import { after, beforeEach, describe, it, mock } from 'node:test';
import { App, Stack } from 'aws-cdk-lib';
import {
ConstructFactoryGetInstanceProps,
Expand All @@ -17,6 +17,8 @@ import { NodeVersion, defineFunction } from './factory.js';
import { lambdaWithDependencies } from './test-assets/lambda-with-dependencies/resource.js';
import { Runtime } from 'aws-cdk-lib/aws-lambda';
import { Policy, PolicyStatement } from 'aws-cdk-lib/aws-iam';
import fsp from 'fs/promises';
import path from 'node:path';

const createStackAndSetContext = (): Stack => {
const app = new App();
Expand Down Expand Up @@ -52,6 +54,14 @@ void describe('AmplifyFunctionFactory', () => {
};
});

after(async () => {
// clean up generated env files
await fsp.rm(path.join(process.cwd(), '.amplify'), {
recursive: true,
force: true,
});
});

void it('creates singleton function instance', () => {
const functionFactory = defaultLambda;
const instance1 = functionFactory.getInstance(getInstanceProps);
Expand Down
12 changes: 11 additions & 1 deletion packages/backend-function/src/function_env_translator.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Construct } from 'constructs';
import { describe, it } from 'node:test';
import { after, describe, it } from 'node:test';
import { FunctionEnvironmentTranslator } from './function_env_translator.js';
import {
BackendIdentifier,
Expand All @@ -13,6 +13,8 @@ import { ParameterPathConversions } from '@aws-amplify/platform-core';
import { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda';
import { Template } from 'aws-cdk-lib/assertions';
import { FunctionEnvironmentTypeGenerator } from './function_env_type_generator.js';
import path from 'node:path';
import fsp from 'fs/promises';

const testStack = {} as Construct;

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

after(async () => {
// clean up generated env files
await fsp.rm(path.join(process.cwd(), '.amplify'), {
recursive: true,
force: true,
});
});

void it('translates env props that do not contain secrets', () => {
const functionEnvProp = {
TEST_VAR: 'testValue',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import { describe, it, mock } from 'node:test';
import { after, describe, it, mock } from 'node:test';
import fs from 'fs';
import fsp from 'fs/promises';
import { FunctionEnvironmentTypeGenerator } from './function_env_type_generator.js';
import assert from 'assert';
import { pathToFileURL } from 'url';
import path from 'path';

void describe('FunctionEnvironmentTypeGenerator', () => {
after(async () => {
// clean up generated env files
await fsp.rm(path.join(process.cwd(), '.amplify'), {
recursive: true,
force: true,
});
});

void it('generates a type definition file', () => {
const fsOpenSyncMock = mock.method(fs, 'openSync');
const fsWriteFileSyncMock = mock.method(fs, 'writeFileSync', () => null);
Expand Down
12 changes: 11 additions & 1 deletion packages/backend-function/src/layer_parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import {
import { App, Stack } from 'aws-cdk-lib';
import { Template } from 'aws-cdk-lib/assertions';
import assert from 'node:assert';
import { beforeEach, describe, it } from 'node:test';
import { after, beforeEach, describe, it } from 'node:test';
import { defineFunction } from './factory.js';
import path from 'node:path';
import fsp from 'fs/promises';

const createStackAndSetContext = (): Stack => {
const app = new App();
Expand Down Expand Up @@ -49,6 +51,14 @@ void describe('AmplifyFunctionFactory - Layers', () => {
};
});

after(async () => {
// clean up generated env files
await fsp.rm(path.join(process.cwd(), '.amplify'), {
recursive: true,
force: true,
});
});

void it('sets a valid layer', () => {
const layerArn = 'arn:aws:lambda:us-east-1:123456789012:layer:my-layer:1';
const functionFactory = defineFunction({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
synthesizeBackendTemplates,
} from '../define_backend_template_harness.js';
import { dataStorageAuthWithTriggers } from '../test-projects/data-storage-auth-with-triggers-ts/amplify/test_factories.js';
import path from 'node:path';
import fsp from 'fs/promises';

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

void it('data storage auth with triggers', () => {
void it('data storage auth with triggers', async () => {
const templates = synthesizeBackendTemplates(dataStorageAuthWithTriggers);

assertExpectedLogicalIds(templates.root, 'AWS::CloudFormation::Stack', [
Expand Down Expand Up @@ -58,4 +60,10 @@ void it('data storage auth with triggers', () => {
'onDeletelambda96BB6F15',
]);
/* eslint-enable spellcheck/spell-checker */

// clean up generated env files
await fsp.rm(path.join(process.cwd(), '.amplify'), {
recursive: true,
force: true,
});
});