Skip to content
This repository has been archived by the owner on Dec 26, 2023. It is now read-only.

Commit

Permalink
fix reporting error without a path
Browse files Browse the repository at this point in the history
  • Loading branch information
paulpach committed Apr 8, 2020
1 parent 8f1a352 commit 118ecfe
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 45 deletions.
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ jobs:
with:
path: '__tests__/*.xml'
access-token: ${{secrets.GITHUB_TOKEN}}
numFailures: 5
31 changes: 12 additions & 19 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2256,33 +2256,22 @@ function getLocation(stacktrace) {
function testCaseAnnotation(testcase) {
const [filename, lineno] = 'stack-trace' in testcase.failure
? getLocation(testcase.failure['stack-trace'])
: ['', 0];
: ['unknown', 0];
const sanitizedFilename = filename.replace(/^\/github\/workspace\//, '');
const message = testcase.failure.message;
const classname = testcase.classname;
const methodname = testcase.methodname;
const stacktrace = 'stack-trace' in testcase.failure
? testcase.failure['stack-trace'].substring(0, 65536)
: '';
return new Annotation(sanitizedFilename, lineno, lineno, 0, 0, 'failure', `Failed test ${methodname} in ${classname}`, 'message', stacktrace);
return new Annotation(sanitizedFilename, lineno, lineno, 0, 0, 'failure', `Failed test ${methodname} in ${classname}`, message, stacktrace);
}
exports.testCaseAnnotation = testCaseAnnotation;
function testCaseDetails(testcase) {
const message = testcase.failure.message;
const classname = testcase.classname;
const methodname = testcase.methodname;
const stacktrace = 'stack-trace' in testcase.failure
? testcase.failure['stack-trace'].substring(0, 65536)
: '';
return `* Failed test ${methodname} in ${classname}\n${message}\n\`\`\`${stacktrace}\`\`\``;
}
exports.testCaseDetails = testCaseDetails;
class TestResult {
constructor(passed, failed, annotations, details) {
constructor(passed, failed, annotations) {
this.passed = passed;
this.failed = failed;
this.annotations = annotations;
this.details = details;
}
}
exports.TestResult = TestResult;
Expand Down Expand Up @@ -2314,15 +2303,14 @@ async function parseNunit(nunitReport) {
const testCases = getTestCases(testRun);
const failedCases = testCases.filter(tc => tc.result === "Failed");
const annotations = failedCases.map(testCaseAnnotation);
const details = failedCases.map(testCaseDetails).join("\n");
return new TestResult(parseInt(testRun.passed), parseInt(testRun.failed), annotations, details);
return new TestResult(parseInt(testRun.passed), parseInt(testRun.failed), annotations);
}
exports.parseNunit = parseNunit;
function combine(result1, result2) {
const passed = result1.passed + result2.passed;
const failed = result1.failed + result2.failed;
const annotations = result1.annotations.concat(result2.annotations);
return new TestResult(passed, failed, annotations, `${result1.details}\n${result2.details}`);
return new TestResult(passed, failed, annotations);
}
async function* resultGenerator(path) {
const globber = await glob_1.create(path, { followSymbolicLinks: false });
Expand All @@ -2332,7 +2320,7 @@ async function* resultGenerator(path) {
}
}
async function readResults(path) {
let results = new TestResult(0, 0, [], '');
let results = new TestResult(0, 0, []);
for await (const result of resultGenerator(path))
results = combine(results, result);
return results;
Expand Down Expand Up @@ -5052,13 +5040,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = __webpack_require__(470);
const github_1 = __webpack_require__(469);
const nunit_1 = __webpack_require__(81);
function generateSummary(annotation) {
return `* ${annotation.title}\n ${annotation.message}`;
}
async function run() {
try {
const path = core_1.getInput('path');
const numFailures = parseInt(core_1.getInput('numFailures'));
const accessToken = core_1.getInput('access-token');
const results = await nunit_1.readResults(path);
const octokit = new github_1.GitHub(accessToken);
const testSummary = results.annotations.map(generateSummary).join("\n");
const summary = results.failed > 0
? `${results.failed} tests failed`
: `${results.passed} tests passed`;
Expand All @@ -5068,7 +5060,8 @@ async function run() {
**${results.passed} tests passed**
**${results.failed} tests failed**

${results.details}
${testSummary}
}
`;
const request = {
head_sha: github_1.context.sha,
Expand Down
13 changes: 11 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import {setFailed, getInput} from '@actions/core'
import {GitHub, context} from '@actions/github'
import {readResults} from './nunit'
import {readResults, Annotation} from './nunit'


function generateSummary(annotation: Annotation): string {
return `* ${annotation.title}\n ${annotation.message}`
}


async function run(): Promise<void> {
try {
Expand All @@ -12,6 +18,8 @@ async function run(): Promise<void> {

const octokit = new GitHub(accessToken)

const testSummary = results.annotations.map(generateSummary).join("\n")

const summary =
results.failed > 0
? `${results.failed} tests failed`
Expand All @@ -24,7 +32,8 @@ async function run(): Promise<void> {
**${results.passed} tests passed**
**${results.failed} tests failed**
${results.details}
${testSummary}
}
`

const request = {
Expand Down
30 changes: 7 additions & 23 deletions src/nunit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function testCaseAnnotation(testcase: any): Annotation {
const [filename, lineno] =
'stack-trace' in testcase.failure
? getLocation(testcase.failure['stack-trace'])
: ['', 0]
: ['unknown', 0]

const sanitizedFilename = filename.replace(/^\/github\/workspace\//, '')
const message = testcase.failure.message
Expand All @@ -60,30 +60,16 @@ export function testCaseAnnotation(testcase: any): Annotation {
0,
'failure',
`Failed test ${methodname} in ${classname}`,
'message',
message,
stacktrace
)
}

export function testCaseDetails(testcase: any): string {

const message = testcase.failure.message
const classname = testcase.classname
const methodname = testcase.methodname

const stacktrace = 'stack-trace' in testcase.failure
? testcase.failure['stack-trace'].substring(0, 65536)
: '';

return `* Failed test ${methodname} in ${classname}\n${message}\n\`\`\`${stacktrace}\`\`\``
}

export class TestResult {
public constructor(
public readonly passed: number,
public readonly failed: number,
public readonly annotations: Annotation[],
public readonly details: string
public readonly annotations: Annotation[]
) { }
}

Expand Down Expand Up @@ -125,14 +111,12 @@ export async function parseNunit(nunitReport: string): Promise<TestResult> {
const testCases = getTestCases(testRun);
const failedCases = testCases.filter(tc => tc.result === "Failed")

const annotations = failedCases.map(testCaseAnnotation);
const details = failedCases.map(testCaseDetails).join("\n");
const annotations = failedCases.map(testCaseAnnotation)

return new TestResult(
parseInt(testRun.passed),
parseInt(testRun.failed),
annotations,
details
annotations
)
}

Expand All @@ -141,7 +125,7 @@ function combine(result1: TestResult, result2: TestResult): TestResult {
const failed = result1.failed + result2.failed
const annotations = result1.annotations.concat(result2.annotations)

return new TestResult(passed, failed, annotations, `${result1.details}\n${result2.details}`)
return new TestResult(passed, failed, annotations)
}

async function* resultGenerator(path: string): AsyncGenerator<TestResult> {
Expand All @@ -154,7 +138,7 @@ async function* resultGenerator(path: string): AsyncGenerator<TestResult> {
}

export async function readResults(path: string): Promise<TestResult> {
let results = new TestResult(0, 0, [], '')
let results = new TestResult(0, 0, [])

for await (const result of resultGenerator(path))
results = combine(results, result)
Expand Down

0 comments on commit 118ecfe

Please sign in to comment.