Skip to content

Commit 311d6b3

Browse files
committed
test: unit tests for log-source-map-service
1 parent 5673981 commit 311d6b3

File tree

5 files changed

+736
-0
lines changed

5 files changed

+736
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ docs/html
4040
docs-cli
4141

4242
!test-scripts/*.js
43+
!test/files/**/*.js
4344

4445
# From previous submodule
4546
lib/common/*.js

Gruntfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ module.exports = function (grunt) {
114114

115115
clean: {
116116
src: ["test/**/*.js*",
117+
"!test/files/**/*.js*",
117118
"lib/**/*.js*",
118119
"!test-scripts/**/*",
119120
"!lib/common/vendor/*.js",

test/files/sourceMapBundle/android/app/bundle.js

Lines changed: 330 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/files/sourceMapBundle/ios/app/bundle.js

Lines changed: 322 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { Yok } from "../../lib/common/yok";
2+
import { assert } from "chai";
3+
import * as path from "path";
4+
import { LogSourceMapService } from "../../lib/services/log-source-map-service";
5+
import { DevicePlatformsConstants } from "../../lib/common/mobile/device-platforms-constants";
6+
import { FileSystem } from "../../lib/common/file-system";
7+
8+
function createTestInjector(): IInjector {
9+
const testInjector = new Yok();
10+
testInjector.register("projectDataService", {
11+
getProjectData: () => {
12+
return {
13+
getAppDirectoryRelativePath: () => {
14+
return "src";
15+
},
16+
projectIdentifiers: {
17+
android: "org.nativescript.sourceMap",
18+
ios: "org.nativescript.sourceMap"
19+
}
20+
};
21+
}
22+
});
23+
testInjector.register("platformsDataService", {
24+
getPlatformData: (platform: string) => {
25+
return {
26+
appDestinationDirectoryPath: path.join(__dirname, ".." , "files", "sourceMapBundle", platform.toLowerCase())
27+
};
28+
}
29+
});
30+
testInjector.register("fs", FileSystem);
31+
testInjector.register("devicePlatformsConstants", DevicePlatformsConstants);
32+
testInjector.register("logSourceMapService", LogSourceMapService);
33+
34+
return testInjector;
35+
}
36+
37+
const testCases: IDictionary<Array<{caseName: string, message: string, expected: string}>> = {
38+
"android": [{
39+
caseName: "trace massage",
40+
message: "JS: at module.exports.push../main-view-model.ts.HelloWorldModel.onTap (file:///data/data/org.nativescript.sourceMap/files/app/bundle.js:303:17)",
41+
expected: "JS: at module.exports.push../main-view-model.ts.HelloWorldModel.onTap file:///src/main-view-model.ts:30:16\n"
42+
}, {
43+
caseName: "error massage",
44+
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",
45+
expected: "System.err: Frame: function:'module.exports.push../main-view-model.ts.HelloWorldModel.onTap', file:' file:///src/main-view-model.ts:31:14\n"
46+
}],
47+
"ios": [{
48+
caseName: "console massage",
49+
message: "CONSOLE LOG file:///app/bundle.js:294:20: Test.",
50+
expected: "CONSOLE LOG Test. file:///src/main-view-model.ts:29:20\n"
51+
}, {
52+
caseName: "trace massage",
53+
message: "CONSOLE TRACE file:///app/bundle.js:295:22: Test",
54+
expected: "CONSOLE TRACE Test file:///src/main-view-model.ts:30:22\n"
55+
}, {
56+
caseName: "error massage",
57+
message: "file:///app/bundle.js:296:32: JS ERROR Error: Test",
58+
expected: "JS ERROR Error Test file:///src/main-view-model.ts:31:31\n"
59+
}]
60+
};
61+
62+
describe("log-source-map-service", () => {
63+
describe("replaceWithOriginalFileLocations", () => {
64+
let logSourceMapService: Mobile.ILogSourceMapService;
65+
before(() => {
66+
const testInjector = createTestInjector();
67+
logSourceMapService = testInjector.resolve("logSourceMapService");
68+
});
69+
70+
_.forEach(testCases, ( cases, platform ) => {
71+
describe(platform, () => {
72+
_.forEach(cases, testCase => {
73+
it(testCase.caseName, () => {
74+
const result = logSourceMapService.replaceWithOriginalFileLocations(platform.toLowerCase(), testCase.message, {logLevel:"info", projectDir: "test"});
75+
76+
assert.equal(result, testCase.expected);
77+
});
78+
});
79+
});
80+
});
81+
});
82+
});

0 commit comments

Comments
 (0)