microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
f42e0082062bc77ebdb0bcadca1f33ae1fd67802

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/test/debugger/sourceMap.test.ts

100lines · 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
67d531f6Vladimir Kotikov9 years ago30test("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.href);
39});
40
6f664c64Joshua Skelton10 years ago41test("should return null 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(result === null);
48});
49
67d531f6Vladimir Kotikov9 years ago50test("should return null 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(result === null);
58});
59
eb4cb70cJoshua Skelton10 years ago60test("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";
b7085605Joshua Skelton10 years ago64const expectedSourceMapBody: string = JSON.stringify({"version": 3, "sources": ["../../test/index.ts"], "names": [], "mappings": "", "file": scriptPath, "sourceRoot": ""});
6f664c64Joshua Skelton10 years ago65const sourceMap = new SourceMapUtil();
66
67const result: string = sourceMap.updateSourceMapFile(sourceMapBody, scriptPath, sourcesRootPath);
eb4cb70cJoshua Skelton10 years ago68assert.equal(expectedSourceMapBody, result);
6f664c64Joshua Skelton10 years ago69});
70
eb4cb70cJoshua Skelton10 years ago71test("should update scripts with source mapping urls", function() {
72const scriptBody: string = "//# sourceMappingURL=/index.ios.map?platform=ios&dev=true";
73const sourceMappingUrl: url.Url = url.parse("/index.android.map");
74const expectedScriptBody = "//# sourceMappingURL=index.android.map";
75const sourceMap = new SourceMapUtil();
76
77const result = sourceMap.updateScriptPaths(scriptBody, sourceMappingUrl);
78assert.equal(expectedScriptBody, result);
79});
80
81test("should not update scripts without source mapping urls", function() {
82const scriptBody: string = "var path = require('path');";
83const sourceMappingUrl: url.Url = url.parse("/index.android.map");
84const sourceMap = new SourceMapUtil();
6f664c64Joshua Skelton10 years ago85
eb4cb70cJoshua Skelton10 years ago86const result = sourceMap.updateScriptPaths(scriptBody, sourceMappingUrl);
87assert.equal(scriptBody, result);
88});
89
90test("should update absolute source path to relative unix style path", function() {
91const sourcePath: string = "foo/bar";
92const sourcesRootPath: string = "baz/fuzz";
93const expectedPath: string = "../../foo/bar";
94const sourceMap = new SourceMapUtil();
95
96const result = (<any>sourceMap).updateSourceMapPath(sourcePath, sourcesRootPath);
97assert.equal(expectedPath, result);
98});
3c2eeb5cJimmy Thomson10 years ago99});
6f664c64Joshua Skelton10 years ago100});