Skip to content

Commit 62bd3a6

Browse files
committed
Improved the contract definition to consider tuple definitions
Making the emulator startup kill unavailable ports
1 parent 5af09f3 commit 62bd3a6

File tree

6 files changed

+45
-5
lines changed

6 files changed

+45
-5
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@muritavo/cypress-toolkit",
3-
"version": "0.8.3",
3+
"version": "0.8.4",
44
"description": "A series of utility functions for working with cypress (mainly cypress Component testing)",
55
"main": "dist/index.js",
66
"repository": "[email protected]:Muritavo/cypress-toolkit.git",
@@ -22,6 +22,7 @@
2222
],
2323
"devDependencies": {
2424
"@muritavo/webpack-microfrontend-scripts": "^0.0.22",
25+
"@types/kill-port": "^2.0.0",
2526
"@types/react": "^18.0.14",
2627
"@types/spellchecker": "^3.5.0",
2728
"@types/webpack": "^5.28.0",

src/scripts/emulator.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { spawn, ChildProcess } from "child_process";
33
import { TasksArgs } from "./tasks";
44
import { initializeApp } from "firebase-admin/app";
55
import { getAuth } from "firebase-admin/auth";
6+
import killPort from "kill-port";
67

78
const log = require("debug")("cypress-toolkit/emulator");
89
let spawnResult: {
@@ -86,14 +87,36 @@ async function startEmulatorTask(args: TasksArgs["StartEmulatorTask"]) {
8687
log("Emulator start sent message", e.toString());
8788
});
8889

90+
let scriptOutput = "";
91+
spawnResult.process.stdout!.on("data", function (data) {
92+
data = data.toString();
93+
scriptOutput += data;
94+
});
95+
8996
spawnResult.process.on("close", (e) => {
9097
clearTimeout(timeout);
9198
log("Emulator closed with", e);
92-
rej(
93-
new Error(
94-
`Emulator closed with code ${e}. Check the firebse-debug.log for more details`
95-
)
99+
const unavailablePorts = args.ports.filter((p) =>
100+
scriptOutput.includes(String(p))
96101
);
102+
const failedWithUnavailablePort = unavailablePorts.length;
103+
if (failedWithUnavailablePort) {
104+
Promise.all(unavailablePorts.map((p) => killPort(p))).then(() => {
105+
rej(
106+
new Error(
107+
`Some ports were unavailable (${unavailablePorts.join(
108+
", "
109+
)}). They were killed, please try running the application again`
110+
)
111+
);
112+
});
113+
} else {
114+
rej(
115+
new Error(
116+
`Emulator closed with code ${e}. Check the firebse-debug.log for more details`
117+
)
118+
);
119+
}
97120
spawnResult = undefined as any;
98121
});
99122
while (!breakLoop) {

src/scripts/tasks.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ export type TasksArgs = {
1111
databaseToImport?: string,
1212
UIPort: number,
1313
suiteId: string
14+
ports: number[]
1415
}
1516
}

src/support/emulator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Cypress.Commands.add(
4747
databaseToImport: databaseToImport,
4848
UIPort: emulatorConfig.emulators.ui.port || 4000,
4949
suiteId: suiteId || databaseToImport,
50+
ports: Object.values(emulatorConfig.emulators).map(a => a.port)
5051
})
5152
.then(() => {
5253
sessionStorage.setItem("last-database", databaseToImport);

types/contract.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type ExtractEvents<A extends AllABIs[number]> = A extends {
2424
type TypeOrInternalType<T> = T['internalType'] extends unknown ? T['type'] : T['internalType']
2525

2626
type MapTypeToJS<L, C> =
27+
L extends "tuple[]" ? TuplifyUnion<C[number], C[number]['name']>[] :
2728
L extends "address" | "uint256" | "uint128" | "uint8" | "string" | "bytes32"
2829
? string
2930
: L extends "bool"

yarn.lock

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2926,6 +2926,14 @@
29262926
dependencies:
29272927
"@types/node" "*"
29282928

2929+
"@types/kill-port@^2.0.0":
2930+
version "2.0.0"
2931+
resolved "https://registry.yarnpkg.com/@types/kill-port/-/kill-port-2.0.0.tgz#ba28034ace13a1444e7a3428c0a487b4e09322f2"
2932+
integrity sha512-AegaqABFauES4++49NeNX7TyZJ7t48t10+qJn4QGVGQqDogEk89M0iI4W0HXS+TEUk/hYAtEsgJ+6nyuSyYxlw==
2933+
dependencies:
2934+
"@types/node" "*"
2935+
shell-exec "^1"
2936+
29292937
"@types/level-errors@*":
29302938
version "3.0.0"
29312939
resolved "https://registry.yarnpkg.com/@types/level-errors/-/level-errors-3.0.0.tgz#15c1f4915a5ef763b51651b15e90f6dc081b96a8"
@@ -10674,6 +10682,11 @@ [email protected]:
1067410682
resolved "https://registry.yarnpkg.com/shell-exec/-/shell-exec-1.0.2.tgz#2e9361b0fde1d73f476c4b6671fa17785f696756"
1067510683
integrity sha512-jyVd+kU2X+mWKMmGhx4fpWbPsjvD53k9ivqetutVW/BQ+WIZoDoP4d8vUMGezV6saZsiNoW2f9GIhg9Dondohg==
1067610684

10685+
shell-exec@^1:
10686+
version "1.1.2"
10687+
resolved "https://registry.yarnpkg.com/shell-exec/-/shell-exec-1.1.2.tgz#d4056f96638d8406c8ab498f9f8b28938eba2dd0"
10688+
integrity sha512-v2NWVDP0ws+S7miKy2oSpJ/OuL6NKuMosPNUZLDWFBlMnBtuoZxZOwxpQJwhsFZgMb+r7frpDTT8p4OSnhkpsg==
10689+
1067710690
side-channel@^1.0.4:
1067810691
version "1.0.4"
1067910692
resolved "https://registry.yarnpkg.com/side-channel/-/side-channel-1.0.4.tgz#efce5c8fdc104ee751b25c58d4290011fa5ea2cf"

0 commit comments

Comments
 (0)