{"action":"created","comment":{"url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/pulls/comments/27156704","id":27156704,"diff_hunk":"@@ -18,8 +26,177 @@ if ('win32' === process.platform) {\n var startSimulator = require('../../index');\n \n module.exports = {\n+\n   'startSimulator spawns with an available port': testStartSimulator(),\n-  'startSimulator spawns with specified port 2112': testStartSimulator(2112)\n+\n+  'startSimulator spawns with specified port 2112': testStartSimulator(2112),\n+\n+  'startSimulator.all() launches multiple simulators': function(test) {\n+\n+    var simulators = [\n+      { version: '1.4', bin: '/bin/b2g-1.4', profile: '/profile/b2g-1.4' },\n+      { version: '2.0', bin: '/bin/b2g-2.0', profile: '/profile/b2g-2.0' },\n+      { version: '2.2', bin: '/bin/b2g-2.2', profile: '/profile/b2g-2.2' }\n+    ];\n+\n+    var ports = [ 8008, 8010, 8012 ];\n+\n+    var mocked = nodemock.ignore('test');\n+\n+    // Mock up findSimulators fed by test data.\n+    mockery.registerMock('node-firefox-find-simulators', function(opts) {\n+      return new Promise(function(resolve, reject) {\n+        if (opts.version) {\n+          return resolve(simulators.filter(function(simulator) {\n+            return simulator.version === opts.version;\n+          }));\n+        }\n+        return resolve(simulators);\n+      });\n+    });\n+\n+    // Mock fs.existsSync that finds simulator binaries in test data.\n+    mockery.registerMock('fs', {\n+      existsSync: function(filename) {\n+        var found = simulators.filter(function(simulator) {\n+          return simulator.bin === filename;\n+        });\n+        return found.length > 0;\n+      }\n+    });\n+\n+    // Mock portfinder.getPort that pulls from a series of test ports.\n+    var portsIdx = 0;\n+    mockery.registerMock('portfinder', {\n+      getPort: function(callback) {\n+        callback(null, ports[portsIdx++]);\n+      }\n+    });\n+\n+    // Mock up child_process.spawn to assert expected launched simulators\n+    for (var spawnIndex = 0; spawnIndex < simulators.length; spawnIndex++) {\n+      var bin = simulators[spawnIndex].bin;\n+      var args = [\n+        '-profile', simulators[spawnIndex].profile,\n+        '-start-debugger-server', ports[spawnIndex],\n+        '-no-remote', '-foreground'\n+      ];\n+      var options = {\n+        'stdio': ['ignore','ignore','ignore'],\n+        'detached': true\n+      };\n+      mocked.mock('spawn')\n+        .takes(bin, args, options)\n+        .returns({\n+          pid: spawnIndex,\n+          bin: bin,\n+          args: args,\n+          options: options,\n+          unref: CALLBACK_TYPE\n+        });\n+    }\n+\n+    mockery.registerMock('child_process', {\n+      spawn: mocked.spawn\n+    });\n+\n+    for (var connectIndex = 0; connectIndex < ports.length; connectIndex++) {\n+      mocked.mock('connect')\n+        .takes(ports[connectIndex], 'localhost')\n+        .returns(true);\n+    }\n+\n+    function MockSocket() { /* no-op */ }\n+\n+    MockSocket.prototype = {\n+      connect: function(port, host) {\n+        return mocked.connect(port, host);\n+      },\n+      on: function(event, callback) {\n+        if (event === 'connect') {\n+          setImmediate(callback);\n+        }\n+        return this;\n+      },\n+      destroy: function() {\n+        return true;\n+      }\n+    };\n+\n+    mockery.registerMock('net', {\n+      Socket: MockSocket\n+    });\n+\n+    // Enable mocks on a clear import cache\n+    mockery.enable({\n+      warnOnReplace: false,\n+      warnOnUnregistered: false,\n+      useCleanCache: true\n+    });\n+\n+    // Require a freshly imported forwardPorts for this test\n+    var startSimulatorWithMocks = require('../../index');\n+    var startSimulatorPromise = startSimulatorWithMocks.all({ detached: true })(simulators);\n+\n+    startSimulatorPromise.catch(function(err) {\n+      test.ifError(err);\n+      test.done();\n+    }).then(function(results) {\n+\n+      // console.log(JSON.stringify(results, null, ' '));\n+\n+      // Ensure all the mocks were called, and with the expected parameters\n+      test.ok(mocked.assert());\n+\n+      // Putting all the mocks together, this is what the results on the other\n+      // end should look like after \"starting\" simulators\n+      var expected = [];\n+      for (var simulatorIndex = 0; simulatorIndex < simulators.length; simulatorIndex++) {\n+        var simulator = simulators[simulatorIndex];\n+        expected.push({\n+          process: {\n+            pid: simulatorIndex,\n+            bin: simulator.bin,\n+            args: [\n+              '-profile', simulator.profile,\n+              '-start-debugger-server', ports[simulatorIndex],\n+              '-no-remote', '-foreground'\n+            ],\n+            options: {\n+              'stdio': [ 'ignore', 'ignore', 'ignore' ],\n+              'detached': true\n+            },\n+            unref: CALLBACK_TYPE\n+          },\n+          pid: simulatorIndex,\n+          port: ports[simulatorIndex],\n+          binary: simulator.bin,\n+          profile: simulator.profile\n+        });\n+      }\n+\n+      test.deepEqual(results, expected);\n+\n+      test.done();\n+    });\n+\n+  },\n+\n+  /*\n+  'startSimulator.all() launches only one simulator per unique version': function(test) {","path":"tests/unit/test.index.js","position":null,"original_position":177,"commit_id":"ace11f54c1a480f3781099b44b65a3381eab4125","original_commit_id":"e424b3e947a5eff380d4f4d4a6fb3932c37242a5","user":{"login":"tofumatt","id":90871,"avatar_url":"https://avatars.githubusercontent.com/u/90871?v=3","gravatar_id":"","url":"https://api.github.com/users/tofumatt","html_url":"https://github.com/tofumatt","followers_url":"https://api.github.com/users/tofumatt/followers","following_url":"https://api.github.com/users/tofumatt/following{/other_user}","gists_url":"https://api.github.com/users/tofumatt/gists{/gist_id}","starred_url":"https://api.github.com/users/tofumatt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tofumatt/subscriptions","organizations_url":"https://api.github.com/users/tofumatt/orgs","repos_url":"https://api.github.com/users/tofumatt/repos","events_url":"https://api.github.com/users/tofumatt/events{/privacy}","received_events_url":"https://api.github.com/users/tofumatt/received_events","type":"User","site_admin":false},"body":"ooooooh?","created_at":"2015-03-25T19:26:59Z","updated_at":"2015-03-25T19:26:59Z","html_url":"https://github.com/mozilla/node-firefox-start-simulator/pull/23#discussion_r27156704","pull_request_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/pulls/23","_links":{"self":{"href":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/pulls/comments/27156704"},"html":{"href":"https://github.com/mozilla/node-firefox-start-simulator/pull/23#discussion_r27156704"},"pull_request":{"href":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/pulls/23"}}},"pull_request":{"url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/pulls/23","id":31955406,"html_url":"https://github.com/mozilla/node-firefox-start-simulator/pull/23","diff_url":"https://github.com/mozilla/node-firefox-start-simulator/pull/23.diff","patch_url":"https://github.com/mozilla/node-firefox-start-simulator/pull/23.patch","issue_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/issues/23","number":23,"state":"open","locked":false,"title":"startSimulator.all() utility to work better with findSimulators()","user":{"login":"lmorchard","id":21687,"avatar_url":"https://avatars.githubusercontent.com/u/21687?v=3","gravatar_id":"","url":"https://api.github.com/users/lmorchard","html_url":"https://github.com/lmorchard","followers_url":"https://api.github.com/users/lmorchard/followers","following_url":"https://api.github.com/users/lmorchard/following{/other_user}","gists_url":"https://api.github.com/users/lmorchard/gists{/gist_id}","starred_url":"https://api.github.com/users/lmorchard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lmorchard/subscriptions","organizations_url":"https://api.github.com/users/lmorchard/orgs","repos_url":"https://api.github.com/users/lmorchard/repos","events_url":"https://api.github.com/users/lmorchard/events{/privacy}","received_events_url":"https://api.github.com/users/lmorchard/received_events","type":"User","site_admin":false},"body":"This enables simplified cooperation between `findSimulators()` and `startSimulator()` like so:\r\n```javascript\r\nfindSimulators().then(startSimulator.all({ detached: true }))\r\n```\r\nFor bonus points, I worked out how to test `startSimulator()` using mocks instead of launching external processes. I'll probably follow this PR up with refactorings to extend that approach to the other existing tests.","created_at":"2015-03-25T19:06:27Z","updated_at":"2015-03-25T19:26:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"55e574b82064f49ff5462ba73525bdd3f04ea6bb","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/pulls/23/commits","review_comments_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/pulls/23/comments","review_comment_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/issues/23/comments","statuses_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/statuses/ace11f54c1a480f3781099b44b65a3381eab4125","head":{"label":"lmorchard:22-work-with-findsimulator","ref":"22-work-with-findsimulator","sha":"ace11f54c1a480f3781099b44b65a3381eab4125","user":{"login":"lmorchard","id":21687,"avatar_url":"https://avatars.githubusercontent.com/u/21687?v=3","gravatar_id":"","url":"https://api.github.com/users/lmorchard","html_url":"https://github.com/lmorchard","followers_url":"https://api.github.com/users/lmorchard/followers","following_url":"https://api.github.com/users/lmorchard/following{/other_user}","gists_url":"https://api.github.com/users/lmorchard/gists{/gist_id}","starred_url":"https://api.github.com/users/lmorchard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lmorchard/subscriptions","organizations_url":"https://api.github.com/users/lmorchard/orgs","repos_url":"https://api.github.com/users/lmorchard/repos","events_url":"https://api.github.com/users/lmorchard/events{/privacy}","received_events_url":"https://api.github.com/users/lmorchard/received_events","type":"User","site_admin":false},"repo":{"id":29750176,"name":"node-firefox-start-simulator","full_name":"lmorchard/node-firefox-start-simulator","owner":{"login":"lmorchard","id":21687,"avatar_url":"https://avatars.githubusercontent.com/u/21687?v=3","gravatar_id":"","url":"https://api.github.com/users/lmorchard","html_url":"https://github.com/lmorchard","followers_url":"https://api.github.com/users/lmorchard/followers","following_url":"https://api.github.com/users/lmorchard/following{/other_user}","gists_url":"https://api.github.com/users/lmorchard/gists{/gist_id}","starred_url":"https://api.github.com/users/lmorchard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lmorchard/subscriptions","organizations_url":"https://api.github.com/users/lmorchard/orgs","repos_url":"https://api.github.com/users/lmorchard/repos","events_url":"https://api.github.com/users/lmorchard/events{/privacy}","received_events_url":"https://api.github.com/users/lmorchard/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/lmorchard/node-firefox-start-simulator","description":"Start a Firefox OS simulator","fork":true,"url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator","forks_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/forks","keys_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/teams","hooks_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/hooks","issue_events_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/issues/events{/number}","events_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/events","assignees_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/assignees{/user}","branches_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/branches{/branch}","tags_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/tags","blobs_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/git/refs{/sha}","trees_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/statuses/{sha}","languages_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/languages","stargazers_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/stargazers","contributors_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/contributors","subscribers_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/subscribers","subscription_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/subscription","commits_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/commits{/sha}","git_commits_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/git/commits{/sha}","comments_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/comments{/number}","issue_comment_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/issues/comments{/number}","contents_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/contents/{+path}","compare_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/merges","archive_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/downloads","issues_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/issues{/number}","pulls_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/pulls{/number}","milestones_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/milestones{/number}","notifications_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/labels{/name}","releases_url":"https://api.github.com/repos/lmorchard/node-firefox-start-simulator/releases{/id}","created_at":"2015-01-23T19:51:50Z","updated_at":"2015-02-23T20:05:31Z","pushed_at":"2015-03-25T19:12:41Z","git_url":"git://github.com/lmorchard/node-firefox-start-simulator.git","ssh_url":"git@github.com:lmorchard/node-firefox-start-simulator.git","clone_url":"https://github.com/lmorchard/node-firefox-start-simulator.git","svn_url":"https://github.com/lmorchard/node-firefox-start-simulator","homepage":"","size":227,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"mozilla:master","ref":"master","sha":"7ca46f60ec0e8541931fe28c6acffcef02ec114a","user":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"repo":{"id":29203665,"name":"node-firefox-start-simulator","full_name":"mozilla/node-firefox-start-simulator","owner":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla/node-firefox-start-simulator","description":"Start a Firefox OS simulator","fork":false,"url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator","forks_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/forks","keys_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/teams","hooks_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/hooks","issue_events_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/events","assignees_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/tags","blobs_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/languages","stargazers_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/stargazers","contributors_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/contributors","subscribers_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/subscribers","subscription_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/subscription","commits_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/issues/comments{/number}","contents_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/merges","archive_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/downloads","issues_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/labels{/name}","releases_url":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/releases{/id}","created_at":"2015-01-13T18:11:43Z","updated_at":"2015-02-23T20:02:59Z","pushed_at":"2015-03-25T19:12:42Z","git_url":"git://github.com/mozilla/node-firefox-start-simulator.git","ssh_url":"git@github.com:mozilla/node-firefox-start-simulator.git","clone_url":"https://github.com/mozilla/node-firefox-start-simulator.git","svn_url":"https://github.com/mozilla/node-firefox-start-simulator","homepage":"","size":333,"stargazers_count":3,"watchers_count":3,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":4,"forks":4,"open_issues":4,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/pulls/23"},"html":{"href":"https://github.com/mozilla/node-firefox-start-simulator/pull/23"},"issue":{"href":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/issues/23"},"comments":{"href":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/issues/23/comments"},"review_comments":{"href":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/pulls/23/comments"},"review_comment":{"href":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/pulls/23/commits"},"statuses":{"href":"https://api.github.com/repos/mozilla/node-firefox-start-simulator/statuses/ace11f54c1a480f3781099b44b65a3381eab4125"}}}}