Repository: karma-runner/karma
Pull request #3650 (2021-02-08 09:56:33)

fix(commitlint): skip task on master
The rule between master and branch should be different to take the PR reference in consideration when merging.

---

This PR should be fixing the current build failure on master due to the latest commit message `fix: report launcher process error when exit event is not emitted (#3647)` being more than 72 characters (https://travis-ci.org/github/karma-runner/karma/jobs/757457475).

---

### Problem
The problem is that the same `header-max-length` rule is applied to master and the PR branches and when a PR branch is merged the commit message has the PR reference appended to it making the length longer and potentially breaking the `commitlint` on master

### Proposed Solution

Using different `header-max-length` rules for master and branches.

* `header-max-length` rule on master set to 80 characters to **temporary fix** the build on master and **then submit another PR to  set the header-max-length rule on master set to 72 characters.**
* `header-max-length` rule on branches set to 64 characters (72 - 8 characters for the PR reference)

devoto13: Hm, maybe it is better to simply disable commit message validation on `master`? 🤔 
AppVeyorBot: :white_check_mark: [Build karma 2926 completed](https://ci.appveyor.com/project/dignifiedquire/karma/builds/37661357) (commit https://github.com/karma-runner/karma/commit/c076f6b558 by @chrisbottin)
karmarunnerbot: :white_check_mark: [Build karma 529 completed](https://ci.appveyor.com/project/karmarunnerbot/karma/builds/37661359) (commit https://github.com/karma-runner/karma/commit/c076f6b558 by @chrisbottin)
karmarunnerbot: :white_check_mark: [Build karma 528 completed](https://ci.appveyor.com/project/karmarunnerbot/karma-8n04t/builds/37661360) (commit https://github.com/karma-runner/karma/commit/c076f6b558 by @chrisbottin)
chrisbottin: > Hm, maybe it is better to simply disable commit message validation on `master`? 🤔

@devoto13 yes we could do that but do you mean permanently? If we are happy with having no `commitlint` running on master then we can just disable it (I can submit another PR) ... otherwise we do need this PR to have different `header-max-length` rules.

Let me know
devoto13: Yes, permanently. If you think about it, the check is not really actionable: one can't revert or fix the commit in `master` branch. But it's just my opinion. It's up to @johnjbarton to decide which approach to use.
johnjbarton: Yes @devoto13  is right, I like the no-master solution better.  @chrisbottin can you do it?
karmarunnerbot: :white_check_mark: [Build karma 535 completed](https://ci.appveyor.com/project/karmarunnerbot/karma/builds/37759761) (commit https://github.com/karma-runner/karma/commit/138b283a52 by @chrisbottin)
AppVeyorBot: :white_check_mark: [Build karma 2932 completed](https://ci.appveyor.com/project/dignifiedquire/karma/builds/37759760) (commit https://github.com/karma-runner/karma/commit/138b283a52 by @chrisbottin)
karmarunnerbot: :white_check_mark: [Build karma 534 completed](https://ci.appveyor.com/project/karmarunnerbot/karma-8n04t/builds/37759762) (commit https://github.com/karma-runner/karma/commit/138b283a52 by @chrisbottin)
AppVeyorBot: :white_check_mark: [Build karma 2933 completed](https://ci.appveyor.com/project/dignifiedquire/karma/builds/37759909) (commit https://github.com/karma-runner/karma/commit/339ac71f89 by @chrisbottin)
karmarunnerbot: :white_check_mark: [Build karma 536 completed](https://ci.appveyor.com/project/karmarunnerbot/karma/builds/37759910) (commit https://github.com/karma-runner/karma/commit/339ac71f89 by @chrisbottin)
karmarunnerbot: :white_check_mark: [Build karma 535 completed](https://ci.appveyor.com/project/karmarunnerbot/karma-8n04t/builds/37759911) (commit https://github.com/karma-runner/karma/commit/339ac71f89 by @chrisbottin)
chrisbottin: @johnjbarton done as requested.

Patch:
diff --git a/.travis.yml b/.travis.yml
index 7c1e548d..e6bee9ac 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -19,7 +19,9 @@ jobs:
     - node_js: "14"
       script:
         - npm run init
-        - commitlint-travis
+        - if [[ "$TRAVIS_BRANCH" != "master" ]]; then
+            commitlint-travis;
+          fi;
         - npm run lint
         - npm run build:check
         - npm run test:unit
diff --git a/lib/middleware/karma.js b/lib/middleware/karma.js
index 3a34b4e5..37e9a46c 100644
--- a/lib/middleware/karma.js
+++ b/lib/middleware/karma.js
@@ -222,10 +222,10 @@ function createKarmaMiddleware (
           }) : []
 
           return data
-            .replace('%SCRIPTS%', scriptTags.join('\n'))
+            .replace('%SCRIPTS%', () => scriptTags.join('\n'))
             .replace('%CLIENT_CONFIG%', 'window.__karma__.config = ' + JSON.stringify(client) + ';\n')
-            .replace('%SCRIPT_URL_ARRAY%', 'window.__karma__.scriptUrls = ' + JSON.stringify(scriptUrls) + ';\n')
-            .replace('%MAPPINGS%', 'window.__karma__.files = {\n' + mappings.join(',\n') + '\n};\n')
+            .replace('%SCRIPT_URL_ARRAY%', () => 'window.__karma__.scriptUrls = ' + JSON.stringify(scriptUrls) + ';\n')
+            .replace('%MAPPINGS%', () => 'window.__karma__.files = {\n' + mappings.join(',\n') + '\n};\n')
             .replace('\n%X_UA_COMPATIBLE%', getXUACompatibleMetaElement(request.url))
         })
       })


Test patch:
diff --git a/test/unit/middleware/karma.spec.js b/test/unit/middleware/karma.spec.js
index 8a968262..b6a0d5d5 100644
--- a/test/unit/middleware/karma.spec.js
+++ b/test/unit/middleware/karma.spec.js
@@ -28,6 +28,7 @@ describe('middleware.karma', () => {
     karma: {
       static: {
         'client.html': mocks.fs.file(0, 'CLIENT HTML\n%X_UA_COMPATIBLE%%X_UA_COMPATIBLE_URL%'),
+        'client_with_context.html': mocks.fs.file(0, 'CLIENT_WITH_CONTEXT\n%SCRIPT_URL_ARRAY%'),
         'context.html': mocks.fs.file(0, 'CONTEXT\n%SCRIPTS%'),
         'debug.html': mocks.fs.file(0, 'DEBUG\n%SCRIPTS%\n%X_UA_COMPATIBLE%'),
         'karma.js': mocks.fs.file(0, 'root: %KARMA_URL_ROOT%, proxy: %KARMA_PROXY_PATH%, v: %KARMA_VERSION%')
@@ -214,6 +215,21 @@ describe('middleware.karma', () => {
     callHandlerWith('/__karma__/context.html')
   })
 
+  it('should serve context.html without using special patterns when replacing script tags', (done) => {
+    includedFiles([
+      new MockFile('/.yarn/$$virtual/first.js', 'sha123'),
+      new MockFile('/.yarn/$$virtual/second.dart', 'sha456')
+    ])
+
+    response.once('end', () => {
+      expect(nextSpy).not.to.have.been.called
+      expect(response).to.beServedAs(200, 'CONTEXT\n<script type="text/javascript" src="/__proxy__/__karma__/absolute/.yarn/$$virtual/first.js?sha123" crossorigin="anonymous"></script>\n<script type="text/javascript" src="/__proxy__/__karma__/absolute/.yarn/$$virtual/second.dart?sha456" crossorigin="anonymous"></script>')
+      done()
+    })
+
+    callHandlerWith('/__karma__/context.html')
+  })
+
   it('should serve context.html with replaced link tags', (done) => {
     includedFiles([
       new MockFile('/first.css', 'sha007'),
@@ -373,6 +389,20 @@ describe('middleware.karma', () => {
     callHandlerWith('/__karma__/context.html')
   })
 
+  it('should inline mappings without using special patterns', (done) => {
+    fsMock._touchFile('/karma/static/context.html', 0, '%MAPPINGS%')
+    servedFiles([
+      new MockFile('/.yarn/$$virtual/abc/a.js', 'sha_a')
+    ])
+
+    response.once('end', () => {
+      expect(response).to.beServedAs(200, "window.__karma__.files = {\n  '/__proxy__/__karma__/absolute/.yarn/$$virtual/abc/a.js': 'sha_a'\n};\n")
+      done()
+    })
+
+    callHandlerWith('/__karma__/context.html')
+  })
+
   it('should escape quotes in mappings with all served files', (done) => {
     fsMock._touchFile('/karma/static/context.html', 0, '%MAPPINGS%')
     servedFiles([
@@ -490,4 +520,19 @@ describe('middleware.karma', () => {
 
     callHandlerWith('/__karma__/debug.html')
   })
+
+  it('should serve client_with_context.html without using special patterns when replacing script urls', (done) => {
+    includedFiles([
+      new MockFile('/.yarn/$$virtual/first.js', 'sha123'),
+      new MockFile('/.yarn/$$virtual/second.dart', 'sha456')
+    ])
+
+    response.once('end', () => {
+      expect(nextSpy).not.to.have.been.called
+      expect(response).to.beServedAs(200, 'CLIENT_WITH_CONTEXT\nwindow.__karma__.scriptUrls = ["\\\\x3Cscript type=\\"text/javascript\\" src=\\"/__proxy__/__karma__/absolute/.yarn/$$virtual/first.js\\" crossorigin=\\"anonymous\\"\\\\x3E\\\\x3C/script\\\\x3E","\\\\x3Cscript type=\\"text/javascript\\" src=\\"/__proxy__/__karma__/absolute/.yarn/$$virtual/second.dart\\" crossorigin=\\"anonymous\\"\\\\x3E\\\\x3C/script\\\\x3E"];\n')
+      done()
+    })
+
+    callHandlerWith('/__karma__/client_with_context.html')
+  })
 })