microsoft/vscode-react-native

Public

mirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
42fac1f6663b2a1aa7f248a34d66c3fd3144bc08

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/test/debugger/sourceMap.test.ts

79lines · modecode

1// 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} from "../../debugger/sourceMap";
5
6import * as assert from "assert";
7import * as path from "path";
8import * as url from "url";
9
10suite("sourceMap", function() {
11 suite("debuggerContext", function() {
12 test("should convert host filesystem paths to URL-style-paths", function() {
13 const sourceMap = new SourceMapUtil();
14 const filePath = path.join("foo", "bar", "baz");
15 const urlPath = "foo/bar/baz";
16 const result = (<any>sourceMap).makeUnixStylePath(filePath);
17 assert(result === urlPath, `Expected "${urlPath}", found "${result}"`);
18 });
19
20 test("should resolve a valid sourcemap url", function () {
21 const scriptUrl: url.Url = url.parse("http://localhost:8081/index.ios.bundle?platform=ios&dev=true");
22 const scriptBody = "//# sourceMappingURL=/index.ios.map?platform=ios&dev=true";
23 const expectedUrlHref = "http://localhost:8081/index.ios.map?platform=ios&dev=true";
24
25 const sourceMap = new SourceMapUtil();
26 const result = sourceMap.getSourceMapURL(scriptUrl, scriptBody);
27 assert.equal(expectedUrlHref, result.href);
28 });
29
30 test("should return null for an invalid sourcemap url", function () {
31 const scriptUrl: url.Url = url.parse("http://localhost:8081/index.ios.bundle?platform=ios&dev=true");
32 const scriptBody = "";
33
34 const sourceMap = new SourceMapUtil();
35 const result = sourceMap.getSourceMapURL(scriptUrl, scriptBody);
36 assert(result === null);
37 });
38
39 test("should update the contents of a source map file", function() {
40 const sourceMapBody: string = JSON.stringify({"version": 3, "sources": ["test/index.ts"], "names": [], "mappings": "", "file": "test/index.js", "sourceRoot": "../../src"});
41 const scriptPath: string = "test/newIndex.ts";
42 const sourcesRootPath: string = "new/src";
43 const expectedSourceMapBody: string = JSON.stringify({"version": 3, "sources": ["../../test/index.ts"], "names": [], "mappings": "", "file": scriptPath, "sourceRoot": ""});
44 const sourceMap = new SourceMapUtil();
45
46 const result: string = sourceMap.updateSourceMapFile(sourceMapBody, scriptPath, sourcesRootPath);
47 assert.equal(expectedSourceMapBody, result);
48 });
49
50 test("should update scripts with source mapping urls", function() {
51 const scriptBody: string = "//# sourceMappingURL=/index.ios.map?platform=ios&dev=true";
52 const sourceMappingUrl: url.Url = url.parse("/index.android.map");
53 const expectedScriptBody = "//# sourceMappingURL=index.android.map";
54 const sourceMap = new SourceMapUtil();
55
56 const result = sourceMap.updateScriptPaths(scriptBody, sourceMappingUrl);
57 assert.equal(expectedScriptBody, result);
58 });
59
60 test("should not update scripts without source mapping urls", function() {
61 const scriptBody: string = "var path = require('path');";
62 const sourceMappingUrl: url.Url = url.parse("/index.android.map");
63 const sourceMap = new SourceMapUtil();
64
65 const result = sourceMap.updateScriptPaths(scriptBody, sourceMappingUrl);
66 assert.equal(scriptBody, result);
67 });
68
69 test("should update absolute source path to relative unix style path", function() {
70 const sourcePath: string = "foo/bar";
71 const sourcesRootPath: string = "baz/fuzz";
72 const expectedPath: string = "../../foo/bar";
73 const sourceMap = new SourceMapUtil();
74
75 const result = (<any>sourceMap).updateSourceMapPath(sourcePath, sourcesRootPath);
76 assert.equal(expectedPath, result);
77 });
78 });
79});
80