@empiricalrun/reporter
Advanced tools
Comparing version 0.6.7 to 0.7.0
# @empiricalrun/reporter | ||
## 0.7.0 | ||
### Minor Changes | ||
- 4081d81: feat: publish test-runs to db via reporter | ||
feat: support platform as an argument in create test-run api | ||
## 0.6.7 | ||
@@ -4,0 +11,0 @@ |
@@ -1,5 +0,5 @@ | ||
import { BaseReportSource } from "../sources/base"; | ||
import { BaseReportSource, Platform } from "../sources/base"; | ||
import { ReportSink } from "../types"; | ||
export declare class DashboardSink implements ReportSink { | ||
private url; | ||
private reportSummaryUrl; | ||
private runLink; | ||
@@ -9,3 +9,6 @@ private runId; | ||
private prLink?; | ||
constructor(url: string, runLink: string, runId: string, reportSource?: BaseReportSource | undefined, prLink?: string | undefined); | ||
private projectName?; | ||
private runBranch?; | ||
private plaform?; | ||
constructor(reportSummaryUrl: string, runLink: string, runId: string, reportSource?: BaseReportSource | undefined, prLink?: string | undefined, projectName?: string | undefined, runBranch?: string | undefined, plaform?: Platform | undefined); | ||
sendEndMessage(): Promise<void>; | ||
@@ -17,3 +20,4 @@ sendStartMessage(): Promise<void>; | ||
private send; | ||
sendTestRunToDb(): Promise<void>; | ||
} | ||
//# sourceMappingURL=dashboard.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DashboardSink = void 0; | ||
const utils_1 = require("../utils"); | ||
const DOMAIN = process.env.DASHBOARD_DOMAIN || "https://test-generator-dashboard.vercel.app"; | ||
class DashboardSink { | ||
url; | ||
reportSummaryUrl; | ||
runLink; | ||
@@ -11,4 +12,7 @@ runId; | ||
prLink; | ||
constructor(url, runLink, runId, reportSource, prLink) { | ||
this.url = url; | ||
projectName; | ||
runBranch; | ||
plaform; | ||
constructor(reportSummaryUrl, runLink, runId, reportSource, prLink, projectName, runBranch, plaform) { | ||
this.reportSummaryUrl = reportSummaryUrl; | ||
this.runLink = runLink; | ||
@@ -18,2 +22,5 @@ this.runId = runId; | ||
this.prLink = prLink; | ||
this.projectName = projectName; | ||
this.runBranch = runBranch; | ||
this.plaform = plaform; | ||
} | ||
@@ -90,3 +97,25 @@ async sendEndMessage() { | ||
} | ||
async sendTestRunToDb() { | ||
try { | ||
const body = JSON.stringify({ | ||
testRunId: this.runId, | ||
reportSummaryUrl: this.reportSummaryUrl, | ||
projectRepoName: (0, utils_1.buildRepoName)(this.projectName), | ||
testRunBranch: this.runBranch, | ||
platform: this.plaform, | ||
}); | ||
await fetch(`${DOMAIN}/api/test-runs`, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body, | ||
}); | ||
} | ||
catch (e) { | ||
console.error(`Error sending test-run to DB: ${e.code}`); | ||
console.error(e.message); | ||
} | ||
} | ||
} | ||
exports.DashboardSink = DashboardSink; |
import { BaseReportSource, Platform, ReportFilter } from "./base"; | ||
export declare class AppiumReportSource implements BaseReportSource { | ||
private repoName; | ||
private projectName; | ||
private runId; | ||
private platformName; | ||
srcFile: string; | ||
constructor(repoName: string, runId: string, platformName: Platform.Android | Platform.iOS); | ||
constructor(projectName: string, runId: string, platformName: Platform.Android | Platform.iOS); | ||
platform(): Platform.Android | Platform.iOS; | ||
getSummaryReportUrl(): string; | ||
reportExists(): boolean; | ||
@@ -10,0 +11,0 @@ resultsSummary(): { |
@@ -11,8 +11,8 @@ "use strict"; | ||
class AppiumReportSource { | ||
repoName; | ||
projectName; | ||
runId; | ||
platformName; | ||
srcFile = path_1.default.join(process.cwd(), "test-results", "summary.json"); | ||
constructor(repoName, runId, platformName) { | ||
this.repoName = repoName; | ||
constructor(projectName, runId, platformName) { | ||
this.projectName = projectName; | ||
this.runId = runId; | ||
@@ -24,2 +24,5 @@ this.platformName = platformName; | ||
} | ||
getSummaryReportUrl() { | ||
return `https://reports.empirical.run/${this.projectName}/${this.runId}/test-results/summary.json`; | ||
} | ||
reportExists() { | ||
@@ -51,3 +54,3 @@ return fs_1.default.existsSync(this.srcFile); | ||
buildReportLink(filter) { | ||
const base = `https://reports.empirical.run/${this.repoName}/mobile/${this.runId}/${this.platformName.toLowerCase()}/index.html`; | ||
const base = `https://reports.empirical.run/${this.projectName}/mobile/${this.runId}/${this.platformName.toLowerCase()}/index.html`; | ||
if (filter && "status" in filter) { | ||
@@ -54,0 +57,0 @@ return `${base}#?q=s:${filter.status}`; |
@@ -21,2 +21,3 @@ export type Results = { | ||
export interface BaseReportSource { | ||
getSummaryReportUrl(): string; | ||
platform(): Platform; | ||
@@ -23,0 +24,0 @@ reportExists(): boolean; |
@@ -8,7 +8,8 @@ import { BaseReportSource, FailedTestWithLink, Platform } from "./base"; | ||
export declare class PlaywrightReportSource implements BaseReportSource { | ||
private repoName; | ||
private projectName; | ||
private runId; | ||
srcFile: string; | ||
constructor(repoName: string, runId: string); | ||
constructor(projectName: string, runId: string); | ||
platform(): Platform; | ||
getSummaryReportUrl(): string; | ||
reportExists(): boolean; | ||
@@ -15,0 +16,0 @@ resultsSummary(): { |
@@ -12,7 +12,7 @@ "use strict"; | ||
class PlaywrightReportSource { | ||
repoName; | ||
projectName; | ||
runId; | ||
srcFile = path_1.default.join(process.cwd(), "test-results", "summary.json"); | ||
constructor(repoName, runId) { | ||
this.repoName = repoName; | ||
constructor(projectName, runId) { | ||
this.projectName = projectName; | ||
this.runId = runId; | ||
@@ -23,2 +23,5 @@ } | ||
} | ||
getSummaryReportUrl() { | ||
return `https://reports.empirical.run/${this.projectName}/${this.runId}/test-results/summary.json`; | ||
} | ||
reportExists() { | ||
@@ -56,3 +59,3 @@ return fs_1.default.existsSync(this.srcFile); | ||
reportLink(filter) { | ||
const base = `https://reports.empirical.run/${this.repoName}/${this.runId}/index.html`; | ||
const base = `https://reports.empirical.run/${this.projectName}/${this.runId}/index.html`; | ||
if (filter && "status" in filter) { | ||
@@ -59,0 +62,0 @@ return `${base}#?q=s:${filter.status}`; |
@@ -16,2 +16,15 @@ export declare enum WorkflowType { | ||
} | ||
export declare enum MESSAGE_TYPE { | ||
START = "start", | ||
END = "end" | ||
} | ||
export declare enum REPORT_TYPE { | ||
PLAYWRIGHT = "playwright", | ||
ANDROID = "appium:android", | ||
IOS = "appium:ios" | ||
} | ||
export declare enum HOST_NAME { | ||
SLACK_HOOKS = "hooks.slack.com", | ||
GOOGLE_CHAT = "chat.googleapis.com" | ||
} | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.WorkflowType = void 0; | ||
exports.HOST_NAME = exports.REPORT_TYPE = exports.MESSAGE_TYPE = exports.WorkflowType = void 0; | ||
var WorkflowType; | ||
@@ -9,1 +9,17 @@ (function (WorkflowType) { | ||
})(WorkflowType || (exports.WorkflowType = WorkflowType = {})); | ||
var MESSAGE_TYPE; | ||
(function (MESSAGE_TYPE) { | ||
MESSAGE_TYPE["START"] = "start"; | ||
MESSAGE_TYPE["END"] = "end"; | ||
})(MESSAGE_TYPE || (exports.MESSAGE_TYPE = MESSAGE_TYPE = {})); | ||
var REPORT_TYPE; | ||
(function (REPORT_TYPE) { | ||
REPORT_TYPE["PLAYWRIGHT"] = "playwright"; | ||
REPORT_TYPE["ANDROID"] = "appium:android"; | ||
REPORT_TYPE["IOS"] = "appium:ios"; | ||
})(REPORT_TYPE || (exports.REPORT_TYPE = REPORT_TYPE = {})); | ||
var HOST_NAME; | ||
(function (HOST_NAME) { | ||
HOST_NAME["SLACK_HOOKS"] = "hooks.slack.com"; | ||
HOST_NAME["GOOGLE_CHAT"] = "chat.googleapis.com"; | ||
})(HOST_NAME || (exports.HOST_NAME = HOST_NAME = {})); |
@@ -13,2 +13,3 @@ import { Platform } from "./sources/base"; | ||
export declare function buildGhRunLink(repoName: string, runId: string): string; | ||
export declare function buildRepoName(projectName: string): string; | ||
/** | ||
@@ -15,0 +16,0 @@ * |
@@ -6,10 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.humanReadable = humanReadable; | ||
exports.parseJsonReport = parseJsonReport; | ||
exports.cleanName = cleanName; | ||
exports.buildGhRunLink = buildGhRunLink; | ||
exports.getGhEvent = getGhEvent; | ||
exports.getGhEventPullNumber = getGhEventPullNumber; | ||
exports.isRunningForAutomatedPR = isRunningForAutomatedPR; | ||
exports.getGhEventPrLink = getGhEventPrLink; | ||
exports.getGhEventPrLink = exports.isRunningForAutomatedPR = exports.getGhEventPullNumber = exports.getGhEvent = exports.buildRepoName = exports.buildGhRunLink = exports.cleanName = exports.parseJsonReport = exports.humanReadable = void 0; | ||
const fs_1 = __importDefault(require("fs")); | ||
@@ -22,5 +15,7 @@ function humanReadable(duration) { | ||
} | ||
exports.humanReadable = humanReadable; | ||
function parseJsonReport(srcFile) { | ||
return JSON.parse(fs_1.default.readFileSync(srcFile, { encoding: "utf-8" })); | ||
} | ||
exports.parseJsonReport = parseJsonReport; | ||
function cleanName(platform) { | ||
@@ -34,2 +29,3 @@ const map = { | ||
} | ||
exports.cleanName = cleanName; | ||
/** | ||
@@ -45,2 +41,7 @@ * method to generate github action run link using `runId` and `repoName` | ||
} | ||
exports.buildGhRunLink = buildGhRunLink; | ||
function buildRepoName(projectName) { | ||
return `${projectName}-tests`; | ||
} | ||
exports.buildRepoName = buildRepoName; | ||
/** | ||
@@ -57,2 +58,3 @@ * | ||
} | ||
exports.getGhEvent = getGhEvent; | ||
/** | ||
@@ -68,2 +70,3 @@ * | ||
} | ||
exports.getGhEventPullNumber = getGhEventPullNumber; | ||
function isRunningForAutomatedPR() { | ||
@@ -77,2 +80,3 @@ const event = getGhEvent(); | ||
} | ||
exports.isRunningForAutomatedPR = isRunningForAutomatedPR; | ||
/** | ||
@@ -89,1 +93,2 @@ * | ||
} | ||
exports.getGhEventPrLink = getGhEventPrLink; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getWorkflow = getWorkflow; | ||
exports.getWorkflow = void 0; | ||
const types_1 = require("../types"); | ||
@@ -21,1 +21,2 @@ const test_generation_1 = require("./test-generation"); | ||
} | ||
exports.getWorkflow = getWorkflow; |
@@ -10,2 +10,3 @@ "use strict"; | ||
const playwright_1 = require("../sources/playwright"); | ||
const types_1 = require("../types"); | ||
const utils_1 = require("../utils"); | ||
@@ -21,16 +22,18 @@ class TestRunWorkflow { | ||
async execute() { | ||
const [messageType, repoName, runId, reportType] = this.parameters; | ||
if (!runId || !repoName) { | ||
const [messageType, projectName, runId, reportType] = this.parameters; | ||
const runBranch = process.env.GITHUB_HEAD_REF; | ||
console.log("runBranch ----------->", runBranch); | ||
if (!runId || !projectName) { | ||
throw Error("Missing arguments: runId or repoName"); | ||
} | ||
const runLink = (0, utils_1.buildGhRunLink)(repoName, runId); | ||
const runLink = (0, utils_1.buildGhRunLink)(projectName, runId); | ||
let reportSource = undefined; | ||
if (reportType == "playwright") { | ||
reportSource = new playwright_1.PlaywrightReportSource(repoName, runId); | ||
if (reportType === types_1.REPORT_TYPE.PLAYWRIGHT) { | ||
reportSource = new playwright_1.PlaywrightReportSource(projectName, runId); | ||
} | ||
else if (reportType == "appium:android") { | ||
reportSource = new appium_1.AppiumReportSource(repoName, runId, base_1.Platform.Android); | ||
else if (reportType == types_1.REPORT_TYPE.ANDROID) { | ||
reportSource = new appium_1.AppiumReportSource(projectName, runId, base_1.Platform.Android); | ||
} | ||
else if (reportType == "appium:ios") { | ||
reportSource = new appium_1.AppiumReportSource(repoName, runId, base_1.Platform.iOS); | ||
else if (reportType === types_1.REPORT_TYPE.IOS) { | ||
reportSource = new appium_1.AppiumReportSource(projectName, runId, base_1.Platform.iOS); | ||
} | ||
@@ -44,6 +47,6 @@ else { | ||
const sinkUrlStr = sinkUrl.toString(); | ||
if (sinkUrl.hostname === "hooks.slack.com") { | ||
if (sinkUrl.hostname === types_1.HOST_NAME.SLACK_HOOKS) { | ||
sinks.push(new slack_1.SlackReportSink(sinkUrlStr, runLink, runId, reportSource)); | ||
} | ||
else if (sinkUrl.hostname === "chat.googleapis.com") { | ||
else if (sinkUrl.hostname === types_1.HOST_NAME.GOOGLE_CHAT) { | ||
sinks.push(new google_1.GoogleChatReportSink(sinkUrlStr, runLink, runId, reportSource)); | ||
@@ -58,10 +61,15 @@ } | ||
} | ||
if ((0, utils_1.isRunningForAutomatedPR)()) { | ||
const prLink = (0, utils_1.getGhEventPrLink)(repoName); | ||
sinks.push(new dashboard_1.DashboardSink("", runLink, runId, reportSource, prLink)); | ||
const platform = reportSource.platform(); | ||
const summaryReportUrl = reportSource.getSummaryReportUrl(); | ||
const isAutomatedPr = (0, utils_1.isRunningForAutomatedPR)(); | ||
const prLink = isAutomatedPr ? (0, utils_1.getGhEventPrLink)(projectName) : undefined; | ||
const dashboardSinkInstance = new dashboard_1.DashboardSink(summaryReportUrl, runLink, runId, reportSource, prLink, projectName, runBranch, platform); | ||
// when test-run is triggered by a PR created by test-gen package | ||
if (isAutomatedPr) { | ||
sinks.push(dashboardSinkInstance); | ||
} | ||
if (messageType === "start") { | ||
if (messageType === types_1.MESSAGE_TYPE.START) { | ||
await Promise.all(sinks.map((s) => s.sendStartMessage())); | ||
} | ||
else if (messageType === "end") { | ||
else if (messageType === types_1.MESSAGE_TYPE.END) { | ||
if (!reportSource.reportExists()) { | ||
@@ -73,2 +81,3 @@ await Promise.all(sinks.map((s) => s.sendMessageForError())); | ||
} | ||
await dashboardSinkInstance.sendTestRunToDb(); | ||
} | ||
@@ -75,0 +84,0 @@ else { |
{ | ||
"name": "@empiricalrun/reporter", | ||
"version": "0.6.7", | ||
"version": "0.7.0", | ||
"publishConfig": { | ||
@@ -5,0 +5,0 @@ "registry": "https://registry.npmjs.org/", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
50251
1160
8
3