Skip to content

Commit bc20ab1

Browse files
rtpascualKamil Sobol
andauthored
Fix type errors when building tests (#1697)
* 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 <[email protected]> --------- Co-authored-by: Kamil Sobol <[email protected]>
1 parent 4489724 commit bc20ab1

21 files changed

+465
-254
lines changed

.changeset/tasty-terms-accept.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
---
3+
4+
fix type errors when building tests

.eslint_dictionary.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"changelog",
2020
"changeset",
2121
"changesets",
22+
"chown",
2223
"cloudformation",
2324
"codebase",
2425
"codegen",
@@ -29,6 +30,7 @@
2930
"ctor",
3031
"darwin",
3132
"datastore",
33+
"datasync",
3234
"debounce",
3335
"declarator",
3436
"deployer",
@@ -117,6 +119,7 @@
117119
"readdir",
118120
"readline",
119121
"readonly",
122+
"readv",
120123
"regexes",
121124
"renderer",
122125
"repo",
@@ -166,6 +169,7 @@
166169
"urls",
167170
"userpool",
168171
"utf",
172+
"utimes",
169173
"verdaccio",
170174
"verifier",
171175
"versioned",
@@ -174,6 +178,7 @@
174178
"wildcard",
175179
"wildcards",
176180
"workspace",
181+
"writev",
177182
"yaml",
178183
"yargs",
179184
"zoneinfo"

packages/backend-deployer/src/cdk_deployer.test.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,15 @@ void describe('invokeCDKCommand', () => {
5151
backendLocator,
5252
packageManagerControllerMock as never
5353
);
54-
const executeCommandMock = mock.method(invoker, 'executeCommand', () =>
55-
Promise.resolve()
54+
const executeCommandMock = mock.method(
55+
invoker,
56+
'executeCommand',
57+
(commandArgs: string[]) => {
58+
if (commandArgs.includes('abc')) {
59+
return Promise.reject(new Error());
60+
}
61+
return Promise.resolve();
62+
}
5663
);
5764

5865
beforeEach(() => {
@@ -446,7 +453,7 @@ void describe('invokeCDKCommand', () => {
446453
if (commandArgs.includes('tsc') && commandArgs.includes('--noEmit')) {
447454
throw new Error('some tsc error');
448455
}
449-
return;
456+
return Promise.resolve();
450457
});
451458

452459
await assert.rejects(

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,9 @@ import { pathToFileURL } from 'url';
77

88
void describe('FunctionEnvironmentTypeGenerator', () => {
99
void it('generates a type definition file', () => {
10-
const fdCloseMock = mock.fn();
1110
const fsOpenSyncMock = mock.method(fs, 'openSync');
1211
const fsWriteFileSyncMock = mock.method(fs, 'writeFileSync', () => null);
13-
fsOpenSyncMock.mock.mockImplementation(() => {
14-
return {
15-
close: fdCloseMock,
16-
};
17-
});
12+
fsOpenSyncMock.mock.mockImplementation(() => 0);
1813
const functionEnvironmentTypeGenerator =
1914
new FunctionEnvironmentTypeGenerator('testFunction');
2015
const sampleStaticEnv = '_HANDLER: string;';
@@ -37,14 +32,9 @@ void describe('FunctionEnvironmentTypeGenerator', () => {
3732
});
3833

3934
void it('generates a type definition file with Amplify backend environment variables', () => {
40-
const fdCloseMock = mock.fn();
4135
const fsOpenSyncMock = mock.method(fs, 'openSync');
4236
const fsWriteFileSyncMock = mock.method(fs, 'writeFileSync', () => null);
43-
fsOpenSyncMock.mock.mockImplementation(() => {
44-
return {
45-
close: fdCloseMock,
46-
};
47-
});
37+
fsOpenSyncMock.mock.mockImplementation(() => 0);
4838
const functionEnvironmentTypeGenerator =
4939
new FunctionEnvironmentTypeGenerator('testFunction');
5040
const sampleStaticEnv = 'TEST_ENV: string;';

packages/cli/src/commands/generate/forms/generate_forms_command.test.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,13 @@ void describe('generate forms command', () => {
4444
.method(fakedBackendOutputClient, 'getOutput')
4545
.mock.mockImplementation(async () => ({
4646
[graphqlOutputKey]: {
47+
version: '1',
4748
payload: {
49+
awsAppsyncRegion: 'us-west-1',
50+
awsAppsyncApiEndpoint: 'test_endpoint',
51+
awsAppsyncAuthenticationType: 'API_KEY',
4852
awsAppsyncApiId: 'test_api_id',
4953
amplifyApiModelSchemaS3Uri: 'test_schema',
50-
awsAppsyncApiEndpoint: 'test_endpoint',
5154
},
5255
},
5356
}));
@@ -88,10 +91,13 @@ void describe('generate forms command', () => {
8891
.method(fakedBackendOutputClient, 'getOutput')
8992
.mock.mockImplementation(async () => ({
9093
[graphqlOutputKey]: {
94+
version: '1',
9195
payload: {
96+
awsAppsyncRegion: 'us-west-1',
97+
awsAppsyncApiEndpoint: 'test_endpoint',
98+
awsAppsyncAuthenticationType: 'API_KEY',
9299
awsAppsyncApiId: 'test_api_id',
93100
amplifyApiModelSchemaS3Uri: 'test_schema',
94-
awsAppsyncApiEndpoint: 'test_endpoint',
95101
},
96102
},
97103
}));
@@ -132,10 +138,13 @@ void describe('generate forms command', () => {
132138
.method(fakedBackendOutputClient, 'getOutput')
133139
.mock.mockImplementation(async () => ({
134140
[graphqlOutputKey]: {
141+
version: '1',
135142
payload: {
143+
awsAppsyncRegion: 'us-west-1',
144+
awsAppsyncApiEndpoint: 'test_endpoint',
145+
awsAppsyncAuthenticationType: 'API_KEY',
136146
awsAppsyncApiId: 'test_api_id',
137147
amplifyApiModelSchemaS3Uri: 'test_schema',
138-
awsAppsyncApiEndpoint: 'test_endpoint',
139148
},
140149
},
141150
}));
@@ -164,7 +173,13 @@ void describe('generate forms command', () => {
164173
const fakeSandboxId = 'my-fake-app-my-fake-username';
165174

166175
const sandboxIdResolver = mock.method(mockedSandboxIdResolver, 'resolve');
167-
sandboxIdResolver.mock.mockImplementation(() => fakeSandboxId);
176+
sandboxIdResolver.mock.mockImplementation(() =>
177+
Promise.resolve({
178+
namespace: fakeSandboxId,
179+
name: fakeSandboxId,
180+
type: 'sandbox',
181+
})
182+
);
168183

169184
const backendIdResolver = new BackendIdentifierResolverWithFallback(
170185
defaultResolver,
@@ -189,10 +204,13 @@ void describe('generate forms command', () => {
189204
.method(fakedBackendOutputClient, 'getOutput')
190205
.mock.mockImplementation(async () => ({
191206
[graphqlOutputKey]: {
207+
version: '1',
192208
payload: {
209+
awsAppsyncRegion: 'us-west-1',
210+
awsAppsyncApiEndpoint: 'test_endpoint',
211+
awsAppsyncAuthenticationType: 'API_KEY',
193212
awsAppsyncApiId: 'test_api_id',
194213
amplifyApiModelSchemaS3Uri: 'test_schema',
195-
awsAppsyncApiEndpoint: 'test_endpoint',
196214
},
197215
},
198216
}));
@@ -203,7 +221,11 @@ void describe('generate forms command', () => {
203221
await commandRunner.runCommand('forms');
204222
assert.deepEqual(
205223
generationMock.mock.calls[0].arguments[0].backendIdentifier,
206-
fakeSandboxId
224+
{
225+
namespace: fakeSandboxId,
226+
name: fakeSandboxId,
227+
type: 'sandbox',
228+
}
207229
);
208230
});
209231
});

packages/cli/src/commands/generate/graphql-client-code/generate_graphql_client_code_command.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ void describe('generate graphql-client-code command', () => {
4242
const defaultResolver = new AppBackendIdentifierResolver(namespaceResolver);
4343
const sandboxIdResolver = new SandboxBackendIdResolver(namespaceResolver);
4444
const fakeSandboxId = 'my-fake-app-my-fake-username';
45-
const mockedSandboxIdResolver = mock.method(sandboxIdResolver, 'resolve');
46-
mockedSandboxIdResolver.mock.mockImplementation(() => ({
45+
mock.method(sandboxIdResolver, 'resolve', () => ({
4746
name: fakeSandboxId,
4847
}));
4948

packages/cli/src/commands/generate/outputs/generate_outputs_command.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ void describe('generate outputs command', () => {
3333

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

3938
const backendIdResolver = new BackendIdentifierResolverWithFallback(
4039
defaultResolver,

packages/cli/src/commands/generate/schema-from-database/generate_schema_command.test.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ void describe('generate graphql-client-code command', () => {
1818
const defaultResolver = new AppBackendIdentifierResolver(namespaceResolver);
1919
const sandboxIdResolver = new SandboxBackendIdResolver(namespaceResolver);
2020
const fakeSandboxId = 'my-fake-app-my-fake-username';
21-
const mockedSandboxIdResolver = mock.method(sandboxIdResolver, 'resolve');
22-
mockedSandboxIdResolver.mock.mockImplementation(() => ({
21+
mock.method(sandboxIdResolver, 'resolve', () => ({
2322
name: fakeSandboxId,
2423
}));
2524

@@ -33,11 +32,11 @@ void describe('generate graphql-client-code command', () => {
3332
const schemaGenerator = new SchemaGenerator();
3433
const schemaGeneratorGenerateMethod = mock.method(
3534
schemaGenerator,
36-
'generate'
35+
'generate',
36+
() => {
37+
return 'TYPESCRIPT_DATA_SCHEMA';
38+
}
3739
);
38-
schemaGeneratorGenerateMethod.mock.mockImplementation(() => {
39-
return 'TYPESCRIPT_DATA_SCHEMA';
40-
});
4140

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

53-
const secretClientGetSecret = mock.method(secretClient, 'getSecret');
54-
secretClientGetSecret.mock.mockImplementation(() => {
52+
const secretClientGetSecret = mock.method(secretClient, 'getSecret', () => {
5553
return Promise.resolve({
5654
name: 'CONN_STRING',
5755
value: 'FAKE_SECRET_VALUE',

packages/client-config/src/client-config-writer/client_config_writer.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void describe('client config writer', () => {
5656
const format = ClientConfigFormat.MJS;
5757
const formattedContent = randomUUID().toString();
5858

59-
pathResolverMock.mock.mockImplementation(() => targetFile);
59+
pathResolverMock.mock.mockImplementation(() => Promise.resolve(targetFile));
6060
nameResolverMock.mock.mockImplementation(
6161
() => ClientConfigFileBaseName.LEGACY
6262
);
@@ -102,7 +102,7 @@ void describe('client config writer', () => {
102102
const format = ClientConfigFormat.MJS;
103103
const formattedContent = randomUUID().toString();
104104

105-
pathResolverMock.mock.mockImplementation(() => targetFile);
105+
pathResolverMock.mock.mockImplementation(() => Promise.resolve(targetFile));
106106
nameResolverMock.mock.mockImplementation(
107107
() => ClientConfigFileBaseName.DEFAULT
108108
);
@@ -147,7 +147,7 @@ void describe('client config writer', () => {
147147
const targetFile = '/foo/bar/baz';
148148
const formattedContent = randomUUID().toString();
149149

150-
pathResolverMock.mock.mockImplementation(() => targetFile);
150+
pathResolverMock.mock.mockImplementation(() => Promise.resolve(targetFile));
151151
nameResolverMock.mock.mockImplementation(
152152
() => ClientConfigFileBaseName.DEFAULT
153153
);

0 commit comments

Comments
 (0)