@aws-cdk/integ-runner 2.202.2 → 2.202.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/lib/cli.d.ts.map +1 -1
  2. package/lib/cli.js +3 -2
  3. package/lib/engines/toolkit-lib.d.ts +1 -1
  4. package/lib/engines/toolkit-lib.d.ts.map +1 -1
  5. package/lib/engines/toolkit-lib.js +11 -11
  6. package/lib/files.d.ts +9 -0
  7. package/lib/files.d.ts.map +1 -0
  8. package/lib/files.js +51 -0
  9. package/lib/index.js +218 -182
  10. package/lib/runner/{cdk-integ-helper.d.ts → cdk-test-app.d.ts} +90 -114
  11. package/lib/runner/cdk-test-app.d.ts.map +1 -0
  12. package/lib/runner/cdk-test-app.js +584 -0
  13. package/lib/runner/engine.d.ts +2 -2
  14. package/lib/runner/engine.d.ts.map +1 -1
  15. package/lib/runner/engine.js +2 -2
  16. package/lib/runner/index.d.ts +1 -1
  17. package/lib/runner/index.d.ts.map +1 -1
  18. package/lib/runner/index.js +2 -2
  19. package/lib/runner/integ-test-runner.d.ts +36 -36
  20. package/lib/runner/integ-test-runner.d.ts.map +1 -1
  21. package/lib/runner/integ-test-runner.js +172 -235
  22. package/lib/runner/integ-test-suite.d.ts +6 -11
  23. package/lib/runner/integ-test-suite.d.ts.map +1 -1
  24. package/lib/runner/integ-test-suite.js +14 -20
  25. package/lib/runner/integration-tests.d.ts +12 -3
  26. package/lib/runner/integration-tests.d.ts.map +1 -1
  27. package/lib/runner/integration-tests.js +32 -8
  28. package/lib/runner/snapshot-test-runner.d.ts +19 -22
  29. package/lib/runner/snapshot-test-runner.d.ts.map +1 -1
  30. package/lib/runner/snapshot-test-runner.js +47 -75
  31. package/lib/workers/extract/extract_worker.d.ts.map +1 -1
  32. package/lib/workers/extract/extract_worker.js +65 -78
  33. package/lib/workers/extract/index.js +226955 -226979
  34. package/lib/workers/integ-test-worker.d.ts.map +1 -1
  35. package/lib/workers/integ-test-worker.js +3 -2
  36. package/package.json +3 -3
  37. package/lib/runner/cdk-integ-helper.d.ts.map +0 -1
  38. package/lib/runner/cdk-integ-helper.js +0 -525
@@ -1,20 +1,17 @@
1
- import type { TestCase, DefaultCdkOptions } from '@aws-cdk/cloud-assembly-schema';
1
+ import { type TestCase, type DefaultCdkOptions } from '@aws-cdk/cloud-assembly-schema';
2
2
  import { IntegTestSuite, LegacyIntegTestSuite } from './integ-test-suite';
3
+ import type { DeployOptions, DestroyOptions, ICdk, WatchEvents } from '../engines/cdk-interface';
3
4
  import type { IntegTest } from './integration-tests';
4
- import type { ICdk } from '../engines/cdk-interface';
5
5
  import type { DestructiveChange } from '../workers/common';
6
6
  /**
7
- * Options for creating an integ helper
7
+ * Options for creating a CDK Cloud Assembly
8
8
  */
