Skip to content

Commit fedf053

Browse files
authored
Add types for many variables (for tests) (#10632)
1 parent 5336c83 commit fedf053

6 files changed

Lines changed: 32 additions & 29 deletions

File tree

packages/e2e-tests/package.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/* Copyright 2024 Record Replay Inc. */
22

3-
const { execSync } = require("child_process");
3+
import { execSync } from "child_process";
44

5-
export function getSecret(key, region) {
5+
export function getSecret(key: string, region: string) {
66
return execSync(
77
`aws secretsmanager get-secret-value --secret-id "${key}" --region ${region} --output json --query "SecretString"`
88
)
99
.toString()
1010
.trim()
11-
.replaceAll('"', "");
11+
.replace(/"/g, "");
1212
}

packages/e2e-tests/scripts/build_products.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import fs from "fs";
55
import os from "os";
66
import path from "path";
77

8-
export function install_build_products(RUNTIME_BUILD_ID, PLATFORM, ARCHITECTURE) {
8+
export function install_build_products(RUNTIME_BUILD_ID: string, PLATFORM: string, ARCHITECTURE: string) {
99
// Set BUILD_FILE based on ARCHITECTURE and PLATFORM
1010
let BUILD_FILE;
1111
let ARCH_SUFFIX = "";

packages/e2e-tests/scripts/buildkite_run_fe_tests.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ const CONFIG = {
1717
};
1818

1919
// We use this for debugging purposes only.
20-
let TestFileOverrideList = [];
20+
let TestFileOverrideList: string[] = [];
2121

2222
// Disable some tests that we know to be problematic.
23-
const TestFileBlockLists = {
23+
const TestFileBlockLists: Record<string, string[]> = {
2424
linux: [],
2525
darwin: [
2626
// This test has been failing for a long, long time. disable it for now so
@@ -40,26 +40,26 @@ const TestFileBlockLists = {
4040

4141
const TestFileBlockList = new Set([
4242
...TestFileBlockLists["ALL"],
43-
...TestFileBlockLists[os.platform()],
43+
...(TestFileBlockLists[os.platform()] || []),
4444
]);
4545

4646
// Force some tests to run that we have recently fixed but not yet enabled everywhere.
47-
const TestFileForceLists = {
47+
const TestFileForceLists: Record<string, string[]> = {
4848
linux: [],
4949
darwin: [],
5050
ALL: [],
5151
};
5252

5353
const TestFileForceList = new Set([
5454
...TestFileForceLists["ALL"],
55-
...TestFileForceLists[os.platform()],
55+
...(TestFileForceLists[os.platform()] || []),
5656
]);
5757

5858
/**
5959
* Re-record all examples that have previously been recorded with
6060
* "recent Chromium".
6161
*/
62-
function checkReRecord(testFile, exampleFileInfo: ExampleInfo) {
62+
function checkReRecord(testFile: string, exampleFileInfo: ExampleInfo) {
6363
const wouldNormallyTest =
6464
exampleFileInfo.runtime === "chromium" &&
6565
exampleFileInfo.runtimeReleaseDate.getUTCFullYear() === 2024 &&
@@ -173,7 +173,7 @@ function gatherChromiumExamplesAndTests() {
173173

174174
// transforms https://github.com/replayio/chromium.git or
175175
// git@github.com:replayio/chromium to replayio/chromium
176-
function githubUrlToRepository(url) {
176+
function githubUrlToRepository(url: string | undefined) {
177177
return url?.replace(/.*github.com[:\/](.*)\.git/, "$1");
178178
}
179179

@@ -184,8 +184,8 @@ function testHttpConnection(
184184
const startTime = Date.now();
185185
return new Promise((resolve, reject) => {
186186
function attemptConnection() {
187-
const request = http.get(url, async res => {
188-
if (res.statusCode < 500) {
187+
const request = http.get(url, async (res: http.IncomingMessage) => {
188+
if (res.statusCode && res.statusCode < 500) {
189189
// As long as we can connect at all, we should be fine.
190190
resolve();
191191
return;
@@ -203,8 +203,8 @@ function testHttpConnection(
203203
setTimeout(attemptConnection, 1000); // Retry after 1 second
204204
});
205205

206-
request.on("error", (err: Error) => {
207-
if (err["code"] === "ECONNREFUSED") {
206+
request.on("error", (err: Error & { code?: string }) => {
207+
if (err.code === "ECONNREFUSED") {
208208
if (Date.now() - startTime >= timeoutMs) {
209209
reject(new Error(`Failed to connect to the server within ${timeoutMs / 1000} seconds`));
210210
return;
@@ -225,7 +225,7 @@ function testHttpConnection(
225225
}
226226

227227
export default async function run_fe_tests(
228-
CHROME_BINARY_PATH,
228+
CHROME_BINARY_PATH: string | undefined,
229229
runInCI = true,
230230
nWorkers = 4,
231231
testOverrides?: string[]

packages/e2e-tests/scripts/buildkite_run_tests_from_reason.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ function run_fe_tests_from_build_id(os: string, arch: string, runtimeBuildId: st
2424
run_fe_tests(CHROME_BINARY_PATH);
2525
}
2626

27-
function buildUrl(pipelineSlug, buildNumber) {
27+
function buildUrl(pipelineSlug: string, buildNumber: string | number) {
2828
return `https://buildkite.com/replay/${pipelineSlug}/builds/${buildNumber}`;
2929
}
3030

31-
function describeReason(markdownMessage, rebuild) {
31+
function describeReason(markdownMessage: string, rebuild?: boolean) {
3232
// do something with `rebuild` here...
3333
execSync(`buildkite-agent annotate --style info "${markdownMessage}"`, {
3434
stdio: "inherit",
3535
});
3636
}
3737

38-
export async function build_from_reason(os, arch) {
38+
export async function build_from_reason(os: string, arch: string) {
3939
const buildReason = await detectAndRecordBuildReason();
4040

4141
if (!process.env.BUILDKITE_TOKEN) {
@@ -46,7 +46,7 @@ export async function build_from_reason(os, arch) {
4646
case "runtime-chromium-build-id": {
4747
describeReason(
4848
`Testing against chromium buildid ${buildReason.chromiumBuildId}`,
49-
buildReason.rebuild
49+
buildReason.rebuild ?? false
5050
);
5151
run_fe_tests_from_build_id(os, arch, buildReason.chromiumBuildId);
5252
break;
@@ -57,7 +57,7 @@ export async function build_from_reason(os, arch) {
5757
"chromium-build",
5858
buildReason.buildNumber
5959
)})`,
60-
buildReason.rebuild
60+
buildReason.rebuild ?? false
6161
);
6262
const runtimeBuildId = await fetchRuntimeBuildIdFromChromiumBuildNumber(
6363
os,
@@ -81,7 +81,7 @@ export async function build_from_reason(os, arch) {
8181
`Testing against latest chromium build on branch \\\`${
8282
buildReason.branch
8383
}\\\`: [#${buildNumber}](${buildUrl("chromium-build", buildNumber)})`,
84-
buildReason.rebuild
84+
buildReason.rebuild ?? false
8585
);
8686
const runtimeBuildId = await fetchRuntimeBuildIdFromChromiumBuildId(os, arch, buildId);
8787
run_fe_tests_from_build_id(os, arch, runtimeBuildId);
@@ -93,7 +93,7 @@ export async function build_from_reason(os, arch) {
9393
buildReason.pipelineSlug,
9494
buildReason.buildNumber
9595
)})`,
96-
buildReason.rebuild
96+
buildReason.rebuild ?? false
9797
);
9898
const runtimeBuildId = await fetchRuntimeBuildIdFromChromiumBuildId(
9999
os,

packages/e2e-tests/scripts/detect_and_record_build_reason.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ export async function detectAndRecordBuildReason() {
113113
if (BUILDKITE_TRIGGERED_FROM_BUILD_ID) {
114114
// if we're running due to a triggered build, record that info in an artifact.
115115
// we assume if BUILDKITE_TRIGGERED_FROM_BUILD_ID is set, then the other two are also set.
116+
if (!BUILDKITE_TRIGGERED_FROM_BUILD_PIPELINE_SLUG || !BUILDKITE_TRIGGERED_FROM_BUILD_NUMBER) {
117+
throw new Error("Missing required environment variables for triggered build");
118+
}
116119
return await storeTriggeredBuildReason(
117120
BUILDKITE_TRIGGERED_FROM_BUILD_PIPELINE_SLUG,
118121
parseInt(BUILDKITE_TRIGGERED_FROM_BUILD_NUMBER),
@@ -191,7 +194,7 @@ async function graphql<ResultT, VariablesT = Record<string, unknown>>(
191194

192195
// apparently we wouldn't need this function (and could use the buildkite-agent cli directly) if
193196
// we upgraded (there's `buildkite-agent build ...`?)
194-
export async function fetchLatestChromiumBuildOnBranch(token, branch) {
197+
export async function fetchLatestChromiumBuildOnBranch(token: string, branch: string) {
195198
type VariablesType = {
196199
branch: string;
197200
};
@@ -233,11 +236,11 @@ export async function fetchLatestChromiumBuildOnBranch(token, branch) {
233236
};
234237
}
235238

236-
export async function fetchRuntimeBuildIdFromChromiumBuildId(os, arch, buildId) {
239+
export async function fetchRuntimeBuildIdFromChromiumBuildId(os: string, arch: string, buildId: string) {
237240
return fetchArtifactContents(buildId, path.join("build_id", os, arch, "build_id"));
238241
}
239242

240-
export async function fetchRuntimeBuildIdFromChromiumBuildNumber(os, arch, buildNumber) {
243+
export async function fetchRuntimeBuildIdFromChromiumBuildNumber(os: string, arch: string, buildNumber: number) {
241244
const pageSize = 25;
242245

243246
// fetch the first page of builds
@@ -324,13 +327,13 @@ export async function fetchRuntimeBuildIdFromChromiumBuildNumber(os, arch, build
324327
throw new Error("did not find build number");
325328
}
326329

327-
async function fetchArtifactContents(buildId, artifactPath) {
330+
async function fetchArtifactContents(buildId: string, artifactPath: string) {
328331
execSync(`buildkite-agent artifact download ${artifactPath} . --build ` + buildId);
329332

330333
return fs.readFileSync(artifactPath, "utf8").trim();
331334
}
332335

333-
async function uploadArtifactContents(artifactPath, contents, contentType) {
336+
async function uploadArtifactContents(artifactPath: string, contents: string, contentType: string) {
334337
fs.writeFileSync(artifactPath, contents);
335338
execSync(`buildkite-agent artifact upload --content-type ${contentType} ${artifactPath}`);
336339
}

0 commit comments

Comments
 (0)