Skip to content

Commit 63d86be

Browse files
falsandtruJonathan Ginsburg
authored and
Jonathan Ginsburg
committed
fix: pass integrity value
1 parent 84f7cc3 commit 63d86be

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

docs/config/02-files.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The `files` array determines which files are included in the browser, watched, a
1515
* **Default.** Will attempt to determine type based on file extension. If that fails, defaults to `js`.
1616
* **Possible Values:**
1717
* `css` - Include using `<link rel="stylesheet">` tag.
18-
* `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.
18+
* `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.
1919
* `js` - Include using `<script></script>` tag.
2020
* `module` - Include using `<script type="module"></script>` tag.
2121
* `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
5757
### `integrity`
5858
* **Type.** String
5959
* **Default.** `undefined`
60-
* **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.
60+
* **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.
6161

6262
## Pattern matching and `basePath`
6363
- All of the relative patterns will get resolved using the `basePath` first.

lib/config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function createPatternObject (pattern) {
6262
: new Pattern(pattern)
6363
} else if (helper.isObject(pattern) && pattern.pattern && helper.isString(pattern.pattern)) {
6464
return helper.isUrlAbsolute(pattern.pattern)
65-
? new UrlPattern(pattern.pattern, pattern.type)
65+
? new UrlPattern(pattern.pattern, pattern.type, pattern.integrity)
6666
: new Pattern(pattern.pattern, pattern.served, pattern.included, pattern.watched, pattern.nocache, pattern.type)
6767
} else {
6868
log.warn(`Invalid pattern ${pattern}!\n\tExpected string or object with "pattern" property.`)

test/unit/config.spec.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -453,13 +453,18 @@ describe('config', () => {
453453
it('should convert patterns to objects and set defaults', () => {
454454
const config = normalizeConfigWithDefaults({
455455
basePath: '/base',
456-
files: ['a/*.js', { pattern: 'b.js', watched: false, included: false }, { pattern: 'c.js' }],
456+
files: [
457+
'a/*.js',
458+
{ pattern: 'b.js', watched: false, included: false },
459+
{ pattern: 'c.js' },
460+
{ pattern: 'http://localhost/d.js', integrity: 'sha256-XXX' }
461+
],
457462
customContextFile: 'context.html',
458463
customDebugFile: 'debug.html',
459464
customClientContextFile: 'client_with_context.html'
460465
})
461466

462-
expect(config.files.length).to.equal(3)
467+
expect(config.files.length).to.equal(4)
463468

464469
let file = config.files.shift()
465470
expect(file.pattern).to.equal(resolveWinPath('/base/a/*.js'))
@@ -479,6 +484,13 @@ describe('config', () => {
479484
expect(file.served).to.equal(true)
480485
expect(file.watched).to.equal(true)
481486

487+
file = config.files.shift()
488+
expect(file.pattern).to.equal('http://localhost/d.js')
489+
expect(file.included).to.equal(true)
490+
expect(file.served).to.equal(false)
491+
expect(file.watched).to.equal(false)
492+
expect(file.integrity).to.equal('sha256-XXX')
493+
482494
expect(config.customContextFile).to.equal(resolveWinPath('/base/context.html'))
483495
expect(config.customDebugFile).to.equal(resolveWinPath('/base/debug.html'))
484496
expect(config.customClientContextFile).to.equal(resolveWinPath('/base/client_with_context.html'))

0 commit comments

Comments
 (0)