microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
347157a16bae7b9c210a61fd9ef4cefccac35110

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/test/debugger/sourceMap.test.ts

79lines · modeblame

3c2eeb5cJimmy Thomson10 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} from "../../debugger/sourceMap";
5
6import * as assert from "assert";
81226dceJimmy Thomson10 years ago7import * as path from "path";
6f664c64Joshua Skelton10 years ago8import * as url from "url";
3c2eeb5cJimmy Thomson10 years ago9
10suite("sourceMap", function() {
11suite("debuggerContext", function() {
81226dceJimmy Thomson10 years ago12test("should convert host filesystem paths to URL-style-paths", function() {
3c2eeb5cJimmy Thomson10 years ago13const sourceMap = new SourceMapUtil();
81226dceJimmy Thomson10 years ago14const filePath = path.join("foo", "bar", "baz");
15const urlPath = "foo/bar/baz";
16const result = (<any>sourceMap).makeUnixStylePath(filePath);
6f664c64Joshua Skelton10 years ago17assert(result === urlPath, `Expected "${urlPath}", found "${result}"`);
3c2eeb5cJimmy Thomson10 years ago18});
81226dceJimmy Thomson10 years ago19
6f664c64Joshua Skelton10 years ago20test("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.href);
28});
29
30test("should return null for an invalid sourcemap url", function () {
31const scriptUrl: url.Url = url.parse("http://localhost:8081/index.ios.bundle?platform=ios&dev=true");
32const scriptBody = "";
33
34const sourceMap = new SourceMapUtil();
35const result = sourceMap.getSourceMapURL(scriptUrl, scriptBody);
36assert(result === null);
37});
38
eb4cb70cJoshua Skelton10 years ago39test("should update the contents of a source map file", function() {
40const sourceMapBody: string = JSON.stringify({"version": 3, "sources": ["test/index.ts"], "names": [], "mappings": "", "file": "test/index.js", "sourceRoot": "../../src"});
41const scriptPath: string = "test/newIndex.ts";
42const sourcesRootPath: string = "new/src";
43const expectedSourceMapBody: string = JSON.stringify({"version": 3, "sources": [path.relative(sourcesRootPath, "test/index.ts")], "names": [], "mappings": "", "file": scriptPath, "sourceRoot": ""});
6f664c64Joshua Skelton10 years ago44const sourceMap = new SourceMapUtil();
45
46const result: string = sourceMap.updateSourceMapFile(sourceMapBody, scriptPath, sourcesRootPath);
eb4cb70cJoshua Skelton10 years ago47assert.equal(expectedSourceMapBody, result);
6f664c64Joshua Skelton10 years ago48});
49
eb4cb70cJoshua Skelton10 years ago50test("should update scripts with source mapping urls", function() {
51const scriptBody: string = "//# sourceMappingURL=/index.ios.map?platform=ios&dev=true";
52const sourceMappingUrl: url.Url = url.parse("/index.android.map");
53const expectedScriptBody = "//# sourceMappingURL=index.android.map";
54const sourceMap = new SourceMapUtil();
55
56const result = sourceMap.updateScriptPaths(scriptBody, sourceMappingUrl);
57assert.equal(expectedScriptBody, result);
58});
59
60test("should not update scripts without source mapping urls", function() {
61const scriptBody: string = "var path = require('path');";
62const sourceMappingUrl: url.Url = url.parse("/index.android.map");
63const sourceMap = new SourceMapUtil();
6f664c64Joshua Skelton10 years ago64
eb4cb70cJoshua Skelton10 years ago65const result = sourceMap.updateScriptPaths(scriptBody, sourceMappingUrl);
66assert.equal(scriptBody, result);
67});
68
69test("should update absolute source path to relative unix style path", function() {
70const sourcePath: string = "foo/bar";
71const sourcesRootPath: string = "baz/fuzz";
72const expectedPath: string = "../../foo/bar";
73const sourceMap = new SourceMapUtil();
74
75const result = (<any>sourceMap).updateSourceMapPath(sourcePath, sourcesRootPath);
76assert.equal(expectedPath, result);
77});
3c2eeb5cJimmy Thomson10 years ago78});
6f664c64Joshua Skelton10 years ago79});