|
| 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