PathTransformer tests for scriptParsed and stackTraceResponse
This commit is contained in:
Родитель
01b4a0b37b
Коммит
7ee4a05bbf
|
@ -87,15 +87,15 @@ export class PathTransformer implements IDebugTransformer {
|
|||
|
||||
public stackTraceResponse(response: IStackTraceResponseBody): void {
|
||||
response.stackFrames.forEach(frame => {
|
||||
// Try to resolve the url to a path in the workspace. If it's not in the workspace,
|
||||
// just use the script.url as-is.
|
||||
if (frame.source.path) {
|
||||
// Try to resolve the url to a path in the workspace. If it's not in the workspace,
|
||||
// just use the script.url as-is. It will be resolved or cleared by the SourceMapTransformer.
|
||||
const clientPath = this._webkitUrlToClientPath.has(frame.source.path) ?
|
||||
this._webkitUrlToClientPath.get(frame.source.path) :
|
||||
utils.webkitUrlToClientPath(this._webRoot, frame.source.path);
|
||||
|
||||
// Incoming stackFrames have sourceReference and path set. If the path was resolved to a file in the workspace,
|
||||
// clear the sourceReference since it's not needed. If it wasn't resolved, clear the path since it's inaccurate.
|
||||
// clear the sourceReference since it's not needed.
|
||||
if (clientPath) {
|
||||
frame.source.path = clientPath;
|
||||
frame.source.sourceReference = 0;
|
||||
|
|
|
@ -123,11 +123,9 @@ export class SourceMapTransformer implements IDebugTransformer {
|
|||
stackFrame.source.name = path.basename(mapped.path);
|
||||
stackFrame.line = mapped.line;
|
||||
stackFrame.column = mapped.column;
|
||||
} else {
|
||||
} else if (!utils.existsSync(stackFrame.source.path)) {
|
||||
// If the frame has not been mapped to a file that exists on disk, clear the path
|
||||
if (!utils.existsSync(stackFrame.source.path)) {
|
||||
stackFrame.source.path = undefined;
|
||||
}
|
||||
stackFrame.source.path = undefined;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
|
|
@ -97,7 +97,7 @@ suite('PathTransformer', () => {
|
|||
});
|
||||
|
||||
suite('scriptParsed', () => {
|
||||
test('Modifies args.source.path of the script parsed event', () => {
|
||||
test('modifies args.source.path of the script parsed event when the file can be mapped', () => {
|
||||
utilsMock.expects('webkitUrlToClientPath')
|
||||
.withExactArgs(/*webRoot=*/undefined, TARGET_URL).returns(CLIENT_PATH);
|
||||
|
||||
|
@ -106,5 +106,43 @@ suite('PathTransformer', () => {
|
|||
transformer.scriptParsed(scriptParsedArgs);
|
||||
assert.deepEqual(scriptParsedArgs, expectedScriptParsedArgs);
|
||||
});
|
||||
|
||||
test(`doesn't modify args.source.path when the file can't be mapped`, () => {
|
||||
utilsMock.expects('webkitUrlToClientPath')
|
||||
.withExactArgs(/*webRoot=*/undefined, TARGET_URL).returns('');
|
||||
|
||||
const scriptParsedArgs = <any>{ body: { scriptUrl: TARGET_URL } };
|
||||
const expectedScriptParsedArgs = <any>{ body: { scriptUrl: TARGET_URL } };
|
||||
transformer.scriptParsed(scriptParsedArgs);
|
||||
assert.deepEqual(scriptParsedArgs, expectedScriptParsedArgs);
|
||||
});
|
||||
});
|
||||
|
||||
suite('stackTraceResponse()', () => {
|
||||
const RUNTIME_LINES = [2, 5, 8];
|
||||
|
||||
test('modifies the source path and clears sourceReference when the file can be mapped', () => {
|
||||
utilsMock.expects('webkitUrlToClientPath')
|
||||
.thrice()
|
||||
.withExactArgs(undefined, TARGET_URL).returns(CLIENT_PATH);
|
||||
|
||||
const response = testUtils.getStackTraceResponseBody(TARGET_URL, RUNTIME_LINES, [1, 2, 3]);
|
||||
const expectedResponse = testUtils.getStackTraceResponseBody(CLIENT_PATH, RUNTIME_LINES);
|
||||
|
||||
transformer.stackTraceResponse(response);
|
||||
assert.deepEqual(response, expectedResponse);
|
||||
});
|
||||
|
||||
test(`doesn't modify the source path or clear the sourceReference when the file can't be mapped`, () => {
|
||||
utilsMock.expects('webkitUrlToClientPath')
|
||||
.thrice()
|
||||
.withExactArgs(undefined, TARGET_URL).returns('');
|
||||
|
||||
const response = testUtils.getStackTraceResponseBody(TARGET_URL, RUNTIME_LINES, [1, 2, 3]);
|
||||
const expectedResponse = testUtils.getStackTraceResponseBody(TARGET_URL, RUNTIME_LINES, [1, 2, 3]);
|
||||
|
||||
transformer.stackTraceResponse(response);
|
||||
assert.deepEqual(response, expectedResponse);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
import * as assert from 'assert';
|
||||
import * as mockery from 'mockery';
|
||||
import * as path from 'path';
|
||||
|
||||
import * as testUtils from '../../testUtils';
|
||||
import { ISourceMaps, MappingResult } from '../../../adapter/sourceMaps/sourceMaps';
|
||||
|
@ -154,33 +153,21 @@ suite('SourceMapTransformer', () => {
|
|||
});
|
||||
|
||||
suite('stackTraceResponse()', () => {
|
||||
function getResponseBody(aPath: string, lines: number[]): IStackTraceResponseBody {
|
||||
return {
|
||||
stackFrames: lines.map((line, i) => ({
|
||||
id: i,
|
||||
name: 'line ' + i,
|
||||
line,
|
||||
column: 0,
|
||||
source: { path: aPath, name: path.basename(aPath), sourceReference: 0 }
|
||||
}))
|
||||
};
|
||||
}
|
||||
|
||||
test('modifies the response stackFrames', () => {
|
||||
utilsMock.expects('existsSync')
|
||||
.thrice()
|
||||
.withExactArgs(AUTHORED_PATH).returns(true);
|
||||
|
||||
const response = getResponseBody(RUNTIME_PATH, RUNTIME_LINES);
|
||||
const expected = getResponseBody(AUTHORED_PATH, AUTHORED_LINES);
|
||||
const response = testUtils.getStackTraceResponseBody(RUNTIME_PATH, RUNTIME_LINES);
|
||||
const expected = testUtils.getStackTraceResponseBody(AUTHORED_PATH, AUTHORED_LINES);
|
||||
|
||||
getTransformer().stackTraceResponse(response);
|
||||
assert.deepEqual(response, expected);
|
||||
});
|
||||
|
||||
test('does nothing when there are no sourcemaps', () => {
|
||||
const response = getResponseBody(RUNTIME_PATH, RUNTIME_LINES);
|
||||
const expected = getResponseBody(RUNTIME_PATH, RUNTIME_LINES);
|
||||
const response = testUtils.getStackTraceResponseBody(RUNTIME_PATH, RUNTIME_LINES);
|
||||
const expected = testUtils.getStackTraceResponseBody(RUNTIME_PATH, RUNTIME_LINES);
|
||||
|
||||
getTransformer(false).stackTraceResponse(response);
|
||||
assert.deepEqual(response, expected);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
*--------------------------------------------------------*/
|
||||
|
||||
import * as path from 'path';
|
||||
import * as sinon from 'sinon';
|
||||
import * as mockery from 'mockery';
|
||||
|
||||
|
@ -100,3 +101,19 @@ export function registerEmptyMocks(moduleNames: string | string[]): void {
|
|||
mockery.registerMock(name, {});
|
||||
});
|
||||
}
|
||||
|
||||
export function getStackTraceResponseBody(aPath: string, lines: number[], sourceReferences: number[] = []): IStackTraceResponseBody {
|
||||
return {
|
||||
stackFrames: lines.map((line, i) => ({
|
||||
id: i,
|
||||
name: 'line ' + i,
|
||||
line,
|
||||
column: 0,
|
||||
source: {
|
||||
path: aPath,
|
||||
name: path.basename(aPath),
|
||||
sourceReference: sourceReferences[i] || 0
|
||||
}
|
||||
}))
|
||||
};
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче