microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
7b48f26eb8caae7ed9cc1a09249195dfed76fa76

Branches

Tags

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

Clone

HTTPS

Download ZIP

test/debugger/sourceMapsCombinator.test.ts

67lines · 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 { SourceMapsCombinator } from "../../src/debugger/sourceMapsCombinator";
5import { RawSourceMap } from "source-map";
6import assert = require("assert");
7import * as sinon from "sinon";
8import * as fs from "fs";
9import * as path from "path";
10
11suite("sourceMapsCombinator", function () {
12 suite("#convert", function () {
13 let fsReadFileStub: Sinon.SinonStub;
14 const pathToJS = "d:/hello.js";
15 const pathToTS = "d:/hello.ts";
16 const sourcemapPath = "d:/hello.js.map";
17 const codeJS = fs.readFileSync(path.resolve(__dirname, "assets/hello.js"));
18 const codeTS = fs.readFileSync(path.resolve(__dirname, "assets/hello.ts"));
19 const sourcemap: RawSourceMap = {
20 version: 3,
21 sources: ["d:/hello.ts"],
22 names: [],
23 mappings:
24 "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",
25 file: "hello.js",
26 sourceRoot: "",
27 };
28
29 setup(() => {
30 fsReadFileStub = sinon.stub(fs, "readFileSync");
31 fsReadFileStub.withArgs(pathToJS).returns(codeJS);
32 fsReadFileStub.withArgs(pathToTS).returns(codeTS);
33 fsReadFileStub.withArgs(sourcemapPath).returns(JSON.stringify(sourcemap));
34 });
35
36 teardown(() => {
37 fsReadFileStub.restore();
38 });
39
40 test("convert sourcemap", function () {
41 const expected = {
42 version: 3,
43 sources: ["d:/hello.ts"],
44 names: <string[]>[],
45 mappings:
46 "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",
47 };
48
49 const rawBundleSourcemap: RawSourceMap = {
50 version: 3,
51 sources: ["d:/hello.js"],
52 names: <string[]>[],
53 mappings:
54 "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",
55 file: "hello.js",
56 sourceRoot: "",
57 };
58
59 let sourceMapsCombinator = new SourceMapsCombinator();
60 let result = sourceMapsCombinator.convert(rawBundleSourcemap);
61 result.sources = result.sources.map(p => {
62 return p.replace(/\\/g, "/");
63 });
64 assert.deepEqual(expected, result);
65 });
66 });
67});
68