Skip to content

Commit

Permalink
Add target framework to project test items
Browse files Browse the repository at this point in the history
Paves the way for multiple Target frameworks
and provides context so users can figure out why the test count is
different than the console or other test explorers

See this discussion: ionide#1874 (comment)
  • Loading branch information
farlee2121 committed Jul 5, 2023
1 parent e4a26f8 commit bb13ef8
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions src/Components/TestExplorer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -546,11 +546,12 @@ module TestItem =
let fromProject
(testItemFactory: TestItemFactory)
(projectPath: ProjectPath)
(targetFramework: string)
(children: TestItem array)
: TestItem =
testItemFactory
{ id = constructId projectPath ""
label = Path.getNameOnly projectPath
label = $"{Path.getNameOnly projectPath} ({targetFramework})"
uri = None
range = None
children = children }
Expand All @@ -566,7 +567,7 @@ module TestItem =
testsForFile.tests
|> Array.map (fromTestAdapter testItemFactory fileUri projectPath)

[| fromProject testItemFactory projectPath fileTests |])
[| fromProject testItemFactory projectPath project.Info.TargetFramework fileTests |])

let getOrMakeHierarchyPath
(rootCollection: TestItemCollection)
Expand Down Expand Up @@ -722,13 +723,18 @@ module TestDiscovery =

recurse targetCollection previousCodeTests newCodeTests

let discoverFromTrx testItemFactory (tryGetLocation: TestId -> LocationRecord option) makeTrxPath projectPaths =
let discoverFromTrx
testItemFactory
(tryGetLocation: TestId -> LocationRecord option)
makeTrxPath
(projectPaths: Project list)
=

let testProjects =
projectPaths
|> Array.ofList
|> Array.choose (fun p ->
match p |> makeTrxPath |> Path.tryPath with
match p.Project |> makeTrxPath |> Path.tryPath with
| Some trxPath -> Some(p, trxPath)
| None -> None)

Expand All @@ -738,15 +744,15 @@ module TestDiscovery =

let treeItems =
trxTestsPerProject
|> Array.map (fun (projPath, trxDefs) ->
let projectPath = ProjectPath.ofString projPath
|> Array.map (fun (project, trxDefs) ->
let projectPath = ProjectPath.ofString project.Project
let heirarchy = TrxParser.inferHierarchy trxDefs

let projectTests =
heirarchy
|> Array.map (TestItem.fromNamedHierarchy testItemFactory tryGetLocation projectPath)

TestItem.fromProject testItemFactory projectPath projectTests)
TestItem.fromProject testItemFactory projectPath project.Info.TargetFramework projectTests)


treeItems
Expand Down Expand Up @@ -1031,13 +1037,7 @@ module Interactions =



let testProjects =
Project.getInWorkspace ()
|> List.choose (fun projectLoadState ->
match projectLoadState with
| Project.ProjectLoadingState.Loaded proj ->
if ProjectExt.isTestProject proj then Some proj else None
| _ -> None)
let testProjects = Project.getLoaded () |> List.filter ProjectExt.isTestProject

let testProjectCount = List.length testProjects
let testProjectPaths = testProjects |> List.map (fun p -> p.Project)
Expand Down Expand Up @@ -1074,7 +1074,12 @@ module Interactions =
|> TestName.inferHierarchy
|> Array.map (TestItem.fromNamedHierarchy testItemFactory tryGetLocation project.Project)

return TestItem.fromProject testItemFactory project.Project testHierarchy
return
TestItem.fromProject
testItemFactory
project.Project
project.Info.TargetFramework
testHierarchy
}

let! listDiscoveredTests = listDiscoveryProjects |> List.map discoverTestsByListOnly |> Promise.all
Expand All @@ -1087,10 +1092,8 @@ module Interactions =
let trxPath = makeTrxPath projectPath |> Some
DotnetCli.test projectPath project.Info.TargetFramework trxPath None)

let trxDiscoveryProjectPaths = trxDiscoveryProjects |> List.map (fun p -> p.Project)

let trxDiscoveredTests =
TestDiscovery.discoverFromTrx testItemFactory tryGetLocation makeTrxPath trxDiscoveryProjectPaths
TestDiscovery.discoverFromTrx testItemFactory tryGetLocation makeTrxPath trxDiscoveryProjects

let newTests = Array.concat [ listDiscoveredTests; trxDiscoveredTests ]

Expand Down Expand Up @@ -1205,7 +1208,7 @@ let activate (context: ExtensionContext) =
let trxTests =
TestDiscovery.discoverFromTrx testItemFactory locationCache.GetById makeTrxPath

let workspaceProjects = ProjectExt.getAllWorkspaceProjects ()
let workspaceProjects = Project.getLoaded ()
let initialTests = trxTests workspaceProjects
initialTests |> Array.iter testController.items.add

Expand Down

0 comments on commit bb13ef8

Please sign in to comment.