@@ -156,13 +156,22 @@ describe('test-item-data', () => {
156
156
157
157
const createAllTestItems = ( ) => {
158
158
const wsRoot = new WorkspaceRoot ( context ) ;
159
- const folder = new FolderData ( context , 'dir ' , wsRoot . item ) ;
160
- const uri : any = { fsPath : 'whatever ' } ;
159
+ const folder = new FolderData ( context , 'tests ' , wsRoot . item ) ;
160
+ const uri : any = { fsPath : '/ws-1/tests/a.test.ts ' } ;
161
161
const doc = new TestDocumentRoot ( context , uri , folder . item ) ;
162
162
const node : any = { fullName : 'a test' , attrs : { } , data : { } } ;
163
163
const testItem = new TestData ( context , uri , node , doc . item ) ;
164
164
return { wsRoot, folder, doc, testItem } ;
165
165
} ;
166
+ // like createAllTestItems but with added a describe block
167
+ const createTestDataTree = ( ) => {
168
+ const { wsRoot, folder, doc, testItem } = createAllTestItems ( ) ;
169
+ const node1 : any = { fullName : 'describe' , attrs : { } , data : { } } ;
170
+ const desc = new TestData ( context , doc . uri , node1 , doc . item ) ;
171
+ const node2 : any = { fullName : 'describe test 2' , attrs : { } , data : { } } ;
172
+ const test2 = new TestData ( context , doc . uri , node2 , desc . item ) ;
173
+ return { wsRoot, folder, doc, testItem, desc, test2 } ;
174
+ } ;
166
175
167
176
beforeEach ( ( ) => {
168
177
controllerMock = mockController ( ) ;
@@ -1834,4 +1843,97 @@ describe('test-item-data', () => {
1834
1843
) ;
1835
1844
} ) ;
1836
1845
} ) ;
1846
+ describe ( 'onAssertionUpdate' , ( ) => {
1847
+ let folder , doc , desc , testItem , test2 ;
1848
+ beforeEach ( ( ) => {
1849
+ ( { folder, doc, desc, testItem, test2 } = createTestDataTree ( ) ) ;
1850
+ } ) ;
1851
+ describe ( 'when test suite failed without assertions' , ( ) => {
1852
+ it ( "all child items should inherit the test suite's status" , ( ) => {
1853
+ // address https://github.com/jest-community/vscode-jest/issues/1098
1854
+ const file = '/ws-1/tests/a.test.ts' ;
1855
+ // context.ext.testResultProvider.getTestList.mockReturnValueOnce([]);
1856
+ const runMode = new RunMode ( { type : 'watch' } ) ;
1857
+ context . ext . settings = { runMode } ;
1858
+
1859
+ // test suite failed and there is no assertions
1860
+ const testSuiteResult : any = {
1861
+ status : 'KnownFail' ,
1862
+ message : 'test file failed' ,
1863
+ } ;
1864
+ context . ext . testResultProvider . getTestSuiteResult . mockReturnValue ( testSuiteResult ) ;
1865
+
1866
+ // doc has 2 children before the test suite event
1867
+ expect ( doc . item . children . size ) . toBe ( 2 ) ;
1868
+
1869
+ // triggers testSuiteChanged event listener
1870
+ contextCreateTestRunSpy . mockClear ( ) ;
1871
+ mockedJestTestRun . mockClear ( ) ;
1872
+
1873
+ // mock a non-watch process that is still running
1874
+ const process = {
1875
+ id : 'whatever' ,
1876
+ request : { type : 'watch-tests' } ,
1877
+ } ;
1878
+ context . ext . testResultProvider . events . testSuiteChanged . event . mock . calls [ 0 ] [ 0 ] ( {
1879
+ type : 'assertions-updated' ,
1880
+ process,
1881
+ files : [ file ] ,
1882
+ } ) ;
1883
+
1884
+ // all child items should have been removed
1885
+ expect ( doc . item . children . size ) . toBe ( 0 ) ;
1886
+
1887
+ // checking item status update...
1888
+ const run = mockedJestTestRun . mock . results [ 0 ] . value ;
1889
+
1890
+ // all child items should be updated regardless before being removed
1891
+ expect ( run . failed ) . toHaveBeenCalledTimes ( 4 ) ;
1892
+ [ doc . item , testItem . item , desc . item , test2 . item ] . forEach ( ( item ) => {
1893
+ expect ( run . failed ) . toHaveBeenCalledWith ( item , expect . anything ( ) ) ;
1894
+ } ) ;
1895
+
1896
+ expect ( run . end ) . toHaveBeenCalledTimes ( 1 ) ;
1897
+ } ) ;
1898
+ } ) ;
1899
+ it ( 'when no test suite result found, the doc and its child items should be removed without any status update' , ( ) => {
1900
+ const file = '/ws-1/tests/a.test.ts' ;
1901
+ const runMode = new RunMode ( { type : 'watch' } ) ;
1902
+ context . ext . settings = { runMode } ;
1903
+
1904
+ // test suite failed and there is no assertions
1905
+ context . ext . testResultProvider . getTestSuiteResult . mockReturnValue ( undefined ) ;
1906
+
1907
+ // doc has 2 children before the test suite event
1908
+ expect ( folder . item . children . size ) . toBe ( 1 ) ;
1909
+ expect ( doc . item . children . size ) . toBe ( 2 ) ;
1910
+
1911
+ // triggers testSuiteChanged event listener
1912
+ contextCreateTestRunSpy . mockClear ( ) ;
1913
+ mockedJestTestRun . mockClear ( ) ;
1914
+
1915
+ // mock a non-watch process that is still running
1916
+ const process = {
1917
+ id : 'whatever' ,
1918
+ request : { type : 'watch-tests' } ,
1919
+ } ;
1920
+ context . ext . testResultProvider . events . testSuiteChanged . event . mock . calls [ 0 ] [ 0 ] ( {
1921
+ type : 'assertions-updated' ,
1922
+ process,
1923
+ files : [ file ] ,
1924
+ } ) ;
1925
+
1926
+ // all doc's child items should have been removed but the doc itself would remain
1927
+ expect ( folder . item . children . size ) . toBe ( 1 ) ;
1928
+ expect ( doc . item . children . size ) . toBe ( 0 ) ;
1929
+
1930
+ // checking item status update...
1931
+ const run = mockedJestTestRun . mock . results [ 0 ] . value ;
1932
+
1933
+ // no update should occur
1934
+ expect ( run . failed ) . not . toHaveBeenCalled ( ) ;
1935
+
1936
+ expect ( run . end ) . toHaveBeenCalledTimes ( 1 ) ;
1937
+ } ) ;
1938
+ } ) ;
1837
1939
} ) ;
0 commit comments