Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add importMapURL to manifest validation #239

Merged
merged 3 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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