Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
npm run build
npm run test
- name: Create test summary
uses: ./bin
uses: ./dist
with:
paths: test/results/*.xml
output: test/results/results.html
Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:
run: |
npm ci
npm run build
npm run pack
npm run package

cp action.yml dist/
cp README.md dist/
Expand Down
37 changes: 10 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "test-summary",
"version": "0.0.1",
"private": true,
"type": "module",
"description": "Display test results in a GitHub Actions workflow",
"main": "dist/index.js",
"exports": {
Expand All @@ -12,9 +13,9 @@
"format": "prettier --write **/*.ts",
"lint": "eslint src/**/*.ts",
"package": "npx rimraf ./dist && npx rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript",
"test": "mocha -r ts-node/register --reporter mocha-multi-reporters --reporter-options configFile=test/config.json test/**/*.ts",
"test": "node --loader ts-node/esm ./node_modules/mocha/bin/mocha --reporter mocha-multi-reporters --reporter-options configFile=test/config.json test/**/*.ts",
"clean": "rm -rf dist",
"all": "npm run build && npm run lint && npm run pack && npm test"
"all": "npm run build && npm run lint && npm run package && npm test"
},
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions src/dashboard.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import escapeHTML from "./escape_html"
import { TestResult, TestStatus } from "./test_parser"
import escapeHTML from "./escape_html.js"
import { TestResult, TestStatus } from "./test_parser.js"

const dashboardUrl = "https://svg.test-summary.com/dashboard.svg"
const passIconUrl = "https://svg.test-summary.com/icon/pass.svg?s=12"
Expand Down
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import * as util from "util"
import * as core from "@actions/core"
import * as glob from "glob"

import { TestResult, TestStatus, parseFile } from "./test_parser"
import { dashboardResults, dashboardSummary } from "./dashboard"
import { TestStatus, parseFile } from "./test_parser.js"
import type { TestResult } from "./test_parser.js"
import { dashboardResults, dashboardSummary } from "./dashboard.js"

async function run(): Promise<void> {
try {
Expand Down
23 changes: 18 additions & 5 deletions src/test_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ export interface TestCase {
duration?: string
}

function normalizeNewlines(value: unknown): string | undefined {
if (value === null || value === undefined) return undefined
if (typeof value === "string") return value.replace(/\r\n/g, "\n")
if (typeof value === "object") {
const v = value as any
if ("_" in v && typeof v._ === "string") {
return v._.replace(/\r\n/g, "\n")
}
}
return String(value).replace(/\r\n/g, "\n")
}

export async function parseTap(data: string): Promise<TestResult> {
const lines = data.trim().split(/\r?\n/)
// let version = 12
Expand Down Expand Up @@ -257,9 +269,9 @@ async function parseJunitXml(xml: any): Promise<TestResult> {

message = element.$ ? element.$.message : undefined
if (typeof element === "string") {
details = element
details = normalizeNewlines(element)
} else {
details = element._
details = normalizeNewlines(element._)
}

counts.failed++
Expand Down Expand Up @@ -335,16 +347,17 @@ export async function parseTrx(xml: any): Promise<TestResult> {
let details: string = ""

const output = item?.Output?.[0]
details = "StdOut:" + output?.StdOut?.[0]
details = `StdOut:${normalizeNewlines(output?.StdOut?.[0]) ?? ""}`

if (outcome == "Passed") {
counts.passed++
} else if (outcome == "Failed") {
status = TestStatus.Fail
counts.failed++

message = output?.ErrorInfo?.[0]?.Message
details = "StackTrace:" + output?.ErrorInfo?.[0]?.StackTrace + '\n' + details
message = normalizeNewlines(output?.ErrorInfo?.[0]?.Message) ?? undefined
details = normalizeNewlines(`StackTrace:${output?.ErrorInfo?.[0]?.StackTrace ?? ""}\n${details}`) ?? details

} else {
status = TestStatus.Pass
counts.skipped++
Expand Down
6 changes: 4 additions & 2 deletions test/dashboard.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/// <reference types="mocha" />
import { expect } from "chai"

import { TestStatus, TestResult } from "../src/test_parser"
import { dashboardResults } from "../src/dashboard"
import { TestStatus } from "../src/test_parser.js"
import type { TestResult } from "../src/test_parser.js"
import { dashboardResults } from "../src/dashboard.js"

describe("dashboard", async () => {
it("escapes HTML entities", async () => {
Expand Down
12 changes: 7 additions & 5 deletions test/file.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import * as chai from "chai"
import chaiAsPromised from 'chai-as-promised'
import { expect } from "chai"

import { TestStatus, parseFile } from "../src/test_parser"
import {dirname, join} from "path"
import { parseFile } from "../src/test_parser.js"
import { fileURLToPath } from "node:url"

chai.use(chaiAsPromised)

const tapResourcePath = `${__dirname}/resources/tap`
const junitResourcePath = `${__dirname}/resources/junit`
const trxResourcePath = `${__dirname}/resources/trx`
const currentDir = dirname(fileURLToPath(import.meta.url))
const tapResourcePath = join(currentDir, "resources/tap")
const junitResourcePath = join(currentDir, "resources/junit")
const trxResourcePath = join(currentDir, "resources/trx")

describe("file", async () => {
it("identifies common tap", async () => {
Expand Down
8 changes: 5 additions & 3 deletions test/junit.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import * as chai from "chai"
import { expect } from "chai"

import { TestStatus, parseJunitFile } from "../src/test_parser"
import { TestStatus, parseJunitFile } from "../src/test_parser.js"
import {dirname, join} from "path"
import { fileURLToPath } from "node:url"

const resourcePath = `${__dirname}/resources/junit`
const currentDir = dirname(fileURLToPath(import.meta.url))
const resourcePath = join(currentDir, "resources/junit")

describe("junit", async () => {
it("parses common", async () => {
Expand Down
8 changes: 5 additions & 3 deletions test/tap.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import * as chai from "chai"
import chaiAsPromised from 'chai-as-promised'
import { expect } from "chai"

import { TestStatus, parseTapFile } from "../src/test_parser"
import { TestStatus, parseTapFile } from "../src/test_parser.js"
import { dirname, join } from "path"
import { fileURLToPath } from "url"

chai.use(chaiAsPromised)

const resourcePath = `${__dirname}/resources/tap`
const currentDir = dirname(fileURLToPath(import.meta.url))
const resourcePath = join(currentDir, "resources/tap")

describe("tap", async () => {
it("parses common", async () => {
Expand Down
8 changes: 5 additions & 3 deletions test/trx.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import * as chai from "chai"
import { expect } from "chai"

import * as fs from "fs"
import * as util from "util"

import xml2js from "xml2js"
import {dirname, join} from "path"
import { fileURLToPath } from "url"

import { TestStatus, parseTrx } from "../src/test_parser"
import { TestStatus, parseTrx } from "../src/test_parser.js"

const resourcePath = `${__dirname}/resources/trx`
const currentDir = dirname(fileURLToPath(import.meta.url))
const resourcePath = join(currentDir, "resources/trx")

async function parseTrxFile(filename: string) {
const readfile = util.promisify(fs.readFile)
Expand Down