Skip to content

Commit

Permalink
test: unit tests for log-source-map-service
Browse files Browse the repository at this point in the history
  • Loading branch information
KristianDD committed Jun 20, 2019
1 parent 5673981 commit 311d6b3
Show file tree
Hide file tree
Showing 5 changed files with 736 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -40,6 +40,7 @@ docs/html
docs-cli

!test-scripts/*.js
!test/files/**/*.js

# From previous submodule
lib/common/*.js
Expand Down
1 change: 1 addition & 0 deletions Gruntfile.js
Expand Up @@ -114,6 +114,7 @@ module.exports = function (grunt) {

clean: {
src: ["test/**/*.js*",
"!test/files/**/*.js*",
"lib/**/*.js*",
"!test-scripts/**/*",
"!lib/common/vendor/*.js",
Expand Down
330 changes: 330 additions & 0 deletions test/files/sourceMapBundle/android/app/bundle.js

Large diffs are not rendered by default.

322 changes: 322 additions & 0 deletions test/files/sourceMapBundle/ios/app/bundle.js

Large diffs are not rendered by default.

82 changes: 82 additions & 0 deletions test/services/log-source-map-service.ts
@@ -0,0 +1,82 @@
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";

function createTestInjector(): IInjector {
const testInjector = new Yok();
testInjector.register("projectDataService", {
getProjectData: () => {
return {
getAppDirectoryRelativePath: () => {
return "src";
},
projectIdentifiers: {
android: "org.nativescript.sourceMap",
ios: "org.nativescript.sourceMap"
}
};
}
});
testInjector.register("platformsDataService", {
getPlatformData: (platform: string) => {
return {
appDestinationDirectoryPath: path.join(__dirname, ".." , "files", "sourceMapBundle", platform.toLowerCase())
};
}
});
testInjector.register("fs", FileSystem);
testInjector.register("devicePlatformsConstants", DevicePlatformsConstants);
testInjector.register("logSourceMapService", LogSourceMapService);

return testInjector;
}

const testCases: IDictionary<Array<{caseName: string, message: string, expected: string}>> = {
"android": [{
caseName: "trace massage",
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:///src/main-view-model.ts:30:16\n"
}, {
caseName: "error massage",
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:///src/main-view-model.ts:31:14\n"
}],
"ios": [{
caseName: "console massage",
message: "CONSOLE LOG file:///app/bundle.js:294:20: Test.",
expected: "CONSOLE LOG Test. file:///src/main-view-model.ts:29:20\n"
}, {
caseName: "trace massage",
message: "CONSOLE TRACE file:///app/bundle.js:295:22: Test",
expected: "CONSOLE TRACE Test file:///src/main-view-model.ts:30:22\n"
}, {
caseName: "error massage",
message: "file:///app/bundle.js:296:32: JS ERROR Error: Test",
expected: "JS ERROR Error Test file:///src/main-view-model.ts:31:31\n"
}]
};

describe("log-source-map-service", () => {
describe("replaceWithOriginalFileLocations", () => {
let logSourceMapService: Mobile.ILogSourceMapService;
before(() => {
const testInjector = createTestInjector();
logSourceMapService = testInjector.resolve("logSourceMapService");
});

_.forEach(testCases, ( cases, platform ) => {
describe(platform, () => {
_.forEach(cases, testCase => {
it(testCase.caseName, () => {
const result = logSourceMapService.replaceWithOriginalFileLocations(platform.toLowerCase(), testCase.message, {logLevel:"info", projectDir: "test"});

assert.equal(result, testCase.expected);
});
});
});
});
});
});

0 comments on commit 311d6b3

Please sign in to comment.