Android Instrumentation Tests Improvements (#2321)

This commit is contained in:
Bart Louwers
2024-04-29 16:02:46 +02:00
committed by GitHub
parent cd9727b06f
commit 3e1868bc26
17 changed files with 141 additions and 59 deletions

View File

@@ -0,0 +1,7 @@
import {
DeviceFarmClient,
} from "@aws-sdk/client-device-farm";
export function getDeviceFarmClient() {
return new DeviceFarmClient({ region: "us-west-2" });
}

View File

@@ -6,11 +6,12 @@ import https from "node:https";
import readline from "node:readline";
import {
DeviceFarmClient,
ListJobsCommand,
ListArtifactsCommand,
} from "@aws-sdk/client-device-farm";
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
import { PutObjectCommand } from "@aws-sdk/client-s3";
import { getDeviceFarmClient } from "./device-farm-client.mjs";
import { getS3Client } from "./s3-client.mjs";
/**
* Retrieves a log file and looks for the line that includes the benchmark results.
@@ -46,7 +47,7 @@ function usage() {
process.exit(1);
}
const deviceFarmClient = new DeviceFarmClient({ region: "us-west-2" });
const deviceFarmClient = getDeviceFarmClient();
if (process.argv.length !== 3) usage();
@@ -103,9 +104,7 @@ const benchmarkResults = benchmarkResultLogLines
.filter((line) => !!line)
.map((jsonVal) => JSON.parse(jsonVal));
const s3Client = new S3Client({
region: "eu-central-1",
});
const s3Client = getS3Client();
// store benchmark results as JSON files on S3
await Promise.all(

View File

@@ -0,0 +1,47 @@
import { ListArtifactsCommand } from "@aws-sdk/client-device-farm";
import { getDeviceFarmClient } from "./device-farm-client.mjs";
/**
* @returns {never}
*/
function usage() {
console.error("Logs test spec output from AWS Device Farm");
console.error(`Usage: node ${process.argv.at(1)} RUN_ARN`);
process.exit(1);
}
if (process.argv.length !== 3) usage();
const arn = process.argv.at(2);
if (typeof arn !== 'string') usage();
const deviceFarmClient = getDeviceFarmClient();
/**
* Looks for the run with the provided ARN and returns the test spec output.
*
* @param {string} arn
* @returns string
*/
async function getTestSpecOutput(arn) {
const logs = await deviceFarmClient.send(new ListArtifactsCommand({
arn,
type: 'FILE'
}));
for (const artifact of logs.artifacts || []) {
if (artifact.type === 'TESTSPEC_OUTPUT' && artifact.url) {
return await (await fetch(artifact.url)).text();
}
}
return "";
}
const testSpecOutput = await getTestSpecOutput(arn);
if (!testSpecOutput) {
console.error(`Test spec output for run '${arn}' not found`);
}
console.log(testSpecOutput);

View File

@@ -0,0 +1,7 @@
import { S3Client } from "@aws-sdk/client-s3";
export function getS3Client() {
return new S3Client({
region: "eu-central-1",
});
}