55
66import * as assert from 'assert' ;
77import * as sinon from 'sinon' ;
8- import { IRunTestContext , TestKind } from '../../src/types' ;
98import { MarkdownString , Range , TestController , TestMessage , TestRunRequest , tests , workspace } from 'vscode' ;
109import { JUnitRunnerResultAnalyzer } from '../../src/runners/junitRunner/JUnitRunnerResultAnalyzer' ;
10+ import { IRunTestContext , TestKind } from '../../src/types' ;
1111import { generateTestItem } from './utils' ;
1212
1313// tslint:disable: only-arrow-functions
@@ -146,7 +146,7 @@ java.lang.AssertionError: expected:<1> but was:<2>
146146 analyzer . analyzeData ( testRunnerOutput ) ;
147147
148148 sinon . assert . calledWith ( failedSpy , testItem , sinon . match . any , sinon . match . number ) ;
149- const testMessage = failedSpy . getCall ( 0 ) . args [ 1 ] as TestMessage ;
149+ const testMessage = failedSpy . getCall ( 1 ) . args [ 1 ] as TestMessage ;
150150 const stringLiteral = ( testMessage . message as MarkdownString ) . value ;
151151 assert . ok ( stringLiteral . split ( '<br/>' ) . length === 3 ) ;
152152 } ) ;
@@ -338,7 +338,8 @@ org.junit.ComparisonFailure: expected:<hello
338338 } ) ;
339339
340340 test ( "test diff is not duplicated when failing assertion is extracted" , ( ) => {
341- const testItem = generateTestItem ( testController , 'junit@junit5.TestWithExtractedEqualityAssertion#test' , TestKind . JUnit5 , new Range ( 2 , 0 , 2 , 0 ) , undefined , 'TestWithExtractedEqualityAssertion.java' ) ;
341+ const range = new Range ( 9 , 0 , 11 , 0 ) ;
342+ const testItem = generateTestItem ( testController , 'junit@junit5.TestWithExtractedEqualityAssertion#test' , TestKind . JUnit5 , range , undefined , 'TestWithExtractedEqualityAssertion.java' ) ;
342343 const testRunRequest = new TestRunRequest ( [ testItem ] , [ ] ) ;
343344 const testRun = testController . createTestRun ( testRunRequest ) ;
344345 const startedSpy = sinon . spy ( testRun , 'started' ) ;
@@ -356,16 +357,9 @@ org.junit.ComparisonFailure: expected:<hello
356357%ACTUALE
357358%TRACES
358359org.opentest4j.AssertionFailedError: expected: <1> but was: <2>
359- at org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:55)
360- at org.junit.jupiter.api.AssertionUtils.failNotEqual(AssertionUtils.java:62)
361- at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:150)
362- at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:145)
363- at org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:510)
364360 at junit5.TestWithExtractedEqualityAssertion.extracted2(TestWithExtractedEqualityAssertion.java:18)
365361 at junit5.TestWithExtractedEqualityAssertion.extracted1(TestWithExtractedEqualityAssertion.java:14)
366- at junit5.TestWithExtractedEqualityAssertion.test(TestWithExtractedEqualityAssertion.java:10)
367- at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
368- at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
362+ at junit5.TestWithExtractedEqualityAssertion.test(TestWithExtractedEqualityAssertion.java:11)
369363%TRACEE
370364%TESTE 3,test(junit5.TestWithExtractedEqualityAssertion)
371365%RUNTIME55` ;
@@ -384,16 +378,12 @@ org.opentest4j.AssertionFailedError: expected: <1> but was: <2>
384378 sinon . assert . calledWith ( startedSpy , testItem ) ;
385379 sinon . assert . calledWith ( failedSpy , testItem , sinon . match . any ) ;
386380
387- const testMessage = failedSpy . getCall ( 0 ) . args [ 1 ] as TestMessage ;
381+ const diffTestMessages = failedSpy . getCalls ( ) . map ( call => call . args [ 1 ] as TestMessage ) . filter ( v => v . actualOutput || v . expectedOutput ) ;
382+ assert . strictEqual ( diffTestMessages . length , 1 , "not more than one diff-message" ) ;
383+ const testMessage = diffTestMessages [ 0 ] ;
388384 assert . strictEqual ( testMessage . expectedOutput , '1' ) ;
389385 assert . strictEqual ( testMessage . actualOutput , '2' ) ;
390- assert . strictEqual ( testMessage . location ?. range . start . line , 2 ) ;
391-
392- const testMessages = failedSpy . getCalls ( ) . map ( call => call . args [ 1 ] as TestMessage ) . filter ( v => v . actualOutput || v . expectedOutput ) ;
393-
394- assert . strictEqual ( testMessages . length , 1 , "not more than one diff-message" ) ;
395- // assert.strictEqual(testMessages[0].location?.range.start, 10); // todo
386+ assert . strictEqual ( testMessage . location ?. range . start . line , 10 ) ; // =11 - 1, (most precise info we get from the stack trace)
396387 } ) ;
397388
398-
399389} ) ;
0 commit comments