From 125aa6e23c2c35a51582541d2420916f00d955c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Bou=C3=A7as?= Date: Tue, 6 Dec 2022 15:11:15 +0000 Subject: [PATCH 1/3] fix: add `importMapURL` to manifest validation --- .eslintrc.cjs | 1 + .../manifest/__snapshots__/index.test.ts.snap | 28 +++++++++---------- node/validation/manifest/index.test.ts | 4 +-- node/validation/manifest/schema.ts | 1 + 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 41aae38b..e4289b6a 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -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', }, diff --git a/node/validation/manifest/__snapshots__/index.test.ts.snap b/node/validation/manifest/__snapshots__/index.test.ts.snap index ae8f9cfa..a395e409 100644 --- a/node/validation/manifest/__snapshots__/index.test.ts.snap +++ b/node/validation/manifest/__snapshots__/index.test.ts.snap @@ -63,7 +63,7 @@ ADDTIONAL PROPERTY must NOT have additional properties | ^^^^^ 😲 foo is not expected to be here! 28 | } 29 | ], - 30 | \\"bundler_version\\": \\"1.6.0\\"" + 30 | \\"importMapURL\\": \\"file:///root/.netlify/edge-functions-dist/import_map.json\\"," `; exports[`layers > should throw on missing flag 1`] = ` @@ -148,29 +148,29 @@ exports[`should show multiple errors 1`] = ` "Validation of Edge Functions manifest failed ADDTIONAL PROPERTY must NOT have additional properties - 28 | ], - 29 | \\"bundler_version\\": \\"1.6.0\\", -> 30 | \\"foo\\": \\"bar\\", + 29 | \\"importMapURL\\": \\"file:///root/.netlify/edge-functions-dist/import_map.json\\", + 30 | \\"bundler_version\\": \\"1.6.0\\", +> 31 | \\"foo\\": \\"bar\\", | ^^^^^ 😲 foo is not expected to be here! - 31 | \\"baz\\": \\"bar\\" - 32 | } + 32 | \\"baz\\": \\"bar\\" + 33 | } ADDTIONAL PROPERTY must NOT have additional properties - 29 | \\"bundler_version\\": \\"1.6.0\\", - 30 | \\"foo\\": \\"bar\\", -> 31 | \\"baz\\": \\"bar\\" + 30 | \\"bundler_version\\": \\"1.6.0\\", + 31 | \\"foo\\": \\"bar\\", +> 32 | \\"baz\\": \\"bar\\" | ^^^^^ 😲 baz is not expected to be here! - 32 | }" + 33 | }" `; exports[`should throw on additional property on root level 1`] = ` "Validation of Edge Functions manifest failed ADDTIONAL PROPERTY must NOT have additional properties - 28 | ], - 29 | \\"bundler_version\\": \\"1.6.0\\", -> 30 | \\"foo\\": \\"bar\\" + 29 | \\"importMapURL\\": \\"file:///root/.netlify/edge-functions-dist/import_map.json\\", + 30 | \\"bundler_version\\": \\"1.6.0\\", +> 31 | \\"foo\\": \\"bar\\" | ^^^^^ 😲 foo is not expected to be here! - 31 | }" + 32 | }" `; diff --git a/node/validation/manifest/index.test.ts b/node/validation/manifest/index.test.ts index f0d228a8..68d7b5f8 100644 --- a/node/validation/manifest/index.test.ts +++ b/node/validation/manifest/index.test.ts @@ -1,4 +1,3 @@ -/* eslint-disable max-nested-callbacks */ import { test, expect, describe } from 'vitest' import { validateManifest, ManifestValidationError } from './index.js' @@ -33,6 +32,7 @@ const getBaseManifest = (): Record => ({ local: 'local', }, ], + importMapURL: 'file:///root/.netlify/edge-functions-dist/import_map.json', bundler_version: '1.6.0', }) @@ -89,6 +89,7 @@ describe('bundle', () => { expect(() => validateManifest(manifest)).toThrowErrorMatchingSnapshot() }) }) + describe('route', () => { test('should throw on additional property', () => { const manifest = getBaseManifest() @@ -143,4 +144,3 @@ describe('layers', () => { expect(() => validateManifest(manifest)).toThrowErrorMatchingSnapshot() }) }) -/* eslint-enable max-nested-callbacks */ diff --git a/node/validation/manifest/schema.ts b/node/validation/manifest/schema.ts index 381e7b86..b74c1e43 100644 --- a/node/validation/manifest/schema.ts +++ b/node/validation/manifest/schema.ts @@ -55,6 +55,7 @@ const edgeManifestSchema = { type: 'array', items: layersSchema, }, + importMapURL: { type: 'string' }, bundler_version: { type: 'string' }, }, additionalProperties: false, From 227db008a1d6621162334b5da633e7990d5a2293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Bou=C3=A7as?= Date: Tue, 6 Dec 2022 15:15:27 +0000 Subject: [PATCH 2/3] chore: improve test --- .../manifest/__snapshots__/index.test.ts.snap | 43 +++++++++++++------ node/validation/manifest/index.test.ts | 17 +++++++- 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/node/validation/manifest/__snapshots__/index.test.ts.snap b/node/validation/manifest/__snapshots__/index.test.ts.snap index a395e409..636ef61f 100644 --- a/node/validation/manifest/__snapshots__/index.test.ts.snap +++ b/node/validation/manifest/__snapshots__/index.test.ts.snap @@ -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 @@ -63,7 +78,7 @@ ADDTIONAL PROPERTY must NOT have additional properties | ^^^^^ 😲 foo is not expected to be here! 28 | } 29 | ], - 30 | \\"importMapURL\\": \\"file:///root/.netlify/edge-functions-dist/import_map.json\\"," + 30 | \\"bundler_version\\": \\"1.6.0\\"" `; exports[`layers > should throw on missing flag 1`] = ` @@ -148,29 +163,29 @@ exports[`should show multiple errors 1`] = ` "Validation of Edge Functions manifest failed ADDTIONAL PROPERTY must NOT have additional properties - 29 | \\"importMapURL\\": \\"file:///root/.netlify/edge-functions-dist/import_map.json\\", - 30 | \\"bundler_version\\": \\"1.6.0\\", -> 31 | \\"foo\\": \\"bar\\", + 28 | ], + 29 | \\"bundler_version\\": \\"1.6.0\\", +> 30 | \\"foo\\": \\"bar\\", | ^^^^^ 😲 foo is not expected to be here! - 32 | \\"baz\\": \\"bar\\" - 33 | } + 31 | \\"baz\\": \\"bar\\" + 32 | } ADDTIONAL PROPERTY must NOT have additional properties - 30 | \\"bundler_version\\": \\"1.6.0\\", - 31 | \\"foo\\": \\"bar\\", -> 32 | \\"baz\\": \\"bar\\" + 29 | \\"bundler_version\\": \\"1.6.0\\", + 30 | \\"foo\\": \\"bar\\", +> 31 | \\"baz\\": \\"bar\\" | ^^^^^ 😲 baz is not expected to be here! - 33 | }" + 32 | }" `; exports[`should throw on additional property on root level 1`] = ` "Validation of Edge Functions manifest failed ADDTIONAL PROPERTY must NOT have additional properties - 29 | \\"importMapURL\\": \\"file:///root/.netlify/edge-functions-dist/import_map.json\\", - 30 | \\"bundler_version\\": \\"1.6.0\\", -> 31 | \\"foo\\": \\"bar\\" + 28 | ], + 29 | \\"bundler_version\\": \\"1.6.0\\", +> 30 | \\"foo\\": \\"bar\\" | ^^^^^ 😲 foo is not expected to be here! - 32 | }" + 31 | }" `; diff --git a/node/validation/manifest/index.test.ts b/node/validation/manifest/index.test.ts index 68d7b5f8..040f8e0f 100644 --- a/node/validation/manifest/index.test.ts +++ b/node/validation/manifest/index.test.ts @@ -32,7 +32,6 @@ const getBaseManifest = (): Record => ({ local: 'local', }, ], - importMapURL: 'file:///root/.netlify/edge-functions-dist/import_map.json', bundler_version: '1.6.0', }) @@ -144,3 +143,19 @@ describe('layers', () => { expect(() => validateManifest(manifest)).toThrowErrorMatchingSnapshot() }) }) + +describe('import map URL', () => { + test('should accept string valid', () => { + 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() + }) +}) From e65ab842ad33c669b1f52724a01544e4289d9853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Bou=C3=A7as?= Date: Tue, 6 Dec 2022 15:17:47 +0000 Subject: [PATCH 3/3] chore: update test title --- node/validation/manifest/index.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/validation/manifest/index.test.ts b/node/validation/manifest/index.test.ts index 040f8e0f..b11d3316 100644 --- a/node/validation/manifest/index.test.ts +++ b/node/validation/manifest/index.test.ts @@ -145,7 +145,7 @@ describe('layers', () => { }) describe('import map URL', () => { - test('should accept string valid', () => { + test('should accept string value', () => { const manifest = getBaseManifest() manifest.importMapURL = 'file:///root/.netlify/edge-functions-dist/import_map.json'