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 522ae71 commit 02cdc54
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/Components/TestExplorer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,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 @@ -734,13 +734,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 @@ -750,15 +755,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 @@ -1073,13 +1078,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 @@ -1116,7 +1115,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 @@ -1129,10 +1133,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 @@ -1247,7 +1249,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 02cdc54

Please sign in to comment.