-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathlog-source-map-service.ts
141 lines (134 loc) · 5.41 KB
/
log-source-map-service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import { Yok } from "../../lib/common/yok";
import { assert } from "chai";
import * as path from "path";
import { LogSourceMapService } from "../../lib/services/log-source-map-service";
import { DevicePlatformsConstants } from "../../lib/common/mobile/device-platforms-constants";
import { FileSystem } from "../../lib/common/file-system";
import { stringReplaceAll } from "../../lib/common/helpers";
import { LoggerStub } from "../stubs";
let runtimeVersion = "6.0.0";
function createTestInjector(): IInjector {
const testInjector = new Yok();
testInjector.register("projectDataService", {
getProjectData: () => {
return {
getAppDirectoryRelativePath: () => {
return "src";
},
projectIdentifiers: {
android: "org.nativescript.sourceMap",
ios: "org.nativescript.sourceMap"
},
projectDir: "projectDir"
};
},
getNSValue: (projectDir: string, propertyName: string): any => {
return {
version: runtimeVersion
};
}
});
testInjector.register("platformsDataService", {
getPlatformData: (platform: string) => {
return {
appDestinationDirectoryPath: path.join(__dirname, "..", "files", "sourceMapBundle", platform.toLowerCase()),
frameworkPackageName: `tns-${platform.toLowerCase()}`
};
}
});
testInjector.register("fs", FileSystem);
testInjector.register("devicePlatformsConstants", DevicePlatformsConstants);
testInjector.register("logger", LoggerStub);
testInjector.register("logSourceMapService", LogSourceMapService);
return testInjector;
}
function toPlatformSep(filePath: string) {
return stringReplaceAll(filePath, "/", path.sep);
}
const testCases: IDictionary<Array<{ caseName: string, message: string, expected: string, runtimeVersion?: string }>> = {
"android": [
{
caseName: "trace message",
message: "JS: at module.exports.push../main-view-model.ts.HelloWorldModel.onTap (file:///data/data/org.nativescript.sourceMap/files/app/bundle.js:303:17)",
expected: `JS: at module.exports.push../main-view-model.ts.HelloWorldModel.onTap file: ${toPlatformSep("src/main-view-model.ts")}:30:16\n`
},
{
caseName: "error message",
message: "System.err: Frame: function:'module.exports.push../main-view-model.ts.HelloWorldModel.onTap', file:'file:///data/data/org.nativescript.sourceMap/files/app/bundle.js', line: 304, column: 15",
expected: `System.err: Frame: function:'module.exports.push../main-view-model.ts.HelloWorldModel.onTap', file:'file: ${toPlatformSep("src/main-view-model.ts")}:31:14\n`
},
{
caseName: "error message no match",
message: "System.err: Frame: function:'module.exports.push../main-view-model.ts.HelloWorldModel.onTap', file:'file:///data/data/org.nativescript.sourceMap/files/app/bundle.js', line: 400, column: 15",
expected: "System.err: Frame: function:'module.exports.push../main-view-model.ts.HelloWorldModel.onTap', file:'file:///data/data/org.nativescript.sourceMap/files/app/bundle.js', line: 400, column: 15\n"
},
{
caseName: "no file match",
message: "System.err: at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1203)",
expected: "System.err: at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1203)\n"
}
],
"ios": [
{
caseName: "console message",
message: "CONSOLE LOG file:///app/bundle.js:294:20: Test.",
expected: `CONSOLE LOG file: ${toPlatformSep("src/main-view-model.ts")}:29:20 Test.\n`
},
{
caseName: "trace message",
message: "CONSOLE TRACE file:///app/bundle.js:295:22: Test",
expected: `CONSOLE TRACE file: ${toPlatformSep("src/main-view-model.ts")}:30:22 Test\n`
},
{
caseName: "error message",
message: "file:///app/bundle.js:296:32: JS ERROR Error: Test",
expected: `file: ${toPlatformSep("src/main-view-model.ts")}:31:31 JS ERROR Error: Test\n`
},
{
caseName: "error stack tracew",
message: "onTap@file:///app/bundle.js:296:32",
expected: `onTap@file: ${toPlatformSep("src/main-view-model.ts")}:31:31\n`
},
{
caseName: "error message no match",
message: "file:///app/bundle.js:400:32: JS ERROR Error: Test",
expected: "file:///app/bundle.js:400:32: JS ERROR Error: Test\n"
},
{
caseName: "error stack trace (new runtime)",
runtimeVersion: "6.1.0",
message: "onTap(file:///app/bundle.js:296:22)",
expected: `onTap(file: ${toPlatformSep("src/main-view-model.ts")}:31:18)\n`
},
]
};
describe("log-source-map-service", () => {
describe("replaceWithOriginalFileLocations", () => {
let logSourceMapService: Mobile.ILogSourceMapService;
let testInjector: IInjector;
beforeEach(async () => {
runtimeVersion = "6.0.0";
testInjector = createTestInjector();
logSourceMapService = testInjector.resolve("logSourceMapService");
const originalFilesLocation = path.join(__dirname, "..", "files", "sourceMapBundle");
const fs = testInjector.resolve<IFileSystem>("fs");
const files = fs.enumerateFilesInDirectorySync(originalFilesLocation);
for (const file of files) {
await logSourceMapService.setSourceMapConsumerForFile(file);
}
});
_.forEach(testCases, (cases, platform) => {
describe(platform, () => {
_.forEach(cases, testCase => {
it(testCase.caseName, () => {
if (testCase.runtimeVersion) {
runtimeVersion = testCase.runtimeVersion;
}
const result = logSourceMapService.replaceWithOriginalFileLocations(platform.toLowerCase(), testCase.message, { logLevel: "info", projectDir: "test" });
assert.equal(result, testCase.expected);
});
});
});
});
});
});