Skip to content

Commit

Permalink
Fix type errors when building tests (#1697)
Browse files Browse the repository at this point in the history
* fix type errors when building tests

* update dependencies validator test

* try this

* try that

* Update .changeset/tasty-terms-accept.md

Co-authored-by: Kamil Sobol <sobkamil@amazon.com>

---------

Co-authored-by: Kamil Sobol <sobkamil@amazon.com>
  • Loading branch information
rtpascual and sobolk authored Jun 28, 2024
1 parent 4489724 commit bc20ab1
Show file tree
Hide file tree
Showing 21 changed files with 465 additions and 254 deletions.
4 changes: 4 additions & 0 deletions .changeset/tasty-terms-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

fix type errors when building tests
5 changes: 5 additions & 0 deletions .eslint_dictionary.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"changelog",
"changeset",
"changesets",
"chown",
"cloudformation",
"codebase",
"codegen",
Expand All @@ -29,6 +30,7 @@
"ctor",
"darwin",
"datastore",
"datasync",
"debounce",
"declarator",
"deployer",
Expand Down Expand Up @@ -117,6 +119,7 @@
"readdir",
"readline",
"readonly",
"readv",
"regexes",
"renderer",
"repo",
Expand Down Expand Up @@ -166,6 +169,7 @@
"urls",
"userpool",
"utf",
"utimes",
"verdaccio",
"verifier",
"versioned",
Expand All @@ -174,6 +178,7 @@
"wildcard",
"wildcards",
"workspace",
"writev",
"yaml",
"yargs",
"zoneinfo"
Expand Down
13 changes: 10 additions & 3 deletions packages/backend-deployer/src/cdk_deployer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,15 @@ void describe('invokeCDKCommand', () => {
backendLocator,
packageManagerControllerMock as never
);
const executeCommandMock = mock.method(invoker, 'executeCommand', () =>
Promise.resolve()
const executeCommandMock = mock.method(
invoker,
'executeCommand',
(commandArgs: string[]) => {
if (commandArgs.includes('abc')) {
return Promise.reject(new Error());
}
return Promise.resolve();
}
);

beforeEach(() => {
Expand Down Expand Up @@ -446,7 +453,7 @@ void describe('invokeCDKCommand', () => {
if (commandArgs.includes('tsc') && commandArgs.includes('--noEmit')) {
throw new Error('some tsc error');
}
return;
return Promise.resolve();
});

await assert.rejects(
Expand Down
14 changes: 2 additions & 12 deletions packages/backend-function/src/function_env_type_generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@ import { pathToFileURL } from 'url';

void describe('FunctionEnvironmentTypeGenerator', () => {
void it('generates a type definition file', () => {
const fdCloseMock = mock.fn();
const fsOpenSyncMock = mock.method(fs, 'openSync');
const fsWriteFileSyncMock = mock.method(fs, 'writeFileSync', () => null);
fsOpenSyncMock.mock.mockImplementation(() => {
return {
close: fdCloseMock,
};
});
fsOpenSyncMock.mock.mockImplementation(() => 0);
const functionEnvironmentTypeGenerator =
new FunctionEnvironmentTypeGenerator('testFunction');
const sampleStaticEnv = '_HANDLER: string;';
Expand All @@ -37,14 +32,9 @@ void describe('FunctionEnvironmentTypeGenerator', () => {
});

void it('generates a type definition file with Amplify backend environment variables', () => {
const fdCloseMock = mock.fn();
const fsOpenSyncMock = mock.method(fs, 'openSync');
const fsWriteFileSyncMock = mock.method(fs, 'writeFileSync', () => null);
fsOpenSyncMock.mock.mockImplementation(() => {
return {
close: fdCloseMock,
};
});
fsOpenSyncMock.mock.mockImplementation(() => 0);
const functionEnvironmentTypeGenerator =
new FunctionEnvironmentTypeGenerator('testFunction');
const sampleStaticEnv = 'TEST_ENV: string;';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ void describe('generate forms command', () => {
.method(fakedBackendOutputClient, 'getOutput')
.mock.mockImplementation(async () => ({
[graphqlOutputKey]: {
version: '1',
payload: {
awsAppsyncRegion: 'us-west-1',
awsAppsyncApiEndpoint: 'test_endpoint',
awsAppsyncAuthenticationType: 'API_KEY',
awsAppsyncApiId: 'test_api_id',
amplifyApiModelSchemaS3Uri: 'test_schema',
awsAppsyncApiEndpoint: 'test_endpoint',
},
},
}));
Expand Down Expand Up @@ -88,10 +91,13 @@ void describe('generate forms command', () => {
.method(fakedBackendOutputClient, 'getOutput')
.mock.mockImplementation(async () => ({
[graphqlOutputKey]: {
version: '1',
payload: {
awsAppsyncRegion: 'us-west-1',
awsAppsyncApiEndpoint: 'test_endpoint',
awsAppsyncAuthenticationType: 'API_KEY',
awsAppsyncApiId: 'test_api_id',
amplifyApiModelSchemaS3Uri: 'test_schema',
awsAppsyncApiEndpoint: 'test_endpoint',
},
},
}));
Expand Down Expand Up @@ -132,10 +138,13 @@ void describe('generate forms command', () => {
.method(fakedBackendOutputClient, 'getOutput')
.mock.mockImplementation(async () => ({
[graphqlOutputKey]: {
version: '1',
payload: {
awsAppsyncRegion: 'us-west-1',
awsAppsyncApiEndpoint: 'test_endpoint',
awsAppsyncAuthenticationType: 'API_KEY',
awsAppsyncApiId: 'test_api_id',
amplifyApiModelSchemaS3Uri: 'test_schema',
awsAppsyncApiEndpoint: 'test_endpoint',
},
},
}));
Expand Down Expand Up @@ -164,7 +173,13 @@ void describe('generate forms command', () => {
const fakeSandboxId = 'my-fake-app-my-fake-username';

const sandboxIdResolver = mock.method(mockedSandboxIdResolver, 'resolve');
sandboxIdResolver.mock.mockImplementation(() => fakeSandboxId);
sandboxIdResolver.mock.mockImplementation(() =>
Promise.resolve({
namespace: fakeSandboxId,
name: fakeSandboxId,
type: 'sandbox',
})
);

const backendIdResolver = new BackendIdentifierResolverWithFallback(
defaultResolver,
Expand All @@ -189,10 +204,13 @@ void describe('generate forms command', () => {
.method(fakedBackendOutputClient, 'getOutput')
.mock.mockImplementation(async () => ({
[graphqlOutputKey]: {
version: '1',
payload: {
awsAppsyncRegion: 'us-west-1',
awsAppsyncApiEndpoint: 'test_endpoint',
awsAppsyncAuthenticationType: 'API_KEY',
awsAppsyncApiId: 'test_api_id',
amplifyApiModelSchemaS3Uri: 'test_schema',
awsAppsyncApiEndpoint: 'test_endpoint',
},
},
}));
Expand All @@ -203,7 +221,11 @@ void describe('generate forms command', () => {
await commandRunner.runCommand('forms');
assert.deepEqual(
generationMock.mock.calls[0].arguments[0].backendIdentifier,
fakeSandboxId
{
namespace: fakeSandboxId,
name: fakeSandboxId,
type: 'sandbox',
}
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ void describe('generate graphql-client-code command', () => {
const defaultResolver = new AppBackendIdentifierResolver(namespaceResolver);
const sandboxIdResolver = new SandboxBackendIdResolver(namespaceResolver);
const fakeSandboxId = 'my-fake-app-my-fake-username';
const mockedSandboxIdResolver = mock.method(sandboxIdResolver, 'resolve');
mockedSandboxIdResolver.mock.mockImplementation(() => ({
mock.method(sandboxIdResolver, 'resolve', () => ({
name: fakeSandboxId,
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ void describe('generate outputs command', () => {

const sandboxIdResolver = new SandboxBackendIdResolver(namespaceResolver);
const fakeSandboxId = 'my-fake-app-my-fake-username';
const mockedSandboxIdResolver = mock.method(sandboxIdResolver, 'resolve');
mockedSandboxIdResolver.mock.mockImplementation(() => fakeSandboxId);
mock.method(sandboxIdResolver, 'resolve', () => fakeSandboxId);

const backendIdResolver = new BackendIdentifierResolverWithFallback(
defaultResolver,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ void describe('generate graphql-client-code command', () => {
const defaultResolver = new AppBackendIdentifierResolver(namespaceResolver);
const sandboxIdResolver = new SandboxBackendIdResolver(namespaceResolver);
const fakeSandboxId = 'my-fake-app-my-fake-username';
const mockedSandboxIdResolver = mock.method(sandboxIdResolver, 'resolve');
mockedSandboxIdResolver.mock.mockImplementation(() => ({
mock.method(sandboxIdResolver, 'resolve', () => ({
name: fakeSandboxId,
}));

Expand All @@ -33,11 +32,11 @@ void describe('generate graphql-client-code command', () => {
const schemaGenerator = new SchemaGenerator();
const schemaGeneratorGenerateMethod = mock.method(
schemaGenerator,
'generate'
'generate',
() => {
return 'TYPESCRIPT_DATA_SCHEMA';
}
);
schemaGeneratorGenerateMethod.mock.mockImplementation(() => {
return 'TYPESCRIPT_DATA_SCHEMA';
});

const generateSchemaCommand = new GenerateSchemaCommand(
backendIdentifierResolver,
Expand All @@ -50,8 +49,7 @@ void describe('generate graphql-client-code command', () => {
);
const commandRunner = new TestCommandRunner(parser);

const secretClientGetSecret = mock.method(secretClient, 'getSecret');
secretClientGetSecret.mock.mockImplementation(() => {
const secretClientGetSecret = mock.method(secretClient, 'getSecret', () => {
return Promise.resolve({
name: 'CONN_STRING',
value: 'FAKE_SECRET_VALUE',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void describe('client config writer', () => {
const format = ClientConfigFormat.MJS;
const formattedContent = randomUUID().toString();

pathResolverMock.mock.mockImplementation(() => targetFile);
pathResolverMock.mock.mockImplementation(() => Promise.resolve(targetFile));
nameResolverMock.mock.mockImplementation(
() => ClientConfigFileBaseName.LEGACY
);
Expand Down Expand Up @@ -102,7 +102,7 @@ void describe('client config writer', () => {
const format = ClientConfigFormat.MJS;
const formattedContent = randomUUID().toString();

pathResolverMock.mock.mockImplementation(() => targetFile);
pathResolverMock.mock.mockImplementation(() => Promise.resolve(targetFile));
nameResolverMock.mock.mockImplementation(
() => ClientConfigFileBaseName.DEFAULT
);
Expand Down Expand Up @@ -147,7 +147,7 @@ void describe('client config writer', () => {
const targetFile = '/foo/bar/baz';
const formattedContent = randomUUID().toString();

pathResolverMock.mock.mockImplementation(() => targetFile);
pathResolverMock.mock.mockImplementation(() => Promise.resolve(targetFile));
nameResolverMock.mock.mockImplementation(
() => ClientConfigFileBaseName.DEFAULT
);
Expand Down
Loading

0 comments on commit bc20ab1

Please sign in to comment.