Skip to content
This repository was archived by the owner on Dec 26, 2023. It is now read-only.
Draft
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
104 changes: 67 additions & 37 deletions __tests__/annotations.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { testCaseAnnotation, parseNunit, Annotation, TestResult, readResults } from '../src/nunit'
import {parseStringPromise } from 'xml2js'
import { promises as fs } from "fs";
import {parseStringPromise} from 'xml2js'
import {promises as fs} from 'fs'
import {parseNunit, readResults} from '../src/nunit/index'
import {testCaseAnnotation} from '../src/nunit/v1'

test('parse TestCase', async () => {

const data = `
test('parse v1 TestCase', async () => {
const data = `
<test-case id="1480" name="ServerUpdate" fullname="Mirror.Tests.NetworkIdentityTests.ServerUpdate" methodname="ServerUpdate" classname="Mirror.Tests.NetworkIdentityTests" runstate="Runnable" seed="1748324986" result="Failed" start-time="2020-03-22 14:13:33Z" end-time="2020-03-22 14:13:33Z" duration="0.052314" asserts="0">
<properties />
<failure>
Expand All @@ -20,46 +20,76 @@ test('parse TestCase', async () => {
]]></output>
</test-case>
`
const testCase: any = await parseStringPromise(data, {
trim: true,
mergeAttrs: true,
explicitArray: false,
})

const annotation = testCaseAnnotation(testCase['test-case']);
const testCase: any = await parseStringPromise(data, {
trim: true,
mergeAttrs: true,
explicitArray: false
})

expect(annotation).toBeTruthy();
const annotation = testCaseAnnotation(testCase['test-case'])

expect(annotation.path).toContain("Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs");
expect(annotation.start_line).toBe(895);
expect(annotation.end_line).toBe(895);
expect(annotation.title).toBe("Failed test ServerUpdate in Mirror.Tests.NetworkIdentityTests")
expect(annotation.message).toBe("Expected: 1\n But was: 0")
expect(annotation.annotation_level).toBe('failure');
expect(annotation).toBeTruthy()

expect(annotation.path.replace(/\\/g, '/')).toContain(
'Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs'
)
expect(annotation.start_line).toBe(895)
expect(annotation.end_line).toBe(895)
expect(annotation.title).toBe(
'Failed test ServerUpdate in Mirror.Tests.NetworkIdentityTests'
)
expect(annotation.message).toBe('Expected: 1\n But was: 0')
expect(annotation.annotation_level).toBe('failure')
})

test('parse v1 Results', async () => {
const data = await fs.readFile('__tests__/editmode-results.xml', 'utf8')

test('parse Results', async () => {
const results = await parseNunit(data)
expect(results.passed).toBe(332)
expect(results.failed).toBe(1)

const data = await fs.readFile("__tests__/editmode-results.xml", 'utf8')
const annotation = results.annotations[0]
expect(annotation.path.replace(/\\/g, '/')).toContain(
'Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs'
)
expect(annotation.start_line).toBe(895)
expect(annotation.end_line).toBe(895)
expect(annotation.title).toBe(
'Failed test ServerUpdate in Mirror.Tests.NetworkIdentityTests'
)
expect(annotation.message).toBe('Expected: 1\n But was: 0')
expect(annotation.annotation_level).toBe('failure')
})

const results = await parseNunit(data);
expect(results.passed).toBe(332);
expect(results.failed).toBe(1);
test('parse v2 Results', async () => {
const data = await fs.readFile('__tests__/failed-results-v2.xml', 'utf8')

const annotation = results.annotations[0];
expect(annotation.path).toContain("Assets/Mirror/Tests/Editor/NetworkIdentityTests.cs");
expect(annotation.start_line).toBe(895);
expect(annotation.end_line).toBe(895);
expect(annotation.title).toBe("Failed test ServerUpdate in Mirror.Tests.NetworkIdentityTests")
expect(annotation.message).toBe("Expected: 1\n But was: 0")
expect(annotation.annotation_level).toBe('failure');
});
const results = await parseNunit(data)

test('parse all Results', async () => {
expect(results.passed).toBe(137)
expect(results.failed).toBe(10)
expect(results.annotations.length).toBe(10)

var results = await readResults("__tests__/*.xml");
const annotation = results.annotations[0]
expect(annotation).toMatchInlineSnapshot(`
Annotation {
"annotation_level": "failure",
"end_column": 0,
"end_line": 0,
"message": "RemoteException: verbose: using stderr for log output",
"path": "unknown",
"raw_details": "at Invoke, D:\\\\a\\\\ps-csproj\\\\ps-csproj\\\\src\\\\process\\\\process.psm1:238
at <ScriptBlock>, D:\\\\a\\\\ps-csproj\\\\ps-csproj\\\\test\\\\process.tests.ps1:17",
"start_column": 0,
"start_line": 0,
"title": "Failed test 'long messages does not break output' in 'Processing output from invoke.long messages does not break output'",
}
`)
})

expect(results.annotations).toHaveLength(6);
});
test('parse all Results', async () => {
var results = await readResults('__tests__/*.xml')

expect(results.annotations).toHaveLength(16)
})
Loading