microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
396b662796956f1b65b052a54f80995d4f21468c

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/test/debugger/sourceMapsCombinator.test.ts

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