{"action":"created","comment":{"url":"https://api.github.com/repos/NativeScript/nativescript-cli/pulls/comments/41376366","id":41376366,"diff_hunk":"@@ -0,0 +1,227 @@\n+///<reference path=\"../.d.ts\"/>\n+\n+\"use strict\"\n+\n+import constants = require(\"../constants\");\n+import path = require('path');\n+import shell = require('shelljs');\n+import util = require('util');\n+import Future = require('fibers/future');\n+import os = require('os');\n+\n+interface ITestExecutionService {\n+\tstartTestRunner(platform: string): IFuture<void>;\n+}\n+\n+class TestExecutionService implements ITestExecutionService {\n+\tprivate static RUNNER_BASE_PATH = './tns_modules/unit-test-runner/'; \n+\tprivate static MAIN_APP_NAME = TestExecutionService.RUNNER_BASE_PATH + 'app.js';\n+\tprivate static CONFIG_FILE_NAME = TestExecutionService.RUNNER_BASE_PATH + 'config.js';\n+\tprivate static SOCKETIO_JS_FILE_NAME = TestExecutionService.RUNNER_BASE_PATH + 'socket.io.js';\n+\n+\tconstructor(\n+\t\tprivate $projectData: IProjectData,\n+\t\tprivate $platformService: IPlatformService,\n+\t\tprivate $platformsData: IPlatformsData,\n+\t\tprivate $usbLiveSyncServiceBase: IUsbLiveSyncServiceBase,\n+\t\tprivate $androidUsbLiveSyncServiceLocator: {factory: Function},\n+\t\tprivate $iosUsbLiveSyncServiceLocator: {factory: Function},\n+\t\tprivate $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,\n+\t\tprivate $resources: IResourceLoader,\n+\t\tprivate $httpClient: Server.IHttpClient,\n+\t\tprivate $fs: IFileSystem,\n+\t\tprivate $options: IOptions) {\n+\t}\n+\n+\tpublic startTestRunner(platform: string) : IFuture<void> {\n+\t\treturn (() => {\n+\t\t\tlet platformData = this.$platformsData.getPlatformData(platform);\n+\n+\t\t\tlet projectFilesPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME);\n+\t\t\t\n+\t\t\tthis.$platformService.preparePlatform(platform).wait();\n+\t\t\tthis.detourEntryPoint(projectFilesPath).wait();\n+\n+\t\t\tvar configJs = this.generateConfig(this.$options.port);\n+\t\t\tthis.$fs.writeFile(path.join(projectFilesPath, TestExecutionService.CONFIG_FILE_NAME), configJs).wait();\n+\t\t\t\n+\t\t\tvar socketIoJsUrl = `http://localhost:${this.$options.port}/socket.io/socket.io.js`;\n+\t\t\tvar socketIoJs = this.$httpClient.httpRequest(socketIoJsUrl).wait().body;\n+\t\t\tthis.$fs.writeFile(path.join(projectFilesPath, TestExecutionService.SOCKETIO_JS_FILE_NAME), socketIoJs).wait();\n+\n+\t\t\tlet watchGlob = path.join(this.$projectData.projectDir, constants.APP_FOLDER_NAME);\n+\n+\t\t\tlet platformSpecificLiveSyncServices: IDictionary<any> = {\n+\t\t\t\tandroid: (_device: Mobile.IDevice, $injector: IInjector): IPlatformSpecificLiveSyncService => {\n+\t\t\t\t\treturn $injector.resolve(this.$androidUsbLiveSyncServiceLocator.factory, {_device: _device});\n+\t\t\t\t},\n+\t\t\t\tios: (_device: Mobile.IDevice, $injector: IInjector) => {\n+\t\t\t\t\treturn $injector.resolve(this.$iosUsbLiveSyncServiceLocator.factory, {_device: _device});\n+\t\t\t\t}\n+\t\t\t};\n+\n+\t\t\tlet notInstalledAppOnDeviceAction = (device: Mobile.IDevice): IFuture<boolean> => {\n+\t\t\t\treturn (() => {\n+\t\t\t\t\tthis.$platformService.installOnDevice(platform).wait();\n+\t\t\t\t\tthis.detourEntryPoint(projectFilesPath).wait();\n+\t\t\t\t\treturn true;\n+\t\t\t\t}).future<boolean>()();\n+\t\t\t}\n+\n+\t\t\tlet notRunningiOSSimulatorAction = (): IFuture<void> => {\n+\t\t\t\treturn this.$platformService.deployOnEmulator(this.$devicePlatformsConstants.iOS.toLowerCase());\n+\t\t\t}\n+\n+\t\t\tlet beforeBatchLiveSyncAction = (filePath: string): IFuture<string> => {\n+\t\t\t\treturn (() => {\n+\t\t\t\t\tthis.$platformService.preparePlatform(platform).wait();\n+\t\t\t\t\treturn path.join(projectFilesPath, path.relative(path.join(this.$projectData.projectDir, constants.APP_FOLDER_NAME), filePath));\n+\t\t\t\t}).future<string>()();\n+\t\t\t}\n+\n+\t\t\tlet localProjectRootPath = platform.toLowerCase() === \"ios\" ? platformData.appDestinationDirectoryPath : null;\n+\t\t\tthis.$usbLiveSyncServiceBase.sync(platform,\n+\t\t\t\tthis.$projectData.projectId,\n+\t\t\t\tprojectFilesPath,\n+\t\t\t\tconstants.LIVESYNC_EXCLUDED_DIRECTORIES,\n+\t\t\t\twatchGlob,\n+\t\t\t\tplatformSpecificLiveSyncServices,\n+\t\t\t\tnotInstalledAppOnDeviceAction,\n+\t\t\t\tnotRunningiOSSimulatorAction,\n+\t\t\t\tlocalProjectRootPath,\n+\t\t\t\t(device: Mobile.IDevice, deviceAppData:Mobile.IDeviceAppData) => Future.fromResult(),\n+\t\t\t\tbeforeBatchLiveSyncAction).wait();\n+\n+\t\t}).future<void>()();\n+\t}\n+\n+\tallowedParameters: ICommandParameter[] = [];\n+\t\n+\tprivate detourEntryPoint(projectFilesPath: string): IFuture<void> {\n+\t\treturn (() => {\n+\t\t\tvar packageJsonPath = path.join(projectFilesPath, 'package.json');\n+\t\t\tvar packageJson = this.$fs.readJson(packageJsonPath).wait();\n+\t\t\tpackageJson.main = TestExecutionService.MAIN_APP_NAME;\n+\t\t\tthis.$fs.writeJson(packageJsonPath, packageJson).wait();\n+\t\t}).future<void>()();\n+\t}\n+\t\n+\tprivate generateConfig(port: Number): string {\n+\t\tlet nics = os.networkInterfaces();\n+\t\tlet ips = Object.keys(nics)\n+\t\t\t.map(nicName => nics[nicName].filter((binding: any) => binding.family === 'IPv4' && !binding.internal)[0])\n+\t\t\t.filter(binding => binding)\n+\t\t\t.map(binding => binding.address);\n+\t\n+\t\tvar config = {","path":"lib/commands/test.ts","position":116,"original_position":116,"commit_id":"18edb5e1f76402c6d661afe587eed9086d91957a","original_commit_id":"18edb5e1f76402c6d661afe587eed9086d91957a","user":{"login":"teobugslayer","id":5443453,"avatar_url":"https://avatars.githubusercontent.com/u/5443453?v=3","gravatar_id":"","url":"https://api.github.com/users/teobugslayer","html_url":"https://github.com/teobugslayer","followers_url":"https://api.github.com/users/teobugslayer/followers","following_url":"https://api.github.com/users/teobugslayer/following{/other_user}","gists_url":"https://api.github.com/users/teobugslayer/gists{/gist_id}","starred_url":"https://api.github.com/users/teobugslayer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/teobugslayer/subscriptions","organizations_url":"https://api.github.com/users/teobugslayer/orgs","repos_url":"https://api.github.com/users/teobugslayer/repos","events_url":"https://api.github.com/users/teobugslayer/events{/privacy}","received_events_url":"https://api.github.com/users/teobugslayer/received_events","type":"User","site_admin":false},"body":"You can use destructing here","created_at":"2015-10-07T10:54:20Z","updated_at":"2015-10-07T10:54:20Z","html_url":"https://github.com/NativeScript/nativescript-cli/pull/1016#discussion_r41376366","pull_request_url":"https://api.github.com/repos/NativeScript/nativescript-cli/pulls/1016","_links":{"self":{"href":"https://api.github.com/repos/NativeScript/nativescript-cli/pulls/comments/41376366"},"html":{"href":"https://github.com/NativeScript/nativescript-cli/pull/1016#discussion_r41376366"},"pull_request":{"href":"https://api.github.com/repos/NativeScript/nativescript-cli/pulls/1016"}}},"pull_request":{"url":"https://api.github.com/repos/NativeScript/nativescript-cli/pulls/1016","id":46905417,"html_url":"https://github.com/NativeScript/nativescript-cli/pull/1016","diff_url":"https://github.com/NativeScript/nativescript-cli/pull/1016.diff","patch_url":"https://github.com/NativeScript/nativescript-cli/pull/1016.patch","issue_url":"https://api.github.com/repos/NativeScript/nativescript-cli/issues/1016","number":1016,"state":"open","locked":false,"title":"`test init` and `test android|ios` commands","user":{"login":"tailsu","id":730130,"avatar_url":"https://avatars.githubusercontent.com/u/730130?v=3","gravatar_id":"","url":"https://api.github.com/users/tailsu","html_url":"https://github.com/tailsu","followers_url":"https://api.github.com/users/tailsu/followers","following_url":"https://api.github.com/users/tailsu/following{/other_user}","gists_url":"https://api.github.com/users/tailsu/gists{/gist_id}","starred_url":"https://api.github.com/users/tailsu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tailsu/subscriptions","organizations_url":"https://api.github.com/users/tailsu/orgs","repos_url":"https://api.github.com/users/tailsu/repos","events_url":"https://api.github.com/users/tailsu/events{/privacy}","received_events_url":"https://api.github.com/users/tailsu/received_events","type":"User","site_admin":false},"body":"Unit testing support for nativescript","created_at":"2015-10-06T13:54:18Z","updated_at":"2015-10-07T10:54:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b72922484720595da9add087293cdbdb1f564357","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/NativeScript/nativescript-cli/pulls/1016/commits","review_comments_url":"https://api.github.com/repos/NativeScript/nativescript-cli/pulls/1016/comments","review_comment_url":"https://api.github.com/repos/NativeScript/nativescript-cli/pulls/comments{/number}","comments_url":"https://api.github.com/repos/NativeScript/nativescript-cli/issues/1016/comments","statuses_url":"https://api.github.com/repos/NativeScript/nativescript-cli/statuses/18edb5e1f76402c6d661afe587eed9086d91957a","head":{"label":"NativeScript:sd/karma","ref":"sd/karma","sha":"18edb5e1f76402c6d661afe587eed9086d91957a","user":{"login":"NativeScript","id":7392261,"avatar_url":"https://avatars.githubusercontent.com/u/7392261?v=3","gravatar_id":"","url":"https://api.github.com/users/NativeScript","html_url":"https://github.com/NativeScript","followers_url":"https://api.github.com/users/NativeScript/followers","following_url":"https://api.github.com/users/NativeScript/following{/other_user}","gists_url":"https://api.github.com/users/NativeScript/gists{/gist_id}","starred_url":"https://api.github.com/users/NativeScript/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NativeScript/subscriptions","organizations_url":"https://api.github.com/users/NativeScript/orgs","repos_url":"https://api.github.com/users/NativeScript/repos","events_url":"https://api.github.com/users/NativeScript/events{/privacy}","received_events_url":"https://api.github.com/users/NativeScript/received_events","type":"Organization","site_admin":false},"repo":{"id":21347346,"name":"nativescript-cli","full_name":"NativeScript/nativescript-cli","owner":{"login":"NativeScript","id":7392261,"avatar_url":"https://avatars.githubusercontent.com/u/7392261?v=3","gravatar_id":"","url":"https://api.github.com/users/NativeScript","html_url":"https://github.com/NativeScript","followers_url":"https://api.github.com/users/NativeScript/followers","following_url":"https://api.github.com/users/NativeScript/following{/other_user}","gists_url":"https://api.github.com/users/NativeScript/gists{/gist_id}","starred_url":"https://api.github.com/users/NativeScript/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NativeScript/subscriptions","organizations_url":"https://api.github.com/users/NativeScript/orgs","repos_url":"https://api.github.com/users/NativeScript/repos","events_url":"https://api.github.com/users/NativeScript/events{/privacy}","received_events_url":"https://api.github.com/users/NativeScript/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/NativeScript/nativescript-cli","description":"Command-line interface for building NativeScript apps","fork":false,"url":"https://api.github.com/repos/NativeScript/nativescript-cli","forks_url":"https://api.github.com/repos/NativeScript/nativescript-cli/forks","keys_url":"https://api.github.com/repos/NativeScript/nativescript-cli/keys{/key_id}","collaborators_url":"https://api.github.com/repos/NativeScript/nativescript-cli/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/NativeScript/nativescript-cli/teams","hooks_url":"https://api.github.com/repos/NativeScript/nativescript-cli/hooks","issue_events_url":"https://api.github.com/repos/NativeScript/nativescript-cli/issues/events{/number}","events_url":"https://api.github.com/repos/NativeScript/nativescript-cli/events","assignees_url":"https://api.github.com/repos/NativeScript/nativescript-cli/assignees{/user}","branches_url":"https://api.github.com/repos/NativeScript/nativescript-cli/branches{/branch}","tags_url":"https://api.github.com/repos/NativeScript/nativescript-cli/tags","blobs_url":"https://api.github.com/repos/NativeScript/nativescript-cli/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/NativeScript/nativescript-cli/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/NativeScript/nativescript-cli/git/refs{/sha}","trees_url":"https://api.github.com/repos/NativeScript/nativescript-cli/git/trees{/sha}","statuses_url":"https://api.github.com/repos/NativeScript/nativescript-cli/statuses/{sha}","languages_url":"https://api.github.com/repos/NativeScript/nativescript-cli/languages","stargazers_url":"https://api.github.com/repos/NativeScript/nativescript-cli/stargazers","contributors_url":"https://api.github.com/repos/NativeScript/nativescript-cli/contributors","subscribers_url":"https://api.github.com/repos/NativeScript/nativescript-cli/subscribers","subscription_url":"https://api.github.com/repos/NativeScript/nativescript-cli/subscription","commits_url":"https://api.github.com/repos/NativeScript/nativescript-cli/commits{/sha}","git_commits_url":"https://api.github.com/repos/NativeScript/nativescript-cli/git/commits{/sha}","comments_url":"https://api.github.com/repos/NativeScript/nativescript-cli/comments{/number}","issue_comment_url":"https://api.github.com/repos/NativeScript/nativescript-cli/issues/comments{/number}","contents_url":"https://api.github.com/repos/NativeScript/nativescript-cli/contents/{+path}","compare_url":"https://api.github.com/repos/NativeScript/nativescript-cli/compare/{base}...{head}","merges_url":"https://api.github.com/repos/NativeScript/nativescript-cli/merges","archive_url":"https://api.github.com/repos/NativeScript/nativescript-cli/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/NativeScript/nativescript-cli/downloads","issues_url":"https://api.github.com/repos/NativeScript/nativescript-cli/issues{/number}","pulls_url":"https://api.github.com/repos/NativeScript/nativescript-cli/pulls{/number}","milestones_url":"https://api.github.com/repos/NativeScript/nativescript-cli/milestones{/number}","notifications_url":"https://api.github.com/repos/NativeScript/nativescript-cli/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/NativeScript/nativescript-cli/labels{/name}","releases_url":"https://api.github.com/repos/NativeScript/nativescript-cli/releases{/id}","created_at":"2014-06-30T10:21:20Z","updated_at":"2015-10-07T08:34:59Z","pushed_at":"2015-10-07T10:45:31Z","git_url":"git://github.com/NativeScript/nativescript-cli.git","ssh_url":"git@github.com:NativeScript/nativescript-cli.git","clone_url":"https://github.com/NativeScript/nativescript-cli.git","svn_url":"https://github.com/NativeScript/nativescript-cli","homepage":"https://www.npmjs.com/package/nativescript","size":40619,"stargazers_count":316,"watchers_count":316,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":54,"mirror_url":null,"open_issues_count":112,"forks":54,"open_issues":112,"watchers":316,"default_branch":"master"}},"base":{"label":"NativeScript:master","ref":"master","sha":"b3f779dd3cdb15136a0c06744dbf1087d9a5e53a","user":{"login":"NativeScript","id":7392261,"avatar_url":"https://avatars.githubusercontent.com/u/7392261?v=3","gravatar_id":"","url":"https://api.github.com/users/NativeScript","html_url":"https://github.com/NativeScript","followers_url":"https://api.github.com/users/NativeScript/followers","following_url":"https://api.github.com/users/NativeScript/following{/other_user}","gists_url":"https://api.github.com/users/NativeScript/gists{/gist_id}","starred_url":"https://api.github.com/users/NativeScript/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NativeScript/subscriptions","organizations_url":"https://api.github.com/users/NativeScript/orgs","repos_url":"https://api.github.com/users/NativeScript/repos","events_url":"https://api.github.com/users/NativeScript/events{/privacy}","received_events_url":"https://api.github.com/users/NativeScript/received_events","type":"Organization","site_admin":false},"repo":{"id":21347346,"name":"nativescript-cli","full_name":"NativeScript/nativescript-cli","owner":{"login":"NativeScript","id":7392261,"avatar_url":"https://avatars.githubusercontent.com/u/7392261?v=3","gravatar_id":"","url":"https://api.github.com/users/NativeScript","html_url":"https://github.com/NativeScript","followers_url":"https://api.github.com/users/NativeScript/followers","following_url":"https://api.github.com/users/NativeScript/following{/other_user}","gists_url":"https://api.github.com/users/NativeScript/gists{/gist_id}","starred_url":"https://api.github.com/users/NativeScript/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NativeScript/subscriptions","organizations_url":"https://api.github.com/users/NativeScript/orgs","repos_url":"https://api.github.com/users/NativeScript/repos","events_url":"https://api.github.com/users/NativeScript/events{/privacy}","received_events_url":"https://api.github.com/users/NativeScript/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/NativeScript/nativescript-cli","description":"Command-line interface for building NativeScript apps","fork":false,"url":"https://api.github.com/repos/NativeScript/nativescript-cli","forks_url":"https://api.github.com/repos/NativeScript/nativescript-cli/forks","keys_url":"https://api.github.com/repos/NativeScript/nativescript-cli/keys{/key_id}","collaborators_url":"https://api.github.com/repos/NativeScript/nativescript-cli/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/NativeScript/nativescript-cli/teams","hooks_url":"https://api.github.com/repos/NativeScript/nativescript-cli/hooks","issue_events_url":"https://api.github.com/repos/NativeScript/nativescript-cli/issues/events{/number}","events_url":"https://api.github.com/repos/NativeScript/nativescript-cli/events","assignees_url":"https://api.github.com/repos/NativeScript/nativescript-cli/assignees{/user}","branches_url":"https://api.github.com/repos/NativeScript/nativescript-cli/branches{/branch}","tags_url":"https://api.github.com/repos/NativeScript/nativescript-cli/tags","blobs_url":"https://api.github.com/repos/NativeScript/nativescript-cli/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/NativeScript/nativescript-cli/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/NativeScript/nativescript-cli/git/refs{/sha}","trees_url":"https://api.github.com/repos/NativeScript/nativescript-cli/git/trees{/sha}","statuses_url":"https://api.github.com/repos/NativeScript/nativescript-cli/statuses/{sha}","languages_url":"https://api.github.com/repos/NativeScript/nativescript-cli/languages","stargazers_url":"https://api.github.com/repos/NativeScript/nativescript-cli/stargazers","contributors_url":"https://api.github.com/repos/NativeScript/nativescript-cli/contributors","subscribers_url":"https://api.github.com/repos/NativeScript/nativescript-cli/subscribers","subscription_url":"https://api.github.com/repos/NativeScript/nativescript-cli/subscription","commits_url":"https://api.github.com/repos/NativeScript/nativescript-cli/commits{/sha}","git_commits_url":"https://api.github.com/repos/NativeScript/nativescript-cli/git/commits{/sha}","comments_url":"https://api.github.com/repos/NativeScript/nativescript-cli/comments{/number}","issue_comment_url":"https://api.github.com/repos/NativeScript/nativescript-cli/issues/comments{/number}","contents_url":"https://api.github.com/repos/NativeScript/nativescript-cli/contents/{+path}","compare_url":"https://api.github.com/repos/NativeScript/nativescript-cli/compare/{base}...{head}","merges_url":"https://api.github.com/repos/NativeScript/nativescript-cli/merges","archive_url":"https://api.github.com/repos/NativeScript/nativescript-cli/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/NativeScript/nativescript-cli/downloads","issues_url":"https://api.github.com/repos/NativeScript/nativescript-cli/issues{/number}","pulls_url":"https://api.github.com/repos/NativeScript/nativescript-cli/pulls{/number}","milestones_url":"https://api.github.com/repos/NativeScript/nativescript-cli/milestones{/number}","notifications_url":"https://api.github.com/repos/NativeScript/nativescript-cli/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/NativeScript/nativescript-cli/labels{/name}","releases_url":"https://api.github.com/repos/NativeScript/nativescript-cli/releases{/id}","created_at":"2014-06-30T10:21:20Z","updated_at":"2015-10-07T08:34:59Z","pushed_at":"2015-10-07T10:45:31Z","git_url":"git://github.com/NativeScript/nativescript-cli.git","ssh_url":"git@github.com:NativeScript/nativescript-cli.git","clone_url":"https://github.com/NativeScript/nativescript-cli.git","svn_url":"https://github.com/NativeScript/nativescript-cli","homepage":"https://www.npmjs.com/package/nativescript","size":40619,"stargazers_count":316,"watchers_count":316,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":54,"mirror_url":null,"open_issues_count":112,"forks":54,"open_issues":112,"watchers":316,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/NativeScript/nativescript-cli/pulls/1016"},"html":{"href":"https://github.com/NativeScript/nativescript-cli/pull/1016"},"issue":{"href":"https://api.github.com/repos/NativeScript/nativescript-cli/issues/1016"},"comments":{"href":"https://api.github.com/repos/NativeScript/nativescript-cli/issues/1016/comments"},"review_comments":{"href":"https://api.github.com/repos/NativeScript/nativescript-cli/pulls/1016/comments"},"review_comment":{"href":"https://api.github.com/repos/NativeScript/nativescript-cli/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/NativeScript/nativescript-cli/pulls/1016/commits"},"statuses":{"href":"https://api.github.com/repos/NativeScript/nativescript-cli/statuses/18edb5e1f76402c6d661afe587eed9086d91957a"}}}}