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

Commit

Permalink
Clean-up and fix-up for using report title in github check
Browse files Browse the repository at this point in the history
* Prettier run on some files
* Fix unit tests for windows developers
  • Loading branch information
jasonleenaylor committed Mar 22, 2021
1 parent d68a059 commit 63ab85d
Show file tree
Hide file tree
Showing 4 changed files with 339 additions and 203 deletions.
85 changes: 48 additions & 37 deletions __tests__/annotations.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { testCaseAnnotation, parseNunit, Annotation, TestResult, readResults } from '../src/nunit'
import {parseStringPromise } from 'xml2js'
import { promises as fs } from "fs";
import {
testCaseAnnotation,
parseNunit,
Annotation,
TestResult,
readResults
} from '../src/nunit'
import {parseStringPromise} from 'xml2js'
import {promises as fs} from 'fs'
import path from 'path';

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

const data = `
test('parse 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 +27,50 @@ 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).toContain(
path.join('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 Results', async () => {
const data = await fs.readFile('__tests__/editmode-results.xml', 'utf8')

const data = await fs.readFile("__tests__/editmode-results.xml", 'utf8')

const results = await parseNunit(data);
expect(results.passed).toBe(332);
expect(results.failed).toBe(1);
const results = await parseNunit(data)
expect(results.passed).toBe(332)
expect(results.failed).toBe(1)

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 annotation = results.annotations[0]
expect(annotation.path).toContain(
path.join('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).toMatch(/Expected: 1\s+But was: 0/)
expect(annotation.annotation_level).toBe('failure')
})

test('parse all Results', async () => {
var results = await readResults('__tests__/*.xml')

var results = await readResults("__tests__/*.xml");

expect(results.annotations).toHaveLength(6);
});
expect(results.annotations).toHaveLength(6)
})
Loading

0 comments on commit 63ab85d

Please sign in to comment.