From 8d262e3b1bf360bae7d5adb119e1f9f9701fd0a8 Mon Sep 17 00:00:00 2001
From: Timo Tijhof <krinklemail@gmail.com>
Date: Sun, 6 Jun 2021 22:15:00 +0100
Subject: [PATCH 1/5] Update js-reporters to 2.1.0

Important changes:

* Mocha 8 and later are now supported. Previously, it's pending tests
  were incorrectly reported as undefined or failing.

* `QUnit.todo()` is now supported. Previously, these intentional
  failures were reported by browserstack-runner as failing tests.

  With js-reported 2.1 the runEnd report counts them as `todo` instead
  of as `failed`.

The API that browserstack-runner depends on has not changed since 1.1.0.
<https://github.com/js-reporters/js-reporters/blob/v2.1.0/CHANGELOG.md>.

Specifically, browserstack-runner captures the following data in
lib/_patch/reporter.js, and proccesses it in lib/server.js under
the "_progress" and "_report" handlers:

* The `testEnd` event, reading:
  - `name` string,
  - `suiteName` string,
  - `status` string,
  - `errors` array.

* The `runEnd` event, reading:
  - `status` string,
  - `testCounts` object with ints `total`, `passed`, `failed`, `skipped`,
  - `runtime` int.

These still exist the same way in the latest release:
<https://github.com/js-reporters/js-reporters/blob/v2.1.0/spec/cri-draft.adoc#runend>

Fixes https://github.com/browserstack/browserstack-runner/issues/248.
Ref https://github.com/browserstack/browserstack-runner/issues/247.
---
 package-lock.json | 6 +++---
 package.json      | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/package-lock.json b/package-lock.json
