microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.5.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

test/debugger/sourceMapsCombinator.test.ts

71lines · modeblame

9f75364dArtem 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
3c172a05Artem Egorov8 years ago4import { SourceMapsCombinator } from "../../src/debugger/sourceMapsCombinator";
5c8365a6Artem Egorov8 years ago5import { RawSourceMap } from "source-map";
9f75364dArtem Egorov8 years ago6
7import * as assert from "assert";
8import * as sinon from "sinon";
9import * as fs from "fs";
10import * as path from "path";
11
12suite("sourceMapsCombinator", function () {
13let sandbox: Sinon.SinonSandbox;
14
15setup(() => {
16sandbox = sinon.sandbox.create();
17});
18
19suiteTeardown(() => {
20sandbox.restore();
21});
22
23suite("#convert", function () {
24test("convert sourcemap", function () {
25const pathToJS = "d:/hello.js";
26const pathToTS = "d:/hello.ts";
27const sourcemapPath = "d:/hello.js.map";
28const codeJS = fs.readFileSync(path.resolve(__dirname, "assets/hello.js"));
678db279Artem Egorov8 years ago29const codeTS = fs.readFileSync(path.resolve(__dirname, "assets/hello.ts"));
5c8365a6Artem Egorov8 years ago30const sourcemap: RawSourceMap = {
9f75364dArtem Egorov8 years ago31"version": 3,
32"sources": [
33"d:/hello.ts",
34],
35"names": [],
36"mappings": "AAAA,MAAM,MAAM;IACR,YAAY,CAAC,OAAO,GAAG,EAAE,MAAM,CAAC;IAChC;IACA,OAAO,QAAQ,CAAC,EAAE;QACd,OAAO,OAAO,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO;IACtC;AACJ;;AAEA,MAAM,MAAM,EAAE,IAAI,KAAK,CAAC,gDAAgD,CAAC;;AAEzE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC", "file": "hello.js", "sourceRoot": "",
37};
38
39const expected = {
40"version": 3,
41"sources": [
42"d:/hello.ts",
43],
5c8365a6Artem Egorov8 years ago44"names": <string[]>[],
9f75364dArtem Egorov8 years ago45"mappings": "AAAA,IAAA,MAAM,EAAM,CAAA,SAAA,CAAA,EAAA;IACR,SAAA,KAAa,CAAA,GAAA,EAAO;QACpB,IAAA,CAAA,IAAA,EAAA,GAAA;IACA;SACI,CAAA,SAAO,CAAA,SAAc,EAAA,SAAM,CAAA,EAAO;QACtC,OAAA,OAAA,EAAA,IAAA,CAAA,IAAA,EAAA,OAAA;IACJ,CAAA;;AAEA,CAAA,CAAA,CAAA,CAAA;;AAEA,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC",
46};
47
5c8365a6Artem Egorov8 years ago48let rawBundleSourcemap: RawSourceMap = {
9f75364dArtem Egorov8 years ago49"version": 3,
50"sources": [
51"d:/hello.js",
52],
5c8365a6Artem Egorov8 years ago53"names": <string[]>[],
9f75364dArtem Egorov8 years ago54"mappings": "AAAA,IAAI,MAAM,EAAE,CAAC,SAAS,CAAC,EAAE;IACrB,SAAS,KAAK,CAAC,GAAG,EAAE;QAChB,IAAI,CAAC,IAAI,EAAE,GAAG;IAClB;IACA,KAAK,CAAC,SAAS,CAAC,SAAS,EAAE,SAAS,CAAC,EAAE;QACnC,OAAO,OAAO,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO;IACtC,CAAC;IACD,OAAO,KAAK;AAChB,CAAC,CAAC,CAAC,CAAC;AACJ,IAAI,MAAM,EAAE,IAAI,KAAK,CAAC,gDAAgD,CAAC;AACvE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC", "file": "hello.js", "sourceRoot": "",
55};
56
57const fsReadFileStub = sandbox.stub(fs, "readFileSync");
58
59fsReadFileStub.withArgs(pathToJS).returns(codeJS);
60fsReadFileStub.withArgs(pathToTS).returns(codeTS);
61fsReadFileStub.withArgs(sourcemapPath).returns(JSON.stringify(sourcemap));
62
63let sourceMapsCombinator = new SourceMapsCombinator();
64let result = sourceMapsCombinator.convert(rawBundleSourcemap);
65result.sources = result.sources.map(p => {
66return p.replace(/\\/g, "/");
67});
68assert.deepEqual(expected, result);
69});
70});
71});