Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ export async function resolveSourceMap(file: string, fileToSources: Map<string,
await new Promise(f => rl.on('close', f));

if (lastLine?.startsWith('//# sourceMappingURL=')) {
const sourceMappingFile = path.resolve(path.dirname(file), lastLine.substring('//# sourceMappingURL='.length));
const sourceMappingURL = lastLine.substring('//# sourceMappingURL='.length);
const inlineSourceMap = /^data:application\/json[^,]+base64,/.test(sourceMappingURL);
const sourceMappingFile = inlineSourceMap ? file : path.resolve(path.dirname(file), sourceMappingURL);
try {
const sourceMapping = await fs.promises.readFile(sourceMappingFile, 'utf-8');
const sourceMapping = inlineSourceMap ? Buffer.from(sourceMappingURL.substring(sourceMappingURL.indexOf(',') + 1), 'base64').toString() : await fs.promises.readFile(sourceMappingFile, 'utf-8');
const sources = JSON.parse(sourceMapping).sources;
const sourcePaths = sources.map((s: string) => {
const source = path.resolve(path.dirname(sourceMappingFile), s);
Expand Down
33 changes: 31 additions & 2 deletions tests/source-map.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,32 @@ test('should list files', async ({ activate }) => {
]);
});

test('should list tests with inline source map', async ({ activate }) => {
const { vscode, testController } = await activate({
'playwright.config.js': `module.exports = { testDir: 'build' }`,
'tests/test.spec.ts': testSpecTs,
'build/test.spec.js': testSpecJsWithInlineSourceMap('test.spec'),
});

await testController.expandTestItems(/test.spec.ts/);
await expect(testController).toHaveTestTree(`
- tests
- test.spec.ts
- one [2:0]
- two [3:0]
`);

await expect(vscode).toHaveConnectionLog([
{ method: 'listFiles', params: {} },
{
method: 'listTests',
params: expect.objectContaining({
locations: [expect.stringContaining(`tests${escapedPathSep}test\\.spec\\.ts`)],
})
},
]);
});

test('should list tests on expand', async ({ activate }) => {
const { vscode, testController } = await activate({
'playwright.config.js': `module.exports = { testDir: 'build' }`,
Expand Down Expand Up @@ -302,12 +328,12 @@ test('one', async ({}) => {});
test('two', async ({}) => {});`;


const testSpecJs = (name: string) => `var import_test = require("@playwright/test");
const testSpecJs = (name: string, sourceMappingURL = `${name}.js.map`) => `var import_test = require("@playwright/test");
(0, import_test.test)("one", async ({}) => {
});
(0, import_test.test)("two", async ({}) => {
});
//# sourceMappingURL=${name}.js.map`;
//# sourceMappingURL=${sourceMappingURL}`;


const testSpecJsMap = (name: string) => `{
Expand All @@ -318,6 +344,9 @@ const testSpecJsMap = (name: string) => `{
}`;


const testSpecJsWithInlineSourceMap = (name: string) => testSpecJs(name, `data:application/json;charset=utf-8;base64,${Buffer.from(testSpecJsMap(name)).toString('base64')}`);


const testSpecTsAfter = `import { test } from '@playwright/test';

test('new', async ({}) => {});
Expand Down
Loading