Skip to content

Commit 35fc264

Browse files
authored
Log FolderContext creation stack (#1878)
When a duplicate folder context is created in a test this typically indicates the test is set up incorrectly. Capture the stack trace at the time of creation, and then log it when a duplicate folder is created.
1 parent c14c506 commit 35fc264

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/FolderContext.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export class FolderContext implements vscode.Disposable {
3737
private testExplorerResolver?: (testExplorer: TestExplorer) => void;
3838
private packageWatcher: PackageWatcher;
3939
private testRunManager: TestRunManager;
40+
public creationStack?: string;
4041

4142
/**
4243
* FolderContext constructor
@@ -57,6 +58,10 @@ export class FolderContext implements vscode.Disposable {
5758
this.taskQueue = new TaskQueue(this);
5859
this.testRunManager = new TestRunManager();
5960

61+
// In order to track down why a FolderContext may be created when we don't want one,
62+
// capture the stack so we can log it if we find a duplicate.
63+
this.creationStack = new Error().stack;
64+
6065
// Tests often need to wait for the test explorer to be created before they can run.
6166
// This promise resolves when the test explorer is created, allowing them to wait for it before starting.
6267
this.resolvedTestExplorer = new Promise<TestExplorer>(resolve => {

src/WorkspaceContext.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,10 @@ export class WorkspaceContext implements vscode.Disposable {
467467
// find context with root folder
468468
const index = this.folders.findIndex(context => context.folder.fsPath === folder.fsPath);
469469
if (index !== -1) {
470+
const existingFolder = this.folders[index];
470471
this.logger.warn(`Adding package folder ${folder} twice: ${Error().stack}`);
471-
return this.folders[index];
472+
this.logger.warn(`Existing folder was created by ${existingFolder.creationStack}`);
473+
return existingFolder;
472474
}
473475
const folderContext = await FolderContext.create(folder, workspaceFolder, this);
474476
this.folders.push(folderContext);

0 commit comments

Comments
 (0)