9
- export interface CdkIntegHelperOptions {
10
- /**
11
- * Information about the test to run
12
- */
9
+ export interface CdkTestAppOptions {
13
10
  readonly test: IntegTest;
14
11
  /**
15
12
  * The region where the test should be deployed
16
13
  */
17
- readonly region: string;
14
+ readonly region?: string;
18
15
  /**
19
16
  * The AWS profile to use when invoking the CDK CLI
20
17
  *
@@ -31,11 +28,14 @@ export interface CdkIntegHelperOptions {
31
28
  [name: string]: string;
32
29
  };
33
30
  /**
34
- * tmp cdk.out directory
31
+ * Where we will write the output of the CDK CLI, including the cloud assembly and the snapshot
35
32
  *
36
- * @default - directory will be `cdk-integ.out.${testName}`
33
+ * Should be a string containing `{testName}`, will be used to generate a directory name in the same
34
+ * directory as the test itself.
35
+ *
36
+ * @default 'cdk-integ.out.{testName}.snapshot'
37
37
  */
38
- readonly integOutDir?: string;
38
+ readonly outputDirectoryNameTemplate: string;
39
39
  /**
40
40
  * Instance of the CDK Toolkit Engine to use
41
41
  *
@@ -61,12 +61,20 @@ export interface CdkIntegHelperOptions {
61
61
  */
62
62
  readonly caBundlePath?: string;
63
63
  /**
64
- * In unit test mode, leave the synth output directories, don't clean them.
64
+ * In unit test mode, we are using mocks for a lot of calls
65
65
  *
66
- * Many of our tests use mocks and don't actually synth output directories, they are
67
- * static and must not be deleted.
66
+ * Don't delete directories, and don't do checks whether files actually exist; the
67
+ * mocks will be there to produce the contents for files that are being read (although
68
+ * they are not there to pretend to have files themselves).
68
69
  */
69
- readonly testingUsingMocksLeaveDirectories?: boolean;
70
+ readonly TESTING_usingMocks?: boolean;
71
+ /**
72
+ * We will only read the legacy test information if the test actually produced an output directory.
73
+ *
74
+ * For historical reasons the tests have been written so that they will expect to read
75
+ * legacy test information always. Force that behavior back for tests.
76
+ */
77
+ readonly TESTING_forceReadLegacyTestSuite?: boolean;
70
78
  }
71
79
  /**
72
80
  * Whether to synthesize the actual snapshot with lookups enabled or not.
@@ -88,55 +96,23 @@ export type LegacyEnableLookups = true | false | 'dont-care';
88
96
  * This is as opposed to other snapshots, which can be generated for example
89
97
  * temporarily in a temporary directory, to compare agains the golden snapshot.
90
98
  */
91
- export declare class CdkIntegHelper {
92
- /**
93
- * Factory method to create an instance of the CdkIntegHelper.
94
- *
95
- * Hiding the constructor to prevent inheritance.
96
- */
97
- static create(options: CdkIntegHelperOptions): CdkIntegHelper;
98
- /**
99
- * The directory where the golden snapshot will be stored
100
- */
101
- readonly goldenSnapshotDir: string;
99
+ export declare class CdkTestApp {
100
+ private readonly options;
101
+ private readonly testSpecificContext?;
102
+ static forGoldenSnapshot(options: Omit<CdkTestAppOptions, 'outputDirectoryNameTemplate'>): Promise<CdkTestApp>;
103
+ static forComparison(options: Omit<CdkTestAppOptions, 'outputDirectoryNameTemplate'>): Promise<CdkTestApp>;
104
+ static forSpecificDirectory(options: CdkTestAppOptions): Promise<CdkTestApp>;
105
+ static forDeployment(options: Omit<CdkTestAppOptions, 'outputDirectoryNameTemplate'>): Promise<CdkTestApp>;
106
+ private static create;
102
107
  /**
103
108
  * An instance of the CDK CLI
104
109
  */
105
- readonly cdk: ICdk;
106
- /**
107
- * Pretty name of the test
108
- */
109
- readonly testName: string;
110
- /**
111
- * The value used in the '--app' CLI parameter
112
- *
113
- * Path to the integ test source file, relative to `this.directory`.
114
- */
115
- readonly cdkApp: string;
116
- /**
117
- * The path where the `cdk.context.json` file
118
- * will be created
119
- */
120
- readonly cdkContextPath: string;
121
- /**
122
- * The working directory that the integration tests will be
123
- * executed from
124
- */
125
- readonly directory: string;
126
- /**
127
- * The test to run
128
- */
129
- private readonly test;
110
+ private readonly cdk;
111
+ readonly outputDirectory: string;
130
112
  /**
131
113
  * Default options to pass to the CDK CLI
132
114
  */
133
- readonly defaultArgs: DefaultCdkOptions;
134
- /**
135
- * The directory where the CDK will be synthed to
136
- *
137
- * Relative to cwd.
138
- */
139
- readonly temporarySnapshotDir: string;
115
+ private readonly defaultArgs;
140
116
  /**
141
117
  * The profile to use for the CDK CLI calls
142
118
  */
@@ -145,46 +121,49 @@ export declare class CdkIntegHelper {
145
121
  * Show output from the integ test run.
146
122
  */
147
123
  private readonly showOutput;
124
+ readonly test: IntegTest;
125
+ synthReproCommand: string;
148
126
  _destructiveChanges?: DestructiveChange[];
149
127
  private legacyContext?;
150
- private _expectedTestSuite?;
151
- private _actualSnapshot?;
128
+ private _testSuite?;
152
129
  private _legacyEnableLookups?;
153
- private readonly deleteSynthDirectories;
154
- /**
155
- * Fields that require an async context to initialize.
156
- */
157
- private _asyncMembers?;
158
- /**
159
- * Private constructor to prevent inheritance.
160
- */
130
+ readonly appCommand: string;
131
+ private hasValidRegion;
161
132
  private constructor();
162
- /**
163
- * Async initialization; copy information from an async context into variables so we can access them synchronously later.
164
- *
165
- * We call this automatically in all public async members, but if a consumer wants to access this context synchronously
166
- * without calling an async members first, it needs to call this.
167
- */
168
- asyncInitialize(): Promise<void>;
169
- private get asyncMembers();
170
133
  /**
171
134
  * Configure the legacy enableLookups value to use when generating the actual snapshot.
172
135
  *
173
136
  * Must be set before using snapshot methods.
174
137
  */
175
138
  configureLegacyEnableLookups(enableLookups: LegacyEnableLookups): void;
139
+ hasOutput(): Promise<boolean>;
176
140
  /**
177
- * Return the list of actual (i.e. new) test cases for this integration test
141
+ * Return the test cases inside the output
178
142
  */
179
- actualTests(): Promise<{
143
+ testCases(): {
180
144
  [testName: string]: TestCase;
181
- } | undefined>;
145
+ };
146
+ /**
147
+ * The test suite from the output
148
+ */
149
+ get testSuite(): IntegTestSuite | LegacyIntegTestSuite;
150
+ /**
151
+ * If the snapshot already exists, load it
152
+ */
153
+ loadExistingSuite(): Promise<IntegTestSuite | LegacyIntegTestSuite | undefined>;
154
+ synthForSnapshotComparison(enableLookupsGuess: LegacyEnableLookups): Promise<IntegTestSuite | LegacyIntegTestSuite>;
155
+ synthForGoldenSnapshot(destructiveChanges: DestructiveChange[], enableLookups: LegacyEnableLookups): Promise<IntegTestSuite | LegacyIntegTestSuite>;
156
+ synthForDeployment(): Promise<IntegTestSuite | LegacyIntegTestSuite>;
182
157
  /**
183
- * Generate a new "actual" snapshot which will be compared to the
184
- * existing "expected" snapshot
185
- * This will synth and then load the integration test manifest
158
+ * For a given cloud assembly return a collection of all templates
159
+ * that should be part of the snapshot and any required meta data.
160
+ *
161
+ * @param cloudAssemblyDir - The directory of the cloud assembly to look for snapshots
162
+ * @param pickStacks - Pick only these stacks from the cloud assembly
163
+ * @returns A SnapshotAssembly, the collection of all templates in this snapshot and required meta data
186
164
  */
187
- private generateActualSnapshot;
165
+ snapshotAssembly(pickStacks?: string[]): SnapshotAssembly;
166
+ private readAssembly;
188
167
  /**
189
168
  * Synth the actual application to the given directory, for purposes of generating/validating a snapshot
190
169
  *
@@ -205,21 +184,12 @@ export declare class CdkIntegHelper {
205
184
  * determine whether to pass the context, and if the new actual snapshot has a
206
185
  * different value for `enableLookups`, we will throw away the old snapshot and synth again.
207
186
  */
208
- private synthActualSnapshot;
209
- actualSynthReproCommand(): string[];
210
- /**
211
- * Returns true if a snapshot already exists for this test
212
- */
213
- hasSnapshot(): boolean;
214
- /**
215
- * The test suite from the existing snapshot
216
- */
217
- expectedTestSuite(): Promise<IntegTestSuite | LegacyIntegTestSuite | undefined>;
218
- actualSnapshot(): Promise<SnapshotAndTestDefinition>;
219
- /**
220
- * The test suite from the new "actual" snapshot
221
- */
222
- private actualTestSuite;
187
+ private synth;
188
+ deploy(deployArgs: Omit<DeployOptions, 'app' | 'requireApproval' | 'profile' | 'output' | 'lookups'>): Promise<import("../engines/cdk-interface").CdkDeployResult>;
189
+ destroy(destroyArgs: Omit<DestroyOptions, 'app' | 'force' | 'profile' | 'output'>): Promise<void>;
190
+ watch(watchArgs: Omit<DeployOptions, 'app' | 'requireApproval' | 'profile' | 'output' | 'lookups'>, watchEvents: WatchEvents): Promise<void>;
191
+ private setReproCommand;
192
+ private _loadLegacyTestSuite;
223
193
  cleanup(): void;
224
194
  /**
225
195
  * If there are any destructive changes to a stack then this will record
@@ -242,24 +212,13 @@ export declare class CdkIntegHelper {
242
212
  * re-zipping on deploy
243
213
  */
244
214
  private removeAssetsCacheFromSnapshot;
245
- /**
246
- * Create the new snapshot.
247
- *
248
- * If lookups are enabled, then we need create the snapshot by synth'ing again
249
- * with the dummy context so that each time the test is run on different machines
250
- * (and with different context/env) the diff will not change.
251
- *
252
- * If lookups are disabled (which means the stack is env agnostic) then just copy
253
- * the assembly that was output by the deployment
254
- */
255
- createSnapshot(): Promise<void>;
256
215
  /**
257
216
  * Perform some cleanup steps after the snapshot is created
258
217
  * Anytime the snapshot needs to be modified after creation
259
218
  * the logic should live here.
260
219
  */
261
220
  private cleanupGoldenSnapshot;
262
- getContext(additionalContext?: Record<string, any>): Record<string, any>;
221
+ getContext(forSnapshot: 'snapshot' | 'deployment'): Record<string, any>;
263
222
  }
264
223
  export declare const DEFAULT_SYNTH_OPTIONS: {
265
224
  context: {
@@ -386,8 +345,25 @@ export declare function currentlyRecommendedAwsCdkLibFlags(): {
386
345
  "@aws-cdk/core:annotationsInValidationReport": boolean;
387
346
  "@aws-cdk/core:defaultCrossStackReferences": string;
388
347
  };
389
- export interface SnapshotAndTestDefinition {
390
- readonly testDefinition: IntegTestSuite | LegacyIntegTestSuite;
391
- readonly snapshotDirectory: string;
348
+ export interface SnapshotAssembly {
349
+ /**
350
+ * Map of stacks that are part of this assembly
351
+ */
352
+ [stackName: string]: {
353
+ /**
354
+ * All templates for this stack, including nested stacks
355
+ */
356
+ templates: {
357
+ [templateId: string]: any;
358
+ };
359
+ /**
360
+ * List of asset Ids that are used by this assembly
361
+ */
362
+ assets: string[];
363
+ };
392
364
  }
393
- //# sourceMappingURL=cdk-integ-helper.d.ts.map
365
+ /**
366
+ * Default options to pass to the CDK CLI
367
+ */
368
+ export declare const DEFAULT_ARGS: DefaultCdkOptions;
369
+ //# sourceMappingURL=cdk-test-app.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cdk-test-app.d.ts","sourceRoot":"","sources":["cdk-test-app.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,iBAAiB,EAAmB,MAAM,gCAAgC,CAAC;AAExG,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAIjG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAQ3D;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAEzB;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEzB;;;;OAIG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAE1B;;;;;OAKG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAE1C;;;;;;;OAOG;IACH,QAAQ,CAAC,2BAA2B,EAAE,MAAM,CAAC;IAE7C;;;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