From df1f25bcd8fab50b059cfd44e74125b19ce54767 Mon Sep 17 00:00:00 2001 From: Pavel Date: Wed, 29 Nov 2023 13:25:28 -0800 Subject: [PATCH] chore: rely upon playwright source map handling --- src/extension.ts | 6 +++--- src/testModel.ts | 33 +++------------------------------ tests/source-map.spec.ts | 14 +++++++------- 3 files changed, 13 insertions(+), 40 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index fd3cf3d74..0f11c192d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -608,10 +608,10 @@ located next to Run / Debug Tests toolbar buttons.`); await this._listTestsInAllModels(files); } - private _listTestsInAllModels(files: string[]): Promise { + private _listTestsInAllModels(inputFiles: string[]): Promise { // Perform coalescing listTests calls to avoid multiple // 'list tests' processes running at the same time. - if (!files.length) + if (!inputFiles.length) return Promise.resolve(); if (!this._filesPendingListTests) { @@ -647,7 +647,7 @@ located next to Run / Debug Tests toolbar buttons.`); }; } - for (const file of files) + for (const file of inputFiles) this._filesPendingListTests.files.add(file); return this._filesPendingListTests.promise; diff --git a/src/testModel.ts b/src/testModel.ts index 732875b0e..c42a8e635 100644 --- a/src/testModel.ts +++ b/src/testModel.ts @@ -204,7 +204,7 @@ export class TestModel { if (!sourcesToLoad.length) return []; - const { entries, errors } = await this._playwrightTest.listTests(this.config, this._mapSourcesToFiles(sourcesToLoad)); + const { entries, errors } = await this._playwrightTest.listTests(this.config, sourcesToLoad); this._updateProjects(entries, sourcesToLoad); return errors; } @@ -261,42 +261,15 @@ export class TestModel { } async runTests(projects: TestProject[], locations: string[] | null, testListener: TestListener, parametrizedTestTitle: string | undefined, token: vscodeTypes.CancellationToken) { - locations = locations ? this._mapSourcesToFiles(locations) : []; + locations = locations || []; await this._playwrightTest.runTests(this.config, projects.map(p => p.name), locations, testListener, parametrizedTestTitle, token); } async debugTests(projects: TestProject[], locations: string[] | null, testListener: TestListener, parametrizedTestTitle: string | undefined, token: vscodeTypes.CancellationToken) { - locations = locations ? this._mapSourcesToFiles(locations) : []; + locations = locations || []; await this._playwrightTest.debugTests(this._vscode, this.config, projects.map(p => p.name), projects.map(p => p.testDir), this._envProvider(), locations, testListener, parametrizedTestTitle, token); } - private _mapSourcesToFiles(sources: string[]): string[] { - const result: string[] = []; - - // When we see - // src/foo.ts in the source, - // we want to pass - // out/bundle.js:0 src/foo.ts - // This way we'll parse bundle.js and filter source-mapped tests by src/foo.ts - - // When we see - // src/foo.ts:14 in the source, - // we want to pass - // out/bundle.js:0 src/foo.ts:14 - // Same idea here, we'll parse bundle and filter by source-mapped location. - // It looks wrong, but it actually achieves the right result. - - for (const source of sources) { - const match = source.match(/^(.*)([:]\d+)$/); - const sourceFile = match ? match[1] : source; - const bundleFile = this._sourceToFile.get(sourceFile); - if (bundleFile) - result.push(bundleFile + ':0'); - result.push(source); - } - return result; - } - private _mapFilesToSources(files: Set): Set { const result = new Set(); for (const file of files) { diff --git a/tests/source-map.spec.ts b/tests/source-map.spec.ts index 023bfc587..9c6f1f34b 100644 --- a/tests/source-map.spec.ts +++ b/tests/source-map.spec.ts @@ -50,7 +50,7 @@ test('should list tests on expand', async ({ activate }) => { expect(vscode.renderExecLog(' ')).toBe(` > playwright list-files -c playwright.config.js - > playwright test -c playwright.config.js --list build/test.spec.js:0 tests/test.spec.ts + > playwright test -c playwright.config.js --list tests/test.spec.ts `); }); @@ -74,7 +74,7 @@ test('should list tests for visible editors', async ({ activate }) => { expect(vscode.renderExecLog(' ')).toBe(` > playwright list-files -c playwright.config.js - > playwright test -c playwright.config.js --list build/test.spec.js:0 tests/test.spec.ts + > playwright test -c playwright.config.js --list tests/test.spec.ts `); }); @@ -169,7 +169,7 @@ test('should discover new tests', async ({ activate }) => { expect(vscode.renderExecLog(' ')).toBe(` > playwright list-files -c playwright.config.js - > playwright test -c playwright.config.js --list build/test.spec.js:0 tests/test.spec.ts + > playwright test -c playwright.config.js --list tests/test.spec.ts `); await Promise.all([ @@ -189,8 +189,8 @@ test('should discover new tests', async ({ activate }) => { expect(vscode.renderExecLog(' ')).toBe(` > playwright list-files -c playwright.config.js - > playwright test -c playwright.config.js --list build/test.spec.js:0 tests/test.spec.ts - > playwright test -c playwright.config.js --list build/test.spec.js:0 tests/test.spec.ts + > playwright test -c playwright.config.js --list tests/test.spec.ts + > playwright test -c playwright.config.js --list tests/test.spec.ts `); }); @@ -242,8 +242,8 @@ test('should run one test', async ({ activate }) => { expect(vscode.renderExecLog(' ')).toBe(` > playwright list-files -c playwright.config.js - > playwright test -c playwright.config.js --list build/test.spec.js:0 tests/test.spec.ts - > playwright test -c playwright.config.js build/test.spec.js:0 tests/test.spec.ts:3 + > playwright test -c playwright.config.js --list tests/test.spec.ts + > playwright test -c playwright.config.js tests/test.spec.ts:3 `); });