@wolsok/nx-aws-cdk-v2 4.2.0 → 4.2.2
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.
- package/package.json +1 -1
- package/src/utils/testing.d.ts +18 -0
- package/src/utils/testing.js +30 -0
- package/src/utils/testing.js.map +1 -1
package/package.json
CHANGED
package/src/utils/testing.d.ts
CHANGED
|
@@ -1,2 +1,20 @@
|
|
|
1
|
+
import type { ChildProcess } from 'child_process';
|
|
1
2
|
import { ExecutorContext } from '@nx/devkit';
|
|
2
3
|
export declare function mockExecutorContext(executorName: string, workspaceVersion?: number): ExecutorContext;
|
|
4
|
+
/** A mock implementation for `exec` that hands out a new `FakeChildProcess`. */
|
|
5
|
+
export declare function spawnFakeChildProcess(): ChildProcess;
|
|
6
|
+
/** The part of a mocked `exec` that tells which processes it returned. */
|
|
7
|
+
interface SpawningMock {
|
|
8
|
+
mock: {
|
|
9
|
+
results: ReadonlyArray<{
|
|
10
|
+
value: unknown;
|
|
11
|
+
}>;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Starts an executor, then lets the process the mocked `exec` spawned last
|
|
16
|
+
* close with `exitCode`, and returns the executor's result. The executor has
|
|
17
|
+
* to call `exec` before its first `await`, as `runCommandProcess` does.
|
|
18
|
+
*/
|
|
19
|
+
export declare function runExecutorToExit<T>(exec: SpawningMock, run: () => Promise<T>, exitCode?: number): Promise<T>;
|
|
20
|
+
export {};
|
package/src/utils/testing.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.mockExecutorContext = mockExecutorContext;
|
|
4
|
+
exports.spawnFakeChildProcess = spawnFakeChildProcess;
|
|
5
|
+
exports.runExecutorToExit = runExecutorToExit;
|
|
6
|
+
const events_1 = require("events");
|
|
4
7
|
function mockExecutorContext(executorName, workspaceVersion = 2) {
|
|
5
8
|
return {
|
|
6
9
|
projectName: 'proj',
|
|
@@ -27,4 +30,31 @@ function mockExecutorContext(executorName, workspaceVersion = 2) {
|
|
|
27
30
|
isVerbose: true,
|
|
28
31
|
};
|
|
29
32
|
}
|
|
33
|
+
/** Stands in for the cdk process a mocked `child_process.exec` spawns. */
|
|
34
|
+
class FakeChildProcess extends events_1.EventEmitter {
|
|
35
|
+
constructor() {
|
|
36
|
+
super(...arguments);
|
|
37
|
+
this.stdout = new events_1.EventEmitter();
|
|
38
|
+
this.stderr = new events_1.EventEmitter();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** A mock implementation for `exec` that hands out a new `FakeChildProcess`. */
|
|
42
|
+
function spawnFakeChildProcess() {
|
|
43
|
+
return new FakeChildProcess();
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Starts an executor, then lets the process the mocked `exec` spawned last
|
|
47
|
+
* close with `exitCode`, and returns the executor's result. The executor has
|
|
48
|
+
* to call `exec` before its first `await`, as `runCommandProcess` does.
|
|
49
|
+
*/
|
|
50
|
+
async function runExecutorToExit(exec, run, exitCode = 0) {
|
|
51
|
+
const result = run();
|
|
52
|
+
const spawned = exec.mock.results.at(-1)?.value;
|
|
53
|
+
if (!(spawned instanceof FakeChildProcess)) {
|
|
54
|
+
await result;
|
|
55
|
+
throw new Error('The executor spawned no FakeChildProcess through exec.');
|
|
56
|
+
}
|
|
57
|
+
spawned.emit('close', exitCode);
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
30
60
|
//# sourceMappingURL=testing.js.map
|
package/src/utils/testing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../../../../../../libs/public/nx-aws-cdk-v2/src/utils/testing.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../../../../../../libs/public/nx-aws-cdk-v2/src/utils/testing.ts"],"names":[],"mappings":";;AAKA,kDA4B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