Skip to content

Commit

Permalink
fix: add importMapURL to manifest validation (#239)
Browse files Browse the repository at this point in the history
* fix: add `importMapURL` to manifest validation

* chore: improve test

* chore: update test title
  • Loading branch information
eduardoboucas committed Dec 6, 2022
1 parent 97afb8c commit 2ba1878
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = {
files: ['node/**/*.test.ts', 'vitest.config.ts'],
rules: {
'max-lines-per-function': 'off',
'max-nested-callbacks': 'off',
'max-statements': 'off',
'no-magic-numbers': 'off',
},
Expand Down
15 changes: 15 additions & 0 deletions node/validation/manifest/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ REQUIRED must have required property 'format'
6 | ],"
`;
exports[`import map URL > should throw on wrong type 1`] = `
"Validation of Edge Functions manifest failed
TYPE must be string
28 | ],
29 | \\"bundler_version\\": \\"1.6.0\\",
> 30 | \\"importMapURL\\": [
| ^
> 31 | \\"file:///root/.netlify/edge-functions-dist/import_map.json\\"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 32 | ]
| ^^^^ 👈🏽 type must be string
33 | }"
`;
exports[`layers > should throw on additional property 1`] = `
"Validation of Edge Functions manifest failed
ADDTIONAL PROPERTY must NOT have additional properties
Expand Down
19 changes: 17 additions & 2 deletions node/validation/manifest/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable max-nested-callbacks */
import { test, expect, describe } from 'vitest'

import { validateManifest, ManifestValidationError } from './index.js'
Expand Down Expand Up @@ -89,6 +88,7 @@ describe('bundle', () => {
expect(() => validateManifest(manifest)).toThrowErrorMatchingSnapshot()
})
})

describe('route', () => {
test('should throw on additional property', () => {
const manifest = getBaseManifest()
Expand Down Expand Up @@ -143,4 +143,19 @@ describe('layers', () => {
expect(() => validateManifest(manifest)).toThrowErrorMatchingSnapshot()
})
})
/* eslint-enable max-nested-callbacks */

describe('import map URL', () => {
test('should accept string value', () => {
const manifest = getBaseManifest()
manifest.importMapURL = 'file:///root/.netlify/edge-functions-dist/import_map.json'

expect(() => validateManifest(manifest)).not.toThrowError()
})

test('should throw on wrong type', () => {
const manifest = getBaseManifest()
manifest.importMapURL = ['file:///root/.netlify/edge-functions-dist/import_map.json']

expect(() => validateManifest(manifest)).toThrowErrorMatchingSnapshot()
})
})
1 change: 1 addition & 0 deletions node/validation/manifest/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const edgeManifestSchema = {
type: 'array',
items: layersSchema,
},
importMapURL: { type: 'string' },
bundler_version: { type: 'string' },
},
additionalProperties: false,
Expand Down

0 comments on commit 2ba1878

Please sign in to comment.