Add test cases
parent
0e1590dc44
commit
0eb0132878
File diff suppressed because one or more lines are too long
|
@ -16,6 +16,7 @@
|
|||
"@actions/core": "^1.2.6",
|
||||
"@actions/exec": "1.0.4",
|
||||
"@actions/github": "^4.0.0",
|
||||
"@octokit/types": "6.10.1",
|
||||
"handlebars": "4.7.7",
|
||||
"xml-js": "1.6.11"
|
||||
},
|
||||
|
|
|
@ -4,10 +4,17 @@ import * as fs from 'fs';
|
|||
import path from 'path';
|
||||
import Handlebars from 'handlebars';
|
||||
import ResultsParser from './results-parser';
|
||||
import { RunMeta } from './ts/meta.ts';
|
||||
import { RunMeta } from './ts/results-meta.ts';
|
||||
|
||||
class ResultsCheck {
|
||||
static async createCheck(artifactsPath, checkName, githubToken) {
|
||||
// Validate input
|
||||
if (!artifactsPath || !checkName || !githubToken) {
|
||||
throw new Error(
|
||||
`Missing input! {"artifactsPath": "${artifactsPath}", "checkName": "${checkName}", "githubToken": "${githubToken}`,
|
||||
);
|
||||
}
|
||||
|
||||
// Parse all results files
|
||||
const runs = [];
|
||||
const files = fs.readdirSync(artifactsPath);
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
import ResultsCheck from './results-check';
|
||||
|
||||
describe('ResultsCheck', () => {
|
||||
describe('createCheck', () => {
|
||||
it('throws for missing input', () => {
|
||||
expect(() => ResultsCheck.createCheck('', '', '')).rejects.toEqual(Error);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -2,10 +2,14 @@ import * as core from '@actions/core';
|
|||
import * as xmljs from 'xml-js';
|
||||
import * as fs from 'fs';
|
||||
import path from 'path';
|
||||
import { RunMeta, TestMeta } from './ts/meta.ts';
|
||||
import { RunMeta, TestMeta } from './ts/results-meta.ts';
|
||||
|
||||
class ResultsParser {
|
||||
static async parseResults(filepath) {
|
||||
if (!fs.existsSync(filepath)) {
|
||||
throw new Error(`Missing file! {"filepath": "${filepath}"}`);
|
||||
}
|
||||
|
||||
core.info(`Trying to open ${filepath}`);
|
||||
const file = await fs.promises.readFile(filepath, 'utf8');
|
||||
const results = xmljs.xml2js(file, { compact: true });
|
||||
|
@ -66,7 +70,8 @@ class ResultsParser {
|
|||
}
|
||||
|
||||
static convertTestCase(suite, testCase) {
|
||||
const { name, fullname, result, failure, duration } = testCase._attributes;
|
||||
const { _attributes, failure } = testCase;
|
||||
const { name, fullname, result, duration } = _attributes;
|
||||
const testMeta = new TestMeta(suite, name);
|
||||
testMeta.result = result;
|
||||
testMeta.duration = Number(duration);
|
||||
|
@ -82,11 +87,10 @@ class ResultsParser {
|
|||
return testMeta;
|
||||
}
|
||||
|
||||
const trace = failure['stack-trace'].cdata;
|
||||
const trace = failure['stack-trace']._cdata;
|
||||
const point = ResultsParser.findAnnotationPoint(trace);
|
||||
if (point === undefined) {
|
||||
core.warning('Not able to find entry point for failed test! Test trace:');
|
||||
core.warning(trace);
|
||||
if (!point.path || !point.line) {
|
||||
core.warning(`Not able to find annotation point for failed test! Test trace: ${trace}`);
|
||||
return testMeta;
|
||||
}
|
||||
|
||||
|
@ -108,8 +112,8 @@ class ResultsParser {
|
|||
static findAnnotationPoint(trace) {
|
||||
const match = trace.match(/at .* in ((?<path>[^:]+):(?<line>\d+))/);
|
||||
return {
|
||||
path: match.groups.path,
|
||||
line: Number(match.groups.line),
|
||||
path: match ? match.groups.path : '',
|
||||
line: match ? Number(match.groups.line) : 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,181 @@
|
|||
import ResultsParser from './results-parser';
|
||||
|
||||
describe('ResultsParser', () => {
|
||||
describe('parseResults', () => {
|
||||
it('throws for missing file', () => {
|
||||
expect(() => ResultsParser.parseResults('')).rejects.toEqual(Error);
|
||||
});
|
||||
});
|
||||
|
||||
describe('convertSuite', () => {
|
||||
test('convert single', () => {
|
||||
const targetSuite = {
|
||||
_attributes: {
|
||||
fullname: 'Suite Full Name',
|
||||
},
|
||||
'test-case': [{ _attributes: { name: 'testA' } }, { _attributes: { name: 'testB' } }],
|
||||
'test-suite': [
|
||||
{
|
||||
_attributes: {
|
||||
fullname: 'Inner Suite Full Name',
|
||||
},
|
||||
'test-case': { _attributes: { name: 'testC' } },
|
||||
'test-suite': [],
|
||||
},
|
||||
],
|
||||
};
|
||||
const result = ResultsParser.convertSuite(targetSuite);
|
||||
|
||||
expect(result).toMatchObject([
|
||||
[
|
||||
{
|
||||
annotation: undefined,
|
||||
duration: Number.NaN,
|
||||
result: undefined,
|
||||
suite: 'Inner Suite Full Name',
|
||||
title: 'testC',
|
||||
},
|
||||
],
|
||||
{
|
||||
annotation: undefined,
|
||||
duration: Number.NaN,
|
||||
result: undefined,
|
||||
suite: 'Suite Full Name',
|
||||
title: 'testA',
|
||||
},
|
||||
{
|
||||
annotation: undefined,
|
||||
duration: Number.NaN,
|
||||
result: undefined,
|
||||
suite: 'Suite Full Name',
|
||||
title: 'testB',
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('convertTests', () => {
|
||||
test('convert array', () => {
|
||||
const testA = { _attributes: { name: 'testA' } };
|
||||
const testB = { _attributes: { name: 'testB' } };
|
||||
const testResult = [testA, testB];
|
||||
const result = ResultsParser.convertTests('Test Suite', testResult);
|
||||
|
||||
expect(result).toMatchObject([
|
||||
{ suite: 'Test Suite', title: 'testA' },
|
||||
{ suite: 'Test Suite', title: 'testB' },
|
||||
]);
|
||||
});
|
||||
|
||||
test('convert single', () => {
|
||||
const testA = { _attributes: { name: 'testA' } };
|
||||
const result = ResultsParser.convertTests('Test Suite', testA);
|
||||
|
||||
expect(result).toMatchObject([{ suite: 'Test Suite', title: 'testA' }]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('convertTestCase', () => {
|
||||
test('not failed', () => {
|
||||
const result = ResultsParser.convertTestCase('Test Suite', {
|
||||
_attributes: {
|
||||
name: 'Test Name',
|
||||
duration: '3.14',
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.suite).toBe('Test Suite');
|
||||
expect(result.title).toBe('Test Name');
|
||||
expect(result.duration).toBe(3.14);
|
||||
expect(result.annotation).toBeUndefined();
|
||||
});
|
||||
|
||||
test('no stack trace', () => {
|
||||
const result = ResultsParser.convertTestCase('Test Suite', {
|
||||
_attributes: {
|
||||
name: 'Test Name',
|
||||
duration: '3.14',
|
||||
},
|
||||
failure: {
|
||||
message: { _cdata: 'Message CDATA' },
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.suite).toBe('Test Suite');
|
||||
expect(result.title).toBe('Test Name');
|
||||
expect(result.duration).toBe(3.14);
|
||||
expect(result.annotation).toBeUndefined();
|
||||
});
|
||||
|
||||
test('no annotation path', () => {
|
||||
const result = ResultsParser.convertTestCase('Test Suite', {
|
||||
_attributes: {
|
||||
name: 'Test Name',
|
||||
duration: '3.14',
|
||||
},
|
||||
failure: {
|
||||
message: { _cdata: 'Message CDATA' },
|
||||
'stack-trace': { _cdata: 'Test CDATA' },
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.suite).toBe('Test Suite');
|
||||
expect(result.title).toBe('Test Name');
|
||||
expect(result.duration).toBe(3.14);
|
||||
expect(result.annotation).toBeUndefined();
|
||||
});
|
||||
|
||||
test('prepare annotation', () => {
|
||||
const result = ResultsParser.convertTestCase('Test Suite', {
|
||||
_attributes: {
|
||||
name: 'Test Name',
|
||||
fullname: 'Test Full Name',
|
||||
duration: '3.14',
|
||||
},
|
||||
failure: {
|
||||
message: { _cdata: 'Message CDATA' },
|
||||
'stack-trace': {
|
||||
_cdata:
|
||||
'at Tests.SetupFailedTest.SetUp () [0x00000] in /github/workspace/unity-project/Assets/Tests/SetupFailedTest.cs:10',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.suite).toBe('Test Suite');
|
||||
expect(result.title).toBe('Test Name');
|
||||
expect(result.duration).toBe(3.14);
|
||||
expect(result.annotation).toMatchObject({
|
||||
annotation_level: 'failure',
|
||||
end_line: 10,
|
||||
message: 'Message CDATA',
|
||||
path: '/github/workspace/unity-project/Assets/Tests/SetupFailedTest.cs',
|
||||
raw_details:
|
||||
'at Tests.SetupFailedTest.SetUp () [0x00000] in /github/workspace/unity-project/Assets/Tests/SetupFailedTest.cs:10',
|
||||
start_line: 10,
|
||||
title: 'Test Full Name',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('findAnnotationPoint', () => {
|
||||
test('keep working if not matching', () => {
|
||||
const result = ResultsParser.findAnnotationPoint('');
|
||||
expect(result.path).toBe('');
|
||||
expect(result.line).toBe(0);
|
||||
});
|
||||
|
||||
test('simple annotation point', () => {
|
||||
const result = ResultsParser.findAnnotationPoint(`at Tests.PlayModeTest+<FailedUnityTest>d__5.MoveNext () [0x0002e] in /github/workspace/unity-project/Assets/Tests/PlayModeTest.cs:39
|
||||
at UnityEngine.TestTools.TestEnumerator+<Execute>d__6.MoveNext () [0x00038] in /github/workspace/unity-project/Library/PackageCache/com.unity.test-framework@1.1.19/UnityEngine.TestRunner/NUnitExtensions/Attributes/TestEnumerator.cs:36`);
|
||||
expect(result.path).toBe('/github/workspace/unity-project/Assets/Tests/PlayModeTest.cs');
|
||||
expect(result.line).toBe(39);
|
||||
});
|
||||
|
||||
test('setup annotation point', () => {
|
||||
const result = ResultsParser.findAnnotationPoint(`SetUp
|
||||
at Tests.SetupFailedTest.SetUp () [0x00000] in /github/workspace/unity-project/Assets/Tests/SetupFailedTest.cs:10`);
|
||||
expect(result.path).toBe('/github/workspace/unity-project/Assets/Tests/SetupFailedTest.cs');
|
||||
expect(result.line).toBe(10);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,4 +1,4 @@
|
|||
import { components } from '@octokit/openapi-types/generated/types';
|
||||
import { components } from '@octokit/openapi-types/dist-types/generated/types';
|
||||
|
||||
export function timeHelper(seconds: number): string {
|
||||
return `${seconds.toFixed(3)}s`;
|
||||
|
@ -17,6 +17,8 @@ export abstract class Meta {
|
|||
abstract get mark(): string;
|
||||
}
|
||||
|
||||
export type Annotation = components['schemas']['check-annotation'];
|
||||
|
||||
export class RunMeta extends Meta {
|
||||
total = 0;
|
||||
passed = 0;
|
||||
|
@ -114,5 +116,3 @@ export class TestMeta extends Meta {
|
|||
return '✅';
|
||||
}
|
||||
}
|
||||
|
||||
export type Annotation = components['schemas']['check-annotation'];
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
/* Basic Options */
|
||||
// "incremental": true, /* Enable incremental compilation */
|
||||
"target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
|
||||
"target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
|
||||
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
|
||||
// "lib": [], /* Specify library files to be included in the compilation. */
|
||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||
|
@ -26,7 +26,7 @@
|
|||
|
||||
/* Strict Type-Checking Options */
|
||||
"strict": true /* Enable all strict type-checking options. */,
|
||||
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
"noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
|
||||
// "strictNullChecks": true, /* Enable strict null checks. */
|
||||
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
||||
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
||||
|
|
12
yarn.lock
12
yarn.lock
|
@ -1342,6 +1342,11 @@
|
|||
resolved "https://registry.yarnpkg.com/@octokit/openapi-types/-/openapi-types-2.2.0.tgz#123e0438a0bc718ccdac3b5a2e69b3dd00daa85b"
|
||||
integrity sha512-274lNUDonw10kT8wHg8fCcUc1ZjZHbWv0/TbAwb0ojhBQqZYc1cQ/4yqTVTtPMDeZ//g7xVEYe/s3vURkRghPg==
|
||||
|
||||
"@octokit/openapi-types@^5.1.0":
|
||||
version "5.1.1"
|
||||
resolved "https://registry.yarnpkg.com/@octokit/openapi-types/-/openapi-types-5.1.1.tgz#d01ae6e2879c589edcea7800e3a427455ece619f"
|
||||
integrity sha512-yMyaX9EDWCiyv7m85/K8L7bLFj1wrLdfDkKcZEZ6gNmepSW5mfSMFJnYwRINN7lF58wvevKPWvw0MYy6sxcFlQ==
|
||||
|
||||
"@octokit/plugin-paginate-rest@^2.2.3":
|
||||
version "2.7.0"
|
||||
resolved "https://registry.yarnpkg.com/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-2.7.0.tgz#6bb7b043c246e0654119a6ec4e72a172c9e2c7f3"
|
||||
|
@ -1380,6 +1385,13 @@
|
|||
once "^1.4.0"
|
||||
universal-user-agent "^6.0.0"
|
||||
|
||||
"@octokit/types@6.10.1":
|
||||
version "6.10.1"
|
||||
resolved "https://registry.yarnpkg.com/@octokit/types/-/types-6.10.1.tgz#5955dc0cf344bb82a46283a0c332651f5dd9f1ad"
|
||||
integrity sha512-hgNC5jxKG8/RlqxU/6GThkGrvFpz25+cPzjQjyiXTNBvhyltn2Z4GhFY25+kbtXwZ4Co4zM0goW5jak1KLp1ug==
|
||||
dependencies:
|
||||
"@octokit/openapi-types" "^5.1.0"
|
||||
|
||||
"@octokit/types@^6.0.0", "@octokit/types@^6.0.1", "@octokit/types@^6.0.3", "@octokit/types@^6.1.0":
|
||||
version "6.2.1"
|
||||
resolved "https://registry.yarnpkg.com/@octokit/types/-/types-6.2.1.tgz#7f881fe44475ab1825776a4a59ca1ae082ed1043"
|
||||
|
|
Loading…
Reference in New Issue