Repository: karma-runner/karma
Pull request #3816 (2022-09-13 11:50:50)

fix: pass integrity value
SRI was not enabled.

falsandtru: @jginsburgn @devoto13 Can you review?
jginsburgn: > @jginsburgn @devoto13 Can you review?

Sorry it took so long, and btw I am no longer an active owner of the project. I may chime in here and then to contribute but it is better to rely on @karma-runner/google-web-test-team for active maintenance and guidance!

Patch:
diff --git a/docs/config/02-files.md b/docs/config/02-files.md
index 0bab8256..21b71903 100644
--- a/docs/config/02-files.md
+++ b/docs/config/02-files.md
@@ -15,7 +15,7 @@ The `files` array determines which files are included in the browser, watched, a
 * **Default.** Will attempt to determine type based on file extension. If that fails, defaults to `js`.
 * **Possible Values:**
   * `css` - Include using `<link rel="stylesheet">` tag.
-  * `html` - Include using [HTML Imports](https://developer.mozilla.org/en-US/docs/Web/Web_Components/HTML_Imports). Note that this feature is obsolete and does not work in the modern browsers. 
+  * `html` - Include using [HTML Imports](https://developer.mozilla.org/en-US/docs/Web/Web_Components/HTML_Imports). Note that this feature is obsolete and does not work in the modern browsers.
   * `js` - Include using `<script></script>` tag.
   * `module` - Include using `<script type="module"></script>` tag.
   * `dom` - Inline content of the file in the page. This can be used, for example, to test components combining HTML and JS.
@@ -57,7 +57,7 @@ The `files` array determines which files are included in the browser, watched, a
 ### `integrity`
 * **Type.** String
 * **Default.** `undefined`
-* **Description.** Set the `integrity` HTML attribute value to the `<script>` or the `<link>` tag to load the resource that matches the given pattern if the pattern is an absolute URL.
+* **Description.** Set the `integrity` HTML attribute value to the `<script>` or the `<link>` tag loading the resource that matches the given pattern if the pattern is an absolute URL.
 
 ## Pattern matching and `basePath`
 - All of the relative patterns will get resolved using the `basePath` first.
diff --git a/lib/config.js b/lib/config.js
index 0dff33c9..f98a34cc 100644
--- a/lib/config.js
+++ b/lib/config.js
@@ -62,7 +62,7 @@ function createPatternObject (pattern) {
       : new Pattern(pattern)
   } else if (helper.isObject(pattern) && pattern.pattern && helper.isString(pattern.pattern)) {
     return helper.isUrlAbsolute(pattern.pattern)
-      ? new UrlPattern(pattern.pattern, pattern.type)
+      ? new UrlPattern(pattern.pattern, pattern.type, pattern.integrity)
       : new Pattern(pattern.pattern, pattern.served, pattern.included, pattern.watched, pattern.nocache, pattern.type)
   } else {
     log.warn(`Invalid pattern ${pattern}!\n\tExpected string or object with "pattern" property.`)


Test patch:
diff --git a/test/unit/config.spec.js b/test/unit/config.spec.js
index ddab6791..55e6780d 100644
--- a/test/unit/config.spec.js
+++ b/test/unit/config.spec.js
@@ -453,13 +453,18 @@ describe('config', () => {
     it('should convert patterns to objects and set defaults', () => {
       const config = normalizeConfigWithDefaults({
         basePath: '/base',
-        files: ['a/*.js', { pattern: 'b.js', watched: false, included: false }, { pattern: 'c.js' }],
+        files: [
+          'a/*.js',
+          { pattern: 'b.js', watched: false, included: false },
+          { pattern: 'c.js' },
+          { pattern: 'http://localhost/d.js', integrity: 'sha256-XXX' }
+        ],
         customContextFile: 'context.html',
         customDebugFile: 'debug.html',
         customClientContextFile: 'client_with_context.html'
       })
 
-      expect(config.files.length).to.equal(3)
+      expect(config.files.length).to.equal(4)
 
       let file = config.files.shift()
       expect(file.pattern).to.equal(resolveWinPath('/base/a/*.js'))
@@ -479,6 +484,13 @@ describe('config', () => {
       expect(file.served).to.equal(true)
       expect(file.watched).to.equal(true)
 
+      file = config.files.shift()
+      expect(file.pattern).to.equal('http://localhost/d.js')
+      expect(file.included).to.equal(true)
+      expect(file.served).to.equal(false)
+      expect(file.watched).to.equal(false)
+      expect(file.integrity).to.equal('sha256-XXX')
+
       expect(config.customContextFile).to.equal(resolveWinPath('/base/context.html'))
       expect(config.customDebugFile).to.equal(resolveWinPath('/base/debug.html'))
       expect(config.customClientContextFile).to.equal(resolveWinPath('/base/client_with_context.html'))