index ecd9f4e..c73c967 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -886,9 +886,9 @@
       "optional": true
     },
     "js-reporters": {
-      "version": "1.1.0",
-      "resolved": "https://registry.npmjs.org/js-reporters/-/js-reporters-1.1.0.tgz",
-      "integrity": "sha1-yDwA/g1Mn2f5RLTt1fOylXSXzWI="
+      "version": "2.1.0",
+      "resolved": "https://registry.npmjs.org/js-reporters/-/js-reporters-2.1.0.tgz",
+      "integrity": "sha512-Q4GcEcPSb6ovhqp91claM3WPbSntQxbIn+3JiJgEXturys2ttWgs31VC60Yja+2unpNOH2A2qyjWFU2thCQ8sg=="
     },
     "jsbn": {
       "version": "0.1.1",
diff --git a/package.json b/package.json
index 276f7f2..bbee5d3 100644
--- a/package.json
+++ b/package.json
@@ -11,7 +11,7 @@
     "browserstack": "1.3.0",
     "chalk": "0.4.0",
     "circular-json": "0.3.1",
-    "js-reporters": "1.1.0",
+    "js-reporters": "2.1.0",
     "mime": "1.6.0",
     "resolve": "1.1.7",
     "send": "0.16.2",

From dab609e86244ff895fe8fae0f669fb57b1593faa Mon Sep 17 00:00:00 2001
From: Timo Tijhof <krinklemail@gmail.com>
Date: Sun, 6 Jun 2021 22:23:13 +0100
Subject: [PATCH 2/5] Fix reporting of QUnit todo tests

The update to js-reporters 2.1.0 in the previous commit has fixed
the most important problem, which is the build status reported
by the `runEnd` event, handled via "_report" submission.

However, the todo tests were still printed as errors in the output
which is confusing.

Before:

```
[Windows 8, Chrome 91.0] Error: "test.todo.each [0]" failed
  Expected: true
  Actual: false
[Windows 8, Chrome 91.0] Passed: 332 tests, 321 passed, 0 failed, 7 skipped; ran for 1255ms
```

After:

```
[Windows 10, Firefox 88.0] Passed: 332 tests, 321 passed, 0 failed, 7 skipped; ran for 1910ms
```

Fixes https://github.com/browserstack/browserstack-runner/issues/247.
---
 lib/server.js | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/lib/server.js b/lib/server.js
index 6058ca1..828a92e 100644
--- a/lib/server.js
+++ b/lib/server.js
@@ -387,17 +387,27 @@ exports.Server = function Server(bsClient, workers, config, callback) {
 
       logger.trace('[%s] _progress', worker.id, CircularJSON.stringify(query));
 
-      if (query && query.test && query.test.errors) {
+      if (query && query.test) {
+        // Include all tests in the report
         var browserReport = getBrowserReport(browserInfo);
         browserReport.tests.push(query.test || {});
 
-        query.test.errors.forEach(function(error) {
-          logger.info('[%s] ' + chalk.red('Error:'), browserInfo, formatTraceback({
-            error: error,
-            testName: query.test.name,
-            suiteName: query.test.suiteName
-          }));
-        });
+        // Only print errors of failed tests
+        // (errors from todo tests are expected and will not be reported as
+        // "failed" to the "_report" handler either, so printing them here
+        // would create a confusing output with error printed but a success
+        // status at the end)
+        // https://github.com/browserstack/browserstack-runner/issues/247
+        if (query.test.errors && query.test.status !== 'todo') {
+          query.test.errors.forEach(function(error) {
+            logger.info('[%s] ' + chalk.red('Error:'), browserInfo, formatTraceback({
+              testName: query.test.name,
+              suiteName: query.test.suiteName,
+              status: query.test.status,
+              error: error
+            }));
+          });
+        }
       }
       response.end();
     },

From 019946e1261992140a36d13067ec6afd9a38f4df Mon Sep 17 00:00:00 2001
From: Timo Tijhof <krinklemail@gmail.com>
Date: Sun, 6 Jun 2021 22:32:42 +0100
Subject: [PATCH 3/5] Tag 0.9.5-qunitjs.1

---
 .travis.yml       | 3 ---
 README.md         | 7 +++++--
 package-lock.json | 2 +-
 package.json      | 6 +++---
 4 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 45dbde0..cb0ca08 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,9 +3,6 @@ language: node_js
 node_js:
   - 'stable'
 
-before_install:
-  - npm install -g grunt-cli jshint gulp
-
 script:
   - npm run-script test-ci
 
diff --git a/README.md b/README.md
index 269106c..33c98b9 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,12 @@
 # BrowserStack Runner
 
-[![Build Status](https://travis-ci.org/browserstack/browserstack-runner.svg?branch=master)](https://travis-ci.org/browserstack/browserstack-runner)
-
 A command line interface to run browser tests over BrowserStack.
 
+## Hotfixes from [@qunitjs/browserstack-runner](https://github.com/qunitjs/browserstack-runner):
+
+1. Fix Mocha 8+ compat. [#248](https://github.com/browserstack/browserstack-runner/issues/248)
+2. Fix QUnit.todo breakage. [#247](https://github.com/browserstack/browserstack-runner/issues/247)
+
 ## Usage
 
 Install globally:
diff --git a/package-lock.json b/package-lock.json
index c73c967..ac13e26 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
 {
   "name": "browserstack-runner",
-  "version": "0.9.5",
+  "version": "0.9.5-qunitjs.1",
   "lockfileVersion": 1,
   "requires": true,
   "dependencies": {
diff --git a/package.json b/package.json
index bbee5d3..74d8c6a 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
 {
-  "name": "browserstack-runner",
-  "description": "A command line interface to run browser tests over BrowserStack",
-  "version": "0.9.5",
+  "name": "@qunitjs/browserstack-runner",
+  "description": "[Hotfix] run browser tests over BrowserStack",
+  "version": "0.9.5-qunitjs.1",
   "homepage": "https://github.com/browserstack/browserstack-runner",
   "repository": {
     "type": "git",

From 529d9dbd203519264245706b5a9b240b2903b6e2 Mon Sep 17 00:00:00 2001
From: Timo Tijhof <krinkle@fastmail.com>
Date: Wed, 29 May 2024 21:48:24 +0100
Subject: [PATCH 4/5] Use the `bs-local.com` hostname on OS X workers

Ref https://github.com/browserstack/browserstack-runner/issues/263.
---
 bin/cli.js | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/bin/cli.js b/bin/cli.js
index 5262736..983d762 100755
--- a/bin/cli.js
+++ b/bin/cli.js
@@ -106,7 +106,8 @@ function getTestBrowserInfo(browserString, path) {
 
 function buildTestUrl(test_path, worker_key, browser) {
   var host;
-  if (browser.os.toLowerCase() === 'ios' ){
+  // https://github.com/browserstack/browserstack-runner/issues/263
+  if (browser.os.toLowerCase() === 'ios' || browser.os === 'OS X') {
     host = 'bs-local.com';
   } else {
     host = 'localhost';

From 5ee0c5a2cb0f8d31addcffff9f912ef2260dfea3 Mon Sep 17 00:00:00 2001
From: Timo Tijhof <krinkle@fastmail.com>
Date: Wed, 29 May 2024 21:58:57 +0100
Subject: [PATCH 5/5] Tag 0.9.5-qunitjs.2

---
 package-lock.json | 4 ++--
 package.json      | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/package-lock.json b/package-lock.json
index ac13e26..20e20fa 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
 {
-  "name": "browserstack-runner",
-  "version": "0.9.5-qunitjs.1",
+  "name": "@qunitjs/browserstack-runner",
+  "version": "0.9.5-qunitjs.2",
   "lockfileVersion": 1,
   "requires": true,
   "dependencies": {
diff --git a/package.json b/package.json
index 74d8c6a..0740d97 100644
--- a/package.json
+++ b/package.json
@@ -1,11 +1,11 @@
 {
   "name": "@qunitjs/browserstack-runner",
   "description": "[Hotfix] run browser tests over BrowserStack",
-  "version": "0.9.5-qunitjs.1",
-  "homepage": "https://github.com/browserstack/browserstack-runner",
+  "version": "0.9.5-qunitjs.2",
+  "homepage": "https://github.com/qunitjs/browserstack-runner",
   "repository": {
     "type": "git",
-    "url": "https://github.com/browserstack/browserstack-runner.git"
+    "url": "https://github.com/qunitjs/browserstack-runner.git"
   },
   "dependencies": {
     "browserstack": "1.3.0",
@@ -26,7 +26,7 @@
   "licenses": [
     {
       "type": "MIT",
-      "url": "https://github.com/browserstack/browserstack-runner/blob/master/MIT-LICENSE.txt"
+      "url": "https://github.com/qunitjs/browserstack-runner/blob/master/MIT-LICENSE.txt"
     }
   ],
   "bin": {
