Skip to content

Commit

Permalink
fix: pass integrity value
Browse files Browse the repository at this point in the history
  • Loading branch information
falsandtru authored and Jonathan Ginsburg committed Sep 19, 2022
1 parent 84f7cc3 commit 63d86be
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docs/config/02-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.`)
Expand Down
16 changes: 14 additions & 2 deletions test/unit/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand All @@ -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'))
Expand Down

0 comments on commit 63d86be

Please sign in to comment.