microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.6.15

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

test/debugger/sourceMap.test.ts

113lines · modeblame

3c172a05Artem Egorov8 years ago1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
4import {SourceMapUtil, IStrictUrl} from "../../src/debugger/sourceMap";
5
6import * as assert from "assert";
7import * as path from "path";
8import * as url from "url";
9
10suite("sourceMap", function() {
11suite("debuggerContext", function() {
12test("should convert host filesystem paths to URL-style-paths", function() {
13const sourceMap = new SourceMapUtil();
14const filePath = path.join("foo", "bar", "baz");
15const urlPath = "foo/bar/baz";
16const result = (<any>sourceMap).makeUnixStylePath(filePath);
17assert(result === urlPath, `Expected "${urlPath}", found "${result}"`);
18});
19
20test("should resolve a valid sourcemap url", function () {
21const scriptUrl: url.Url = url.parse("http://localhost:8081/index.ios.bundle?platform=ios&dev=true");
22const scriptBody = "//# sourceMappingURL=/index.ios.map?platform=ios&dev=true";
23const expectedUrlHref = "http://localhost:8081/index.ios.map?platform=ios&dev=true";
24
25const sourceMap = new SourceMapUtil();
26const result = sourceMap.getSourceMapURL(scriptUrl, scriptBody);
27assert.equal(expectedUrlHref, result && result.href);
28});
29
30test("should ignore inline sourcemap urls", function () {
31const scriptUrl: url.Url = url.parse("http://localhost:8081/index.ios.bundle?platform=ios&dev=true");
32const scriptBody = "//# sourceMappingURL=data:application/json;base64,eyJmb28iOiJiYXIifQ==\n" +
33"//# sourceMappingURL=/index.ios.map?platform=ios&dev=true";
34const expectedUrlHref = "http://localhost:8081/index.ios.map?platform=ios&dev=true";
35
36const sourceMap = new SourceMapUtil();
37const result = sourceMap.getSourceMapURL(scriptUrl, scriptBody);
38assert.equal(expectedUrlHref, result && result.href);
39});
40
41test("should return default IStrictUrl for an invalid sourcemap url", function () {
42const scriptUrl: url.Url = url.parse("http://localhost:8081/index.ios.bundle?platform=ios&dev=true");
43const scriptBody = "";
44
45const sourceMap = new SourceMapUtil();
46const result = sourceMap.getSourceMapURL(scriptUrl, scriptBody);
47assert.deepEqual(null, result);
48});
49
50test("should return default IStrictUrl if there are only inline sourcemap urls", function () {
51const scriptUrl: url.Url = url.parse("http://localhost:8081/index.ios.bundle?platform=ios&dev=true");
52const scriptBody = "//# sourceMappingURL=data:application/json;base64,eyJmb28iOiJiYXIifQ==\n" +
53"//# sourceMappingURL=data:application/json;base64,eyJiYXoiOiJxdXV4In0=";
54
55const sourceMap = new SourceMapUtil();
56const result = sourceMap.getSourceMapURL(scriptUrl, scriptBody);
57assert.deepEqual(null, result);
58});
59
60test("should update the contents of a source map file", function() {
61const sourceMapBody: string = JSON.stringify({"version": 3, "sources": ["test/index.ts"], "names": [], "mappings": "", "file": "test/index.js", "sourceRoot": "../../src"});
62const scriptPath: string = "test/newIndex.ts";
63const sourcesRootPath: string = "new/src";
64const expectedSourceMapBody: string = JSON.stringify({"version": 3, "sources": ["../../test/index.ts"], "names": [], "mappings": "", "file": scriptPath, "sourceRoot": ""});
65const sourceMap = new SourceMapUtil();
66
67const result: string = sourceMap.updateSourceMapFile(sourceMapBody, scriptPath, sourcesRootPath);
68assert.equal(expectedSourceMapBody, result);
69});
70
6eeec3c0Serge Svekolnikov8 years ago71test("should update source map file path for remote packager", function () {
72const localRoot = "/home/local";
73const remoteRoot = "/home/remote";
74const sourceMapBody: string = JSON.stringify({ "version": 3, "sources": [`${remoteRoot}/test/index.ts`], "names": [], "mappings": "", "file": "test/index.js", "sourceRoot": "../../src" });
75const scriptPath: string = "test/newIndex.ts";
76const sourcesRootPath: string = `${localRoot}/new/src`;
77const expectedSourceMapBody: string = JSON.stringify({ "version": 3, "sources": [`../../test/index.ts`], "names": [], "mappings": "", "file": scriptPath, "sourceRoot": "" });
78const sourceMap = new SourceMapUtil();
79
80const result: string = sourceMap.updateSourceMapFile(sourceMapBody, scriptPath, sourcesRootPath, remoteRoot, localRoot);
81assert.equal(expectedSourceMapBody, result);
82});
83
3c172a05Artem Egorov8 years ago84test("should update scripts with source mapping urls", function() {
85const scriptBody: string = "//# sourceMappingURL=/index.ios.map?platform=ios&dev=true";
86const sourceMappingUrl: IStrictUrl = <IStrictUrl>url.parse("/index.android.map");
87const expectedScriptBody = "//# sourceMappingURL=index.android.map";
88const sourceMap = new SourceMapUtil();
89
90const result = sourceMap.updateScriptPaths(scriptBody, sourceMappingUrl);
91assert.equal(expectedScriptBody, result);
92});
93
94test("should not update scripts without source mapping urls", function() {
95const scriptBody: string = "var path = require('path');";
96const sourceMappingUrl: IStrictUrl = <IStrictUrl>url.parse("/index.android.map");
97const sourceMap = new SourceMapUtil();
98
99const result = sourceMap.updateScriptPaths(scriptBody, sourceMappingUrl);
100assert.equal(scriptBody, result);
101});
102
103test("should update absolute source path to relative unix style path", function() {
104const sourcePath: string = "foo/bar";
105const sourcesRootPath: string = "baz/fuzz";
106const expectedPath: string = "../../foo/bar";
107const sourceMap = new SourceMapUtil();
108
109const result = (<any>sourceMap).updateSourceMapPath(sourcePath, sourcesRootPath);
110assert.equal(expectedPath, result);
111});
112});
113});