Skip to content

Commit c70ab1a

Browse files
committed
Merge branch 'trx'
2 parents 7e473ef + 21ae33d commit c70ab1a

5 files changed

Lines changed: 368 additions & 7 deletions

File tree

src/escape_html.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ const lookup: Record<string, string> = {
66
">": "&gt;"
77
}
88

9-
export default function escapeHTML(s: string): string {
10-
return s.replace(/[&"'<>]/g, c => lookup[c])
9+
export default function escapeHTML(s: any): string {
10+
return String(s).replace(/[&"'<>]/g, c => lookup[c] || c)
1111
}

src/test_parser.ts

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ export async function parseTap(data: string): Promise<TestResult> {
199199
}
200200
}
201201

202+
export async function parseTapFile(filename: string): Promise<TestResult> {
203+
const readfile = util.promisify(fs.readFile)
204+
return await parseTap(await readfile(filename, "utf8"))
205+
}
206+
202207
async function parseJunitXml(xml: any): Promise<TestResult> {
203208
let testsuites
204209

@@ -292,16 +297,78 @@ export async function parseJunit(data: string): Promise<TestResult> {
292297
return await parseJunitXml(xml)
293298
}
294299

295-
export async function parseTapFile(filename: string): Promise<TestResult> {
296-
const readfile = util.promisify(fs.readFile)
297-
return await parseTap(await readfile(filename, "utf8"))
298-
}
299-
300300
export async function parseJunitFile(filename: string): Promise<TestResult> {
301301
const readfile = util.promisify(fs.readFile)
302302
return await parseJunit(await readfile(filename, "utf8"))
303303
}
304304

305+
export async function parseTrx(xml: any): Promise<TestResult> {
306+
if (xml.TestRun.$.xmlns != "http://microsoft.com/schemas/VisualStudio/TeamTest/2010"
307+
|| !Array.isArray(xml.TestRun.Results)) {
308+
throw new Error("Not a valid .trx file.")
309+
}
310+
311+
const suites: TestSuite[] = [ ]
312+
const counts = {
313+
passed: 0,
314+
failed: 0,
315+
skipped: 0
316+
}
317+
318+
for (const result of xml.TestRun.Results) {
319+
const cases: TestCase[] = [ ]
320+
321+
if (!Array.isArray(result.UnitTestResult)) {
322+
continue
323+
}
324+
325+
for (const item of result.UnitTestResult) {
326+
let status = TestStatus.Pass
327+
328+
const id = item.$.testId
329+
const name = item.$.testName
330+
const duration = item.$.duration
331+
const outcome = item.$.outcome
332+
333+
let message: string | undefined = undefined
334+
let details: string = ""
335+
336+
const output = item?.Output?.[0]
337+
details = "StdOut:" + output?.StdOut?.[0]
338+
339+
if (outcome == "Passed") {
340+
counts.passed++
341+
} else if (outcome == "Failed") {
342+
status = TestStatus.Fail
343+
counts.failed++
344+
345+
message = output?.ErrorInfo?.[0]?.Message
346+
details = "StackTrace:" + output?.ErrorInfo?.[0]?.StackTrace + '\n' + details
347+
} else {
348+
status = TestStatus.Pass
349+
counts.skipped++
350+
}
351+
352+
cases.push({
353+
status: status,
354+
name: name,
355+
message: message,
356+
details: details,
357+
duration: duration
358+
})
359+
}
360+
361+
suites.push({
362+
cases: cases
363+
})
364+
}
365+
366+
return {
367+
counts: counts,
368+
suites: suites
369+
}
370+
}
371+
305372
export async function parseFile(filename: string): Promise<TestResult> {
306373
const readfile = util.promisify(fs.readFile)
307374
const parser = util.promisify(xml2js.parseString)
@@ -320,5 +387,9 @@ export async function parseFile(filename: string): Promise<TestResult> {
320387
return await parseJunitXml(xml)
321388
}
322389

390+
if ('TestRun' in xml) {
391+
return await parseTrx(xml)
392+
}
393+
323394
throw new Error(`unknown test file type for '${filename}'`)
324395
}

test/file.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ chai.use(chaiAsPromised)
88

99
const tapResourcePath = `${__dirname}/resources/tap`
1010
const junitResourcePath = `${__dirname}/resources/junit`
11+
const trxResourcePath = `${__dirname}/resources/trx`
1112

1213
describe("file", async () => {
1314
it("identifies common tap", async () => {
@@ -62,4 +63,11 @@ describe("file", async () => {
6263
expect(result.counts.failed).to.eql(0)
6364
expect(result.counts.skipped).to.eql(0)
6465
})
66+
67+
it("identifies trx", async() => {
68+
const result = await parseFile(`${trxResourcePath}/example.trx`)
69+
expect(result.counts.passed).to.eql(3)
70+
expect(result.counts.failed).to.eql(1)
71+
expect(result.counts.skipped).to.eql(0)
72+
})
6573
})

test/resources/trx/example.trx

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<TestRun id="97f57849-3919-4bc0-8b5a-60884faca4a9" name="camejef@BUMBLEBEE 2012-02-19 09:25:24" runUser="BUMBLEBEE\camejef" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
3+
<TestSettings name="Default Test Settings" id="fca8b5a8-ae49-45c5-b2b7-a975e4a4fd10">
4+
<Deployment userDeploymentRoot="c:\dev\pickles-results-harness" useDefaultDeploymentRoot="false" runDeploymentRoot="camejef_BUMBLEBEE 2012-02-19 09_25_24" />
5+
<Execution>
6+
<TestTypeSpecific />
7+
<AgentRule name="Execution Agents">
8+
</AgentRule>
9+
</Execution>
10+
</TestSettings>
11+
<Times creation="2012-02-19T09:25:24.8479038-05:00" queuing="2012-02-19T09:25:25.1799228-05:00" start="2012-02-19T09:25:25.2569272-05:00" finish="2012-02-19T09:25:26.0819744-05:00" />
12+
<ResultSummary outcome="Failed">
13+
<Counters total="4" executed="4" passed="3" error="0" failed="1" timeout="0" aborted="0" inconclusive="0" passedButRunAborted="0" notRunnable="0" notExecuted="0" disconnected="0" warning="0" completed="0" inProgress="0" pending="0" />
14+
</ResultSummary>
15+
<TestDefinitions>
16+
<UnitTest name="FailToAddTwoNumbers" storage="pickles.testharness\pickles.testharness.mstest\bin\debug\pickles.testharness.mstest.dll" id="10684beb-1457-c825-5087-2d0029460463">
17+
<Description>Fail to add two numbers</Description>
18+
<Execution id="6a02f552-17f1-4f86-9eaa-bcddec97f075" />
19+
<Properties>
20+
<Property>
21+
<Key>FeatureTitle</Key>
22+
<Value>Addition</Value>
23+
</Property>
24+
</Properties>
25+
<TestMethod codeBase="c:/dev/pickles-results-harness/Pickles.TestHarness/Pickles.TestHarness.MSTest/bin/debug/Pickles.TestHarness.MSTest.DLL" adapterTypeName="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapter, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Adapter, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" className="Pickles.TestHarness.MSTest.AdditionFeature, Pickles.TestHarness.MSTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="FailToAddTwoNumbers" />
26+
</UnitTest>
27+
<UnitTest name="AddTwoNumbers" storage="pickles.testharness\pickles.testharness.mstest\bin\debug\pickles.testharness.mstest.dll" id="45571f70-456e-69eb-dbf2-7ec265c4b751">
28+
<Description>Add two numbers</Description>
29+
<Execution id="17356f2f-b3c9-4bee-b6b3-74fe17b2e82b" />
30+
<Properties>
31+
<Property>
32+
<Key>FeatureTitle</Key>
33+
<Value>Addition</Value>
34+
</Property>
35+
</Properties>
36+
<TestMethod codeBase="c:/dev/pickles-results-harness/Pickles.TestHarness/Pickles.TestHarness.MSTest/bin/debug/Pickles.TestHarness.MSTest.DLL" adapterTypeName="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapter, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Adapter, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" className="Pickles.TestHarness.MSTest.AdditionFeature, Pickles.TestHarness.MSTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="AddTwoNumbers" />
37+
</UnitTest>
38+
<UnitTest name="AddingSeveralNumbers_40" storage="pickles.testharness\pickles.testharness.mstest\bin\debug\pickles.testharness.mstest.dll" id="272c9292-71fc-4aaa-5ed5-d7869de15ae4">
39+
<Description>Adding several numbers</Description>
40+
<Execution id="d7b75d23-a952-4578-8542-326abd65c695" />
41+
<Properties>
42+
<Property>
43+
<Key>FeatureTitle</Key>
44+
<Value>Addition</Value>
45+
</Property>
46+
<Property>
47+
<Key>VariantName</Key>
48+
<Value>40</Value>
49+
</Property>
50+
<Property>
51+
<Key>Parameter:Second Number</Key>
52+
<Value>50</Value>
53+
</Property>
54+
<Property>
55+
<Key>Parameter:Result</Key>
56+
<Value>90</Value>
57+
</Property>
58+
<Property>
59+
<Key>Parameter:First Number</Key>
60+
<Value>40</Value>
61+
</Property>
62+
</Properties>
63+
<TestMethod codeBase="c:/dev/pickles-results-harness/Pickles.TestHarness/Pickles.TestHarness.MSTest/bin/debug/Pickles.TestHarness.MSTest.DLL" adapterTypeName="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapter, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Adapter, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" className="Pickles.TestHarness.MSTest.AdditionFeature, Pickles.TestHarness.MSTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="AddingSeveralNumbers_40" />
64+
</UnitTest>
65+
<UnitTest name="AddingSeveralNumbers_60" storage="pickles.testharness\pickles.testharness.mstest\bin\debug\pickles.testharness.mstest.dll" id="0156926a-5b5c-a0f3-47b4-9cf23f44894b">
66+
<Description>Adding several numbers</Description>
67+
<Execution id="0f00d527-6edd-4045-b9b5-65ebce5b3874" />
68+
<Properties>
69+
<Property>
70+
<Key>FeatureTitle</Key>
71+
<Value>Addition</Value>
72+
</Property>
73+
<Property>
74+
<Key>VariantName</Key>
75+
<Value>60</Value>
76+
</Property>
77+
<Property>
78+
<Key>Parameter:Second Number</Key>
79+
<Value>70</Value>
80+
</Property>
81+
<Property>
82+
<Key>Parameter:Result</Key>
83+
<Value>130</Value>
84+
</Property>
85+
<Property>
86+
<Key>Parameter:First Number</Key>
87+
<Value>60</Value>
88+
</Property>
89+
</Properties>
90+
<TestMethod codeBase="c:/dev/pickles-results-harness/Pickles.TestHarness/Pickles.TestHarness.MSTest/bin/debug/Pickles.TestHarness.MSTest.DLL" adapterTypeName="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapter, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Adapter, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" className="Pickles.TestHarness.MSTest.AdditionFeature, Pickles.TestHarness.MSTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="AddingSeveralNumbers_60" />
91+
</UnitTest>
92+
</TestDefinitions>
93+
<TestLists>
94+
<TestList name="Results Not in a List" id="8c84fa94-04c1-424b-9868-57a2d4851a1d" />
95+
<TestList name="All Loaded Results" id="19431567-8539-422a-85d7-44ee4e166bda" />
96+
</TestLists>
97+
<TestEntries>
98+
<TestEntry testId="272c9292-71fc-4aaa-5ed5-d7869de15ae4" executionId="d7b75d23-a952-4578-8542-326abd65c695" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" />
99+
<TestEntry testId="0156926a-5b5c-a0f3-47b4-9cf23f44894b" executionId="0f00d527-6edd-4045-b9b5-65ebce5b3874" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" />
100+
<TestEntry testId="45571f70-456e-69eb-dbf2-7ec265c4b751" executionId="17356f2f-b3c9-4bee-b6b3-74fe17b2e82b" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" />
101+
<TestEntry testId="10684beb-1457-c825-5087-2d0029460463" executionId="6a02f552-17f1-4f86-9eaa-bcddec97f075" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" />
102+
</TestEntries>
103+
<Results>
104+
<UnitTestResult executionId="d7b75d23-a952-4578-8542-326abd65c695" testId="272c9292-71fc-4aaa-5ed5-d7869de15ae4" testName="AddingSeveralNumbers_40" computerName="BUMBLEBEE" duration="00:00:00.0768910" startTime="2012-02-19T09:25:25.2729281-05:00" endTime="2012-02-19T09:25:25.9379661-05:00" testType="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b" outcome="Passed" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" relativeResultsDirectory="d7b75d23-a952-4578-8542-326abd65c695">
105+
<Output>
106+
<StdOut>
107+
Given I have entered 40 into the calculator
108+
-&gt; done: Steps.GivenIHaveEnteredSomethingIntoTheCalculator(40) (0.0s)
109+
And I have entered 50 into the calculator
110+
-&gt; done: Steps.GivenIHaveEnteredSomethingIntoTheCalculator(50) (0.0s)
111+
When I press add
112+
-&gt; done: Steps.WhenIPressAdd() (0.0s)
113+
Then the result should be 90 on the screen
114+
-&gt; done: Steps.ThenTheResultShouldBePass(90) (0.0s)
115+
</StdOut>
116+
</Output>
117+
</UnitTestResult>
118+
<UnitTestResult executionId="0f00d527-6edd-4045-b9b5-65ebce5b3874" testId="0156926a-5b5c-a0f3-47b4-9cf23f44894b" testName="AddingSeveralNumbers_60" computerName="BUMBLEBEE" duration="00:00:00.0111534" startTime="2012-02-19T09:25:25.9399663-05:00" endTime="2012-02-19T09:25:25.9719681-05:00" testType="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b" outcome="Passed" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" relativeResultsDirectory="0f00d527-6edd-4045-b9b5-65ebce5b3874">
119+
<Output>
120+
<StdOut>
121+
Given I have entered 60 into the calculator
122+
-&gt; done: Steps.GivenIHaveEnteredSomethingIntoTheCalculator(60) (0.0s)
123+
And I have entered 70 into the calculator
124+
-&gt; done: Steps.GivenIHaveEnteredSomethingIntoTheCalculator(70) (0.0s)
125+
When I press add
126+
-&gt; done: Steps.WhenIPressAdd() (0.0s)
127+
Then the result should be 130 on the screen
128+
-&gt; done: Steps.ThenTheResultShouldBePass(130) (0.0s)
129+
</StdOut>
130+
</Output>
131+
</UnitTestResult>
132+
<UnitTestResult executionId="17356f2f-b3c9-4bee-b6b3-74fe17b2e82b" testId="45571f70-456e-69eb-dbf2-7ec265c4b751" testName="AddTwoNumbers" computerName="BUMBLEBEE" duration="00:00:00.0055623" startTime="2012-02-19T09:25:25.9799685-05:00" endTime="2012-02-19T09:25:25.9919692-05:00" testType="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b" outcome="Passed" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" relativeResultsDirectory="17356f2f-b3c9-4bee-b6b3-74fe17b2e82b">
133+
<Output>
134+
<StdOut>
135+
Given I have entered 50 into the calculator
136+
-&gt; done: Steps.GivenIHaveEnteredSomethingIntoTheCalculator(50) (0.0s)
137+
And I have entered 70 into the calculator
138+
-&gt; done: Steps.GivenIHaveEnteredSomethingIntoTheCalculator(70) (0.0s)
139+
When I press add
140+
-&gt; done: Steps.WhenIPressAdd() (0.0s)
141+
Then the result should be 120 on the screen
142+
-&gt; done: Steps.ThenTheResultShouldBePass(120) (0.0s)
143+
</StdOut>
144+
</Output>
145+
</UnitTestResult>
146+
<UnitTestResult executionId="6a02f552-17f1-4f86-9eaa-bcddec97f075" testId="10684beb-1457-c825-5087-2d0029460463" testName="FailToAddTwoNumbers" computerName="BUMBLEBEE" duration="00:00:00.0459057" startTime="2012-02-19T09:25:25.9949694-05:00" endTime="2012-02-19T09:25:26.0469724-05:00" testType="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b" outcome="Failed" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" relativeResultsDirectory="6a02f552-17f1-4f86-9eaa-bcddec97f075">
147+
<Output>
148+
<StdOut>
149+
Given I have entered 50 into the calculator
150+
-&gt; done: Steps.GivenIHaveEnteredSomethingIntoTheCalculator(50) (0.0s)
151+
And I have entered -1 into the calculator
152+
-&gt; done: Steps.GivenIHaveEnteredSomethingIntoTheCalculator(-1) (0.0s)
153+
When I press add
154+
-&gt; done: Steps.WhenIPressAdd() (0.0s)
155+
Then the result should be -50 on the screen
156+
-&gt; error: Assert.NotEqual() Failure
157+
</StdOut>
158+
<ErrorInfo>
159+
<Message>
160+
Test method Pickles.TestHarness.MSTest.AdditionFeature.FailToAddTwoNumbers threw exception:
161+
Should.Core.Exceptions.NotEqualException: Assert.NotEqual() Failure
162+
</Message>
163+
<StackTrace>
164+
at Pickles.TestHarness.MSTest.Steps.ThenTheResultShouldBePass(Int32 result) in C:\dev\pickles-results-harness\Pickles.TestHarness\Pickles.TestHarness.MSTest\Steps.cs:line 28
165+
at lambda_method(Closure , IContextManager , Int32 )
166+
at TechTalk.SpecFlow.Bindings.MethodBinding.InvokeAction(IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan&amp; duration)
167+
at TechTalk.SpecFlow.Bindings.StepDefinitionBinding.Invoke(IContextManager contextManager, ITestTracer testTracer, Object[] arguments, TimeSpan&amp; duration)
168+
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStepMatch(BindingMatch match, Object[] arguments)
169+
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStep(StepArgs stepArgs)
170+
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnAfterLastStep()
171+
at TechTalk.SpecFlow.TestRunner.CollectScenarioErrors()
172+
at Pickles.TestHarness.MSTest.AdditionFeature.ScenarioCleanup() in C:\dev\pickles-results-harness\Pickles.TestHarness\Pickles.TestHarness.MSTest\Addition.feature.cs:line 0
173+
at Pickles.TestHarness.MSTest.AdditionFeature.FailToAddTwoNumbers() in c:\dev\pickles-results-harness\Pickles.TestHarness\Pickles.TestHarness.MSTest\Addition.feature:line 18
174+
</StackTrace>
175+
</ErrorInfo>
176+
</Output>
177+
</UnitTestResult>
178+
</Results>
179+
</TestRun>

0 commit comments

Comments
 (0)