diff --git a/package-lock.json b/package-lock.json index b43cb3d03c..2401d851ba 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1043,6 +1043,14 @@ "url": "https://github.com/sponsors/nzakas" } }, + "node_modules/@humanwhocodes/momoa": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/@humanwhocodes/momoa/-/momoa-2.0.4.tgz", + "integrity": "sha512-RE815I4arJFtt+FVeU1Tgp9/Xvecacji8w/V6XtXsWWH/wz/eNkNbhb+ny/+PlVZjV0rxQpRSQKNKE3lcktHEA==", + "engines": { + "node": ">=10.10.0" + } + }, "node_modules/@humanwhocodes/object-schema": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz", @@ -6553,11 +6561,14 @@ "link": true }, "node_modules/@netlify/edge-bundler": { - "version": "4.3.2", - "resolved": "https://registry.npmjs.org/@netlify/edge-bundler/-/edge-bundler-4.3.2.tgz", - "integrity": "sha512-wHAeLe6IAxf0DB3eqW3YWcjJoIGsOT5j/GlnIGtWCSEwl0TkwUTolThcY2FWLZyPJNv0jD+4XeLy/05Yw8FNCg==", + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/@netlify/edge-bundler/-/edge-bundler-4.4.0.tgz", + "integrity": "sha512-jJvoMA4UUB8wGzEH43z6uiE4/K/D/auO7CH3f8cgNlT8V885agT21nnXapIpSfugGemfghvP6ld/Ul+nI8GIxQ==", "dependencies": { "@import-maps/resolve": "^1.0.1", + "ajv": "^8.11.2", + "ajv-errors": "^3.0.0", + "better-ajv-errors": "^1.2.0", "common-path-prefix": "^3.0.0", "del": "^7.0.0", "env-paths": "^3.0.0", @@ -9166,9 +9177,9 @@ } }, "node_modules/ajv": { - "version": "8.11.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.11.0.tgz", - "integrity": "sha512-wGgprdCvMalC0BztXvitD2hC04YffAvtsUn93JbGXYLAtCUO4xd17mCCZQxUOItiBwZvJScWo8NIvQMQ71rdpg==", + "version": "8.11.2", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.11.2.tgz", + "integrity": "sha512-E4bfmKAhGiSTvMfL1Myyycaub+cUEU2/IvpylXkUu7CHBkBj1f/ikdzbD7YQ6FKUbixDxeYvB/xY4fvyroDlQg==", "dependencies": { "fast-deep-equal": "^3.1.1", "json-schema-traverse": "^1.0.0", @@ -9833,6 +9844,80 @@ "integrity": "sha512-NzUnlZexiaH/46WDhANlyR2bXRopNg4F/zuSA3OpZnllCUgRaOF2znDioDWrmbNVsuZk6l9pMquQB38cfBZwkQ==", "dev": true }, + "node_modules/better-ajv-errors": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/better-ajv-errors/-/better-ajv-errors-1.2.0.tgz", + "integrity": "sha512-UW+IsFycygIo7bclP9h5ugkNH8EjCSgqyFB/yQ4Hqqa1OEYDtb0uFIkYE0b6+CjkgJYVM5UKI/pJPxjYe9EZlA==", + "dependencies": { + "@babel/code-frame": "^7.16.0", + "@humanwhocodes/momoa": "^2.0.2", + "chalk": "^4.1.2", + "jsonpointer": "^5.0.0", + "leven": "^3.1.0 < 4" + }, + "engines": { + "node": ">= 12.13.0" + }, + "peerDependencies": { + "ajv": "4.11.8 - 8" + } + }, + "node_modules/better-ajv-errors/node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/better-ajv-errors/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/better-ajv-errors/node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/better-ajv-errors/node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + }, + "node_modules/better-ajv-errors/node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/bin-links": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/bin-links/-/bin-links-3.0.3.tgz", @@ -17352,6 +17437,14 @@ "node >= 0.2.0" ] }, + "node_modules/jsonpointer": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/jsonpointer/-/jsonpointer-5.0.1.tgz", + "integrity": "sha512-p/nXbhSEcu3pZRdkW1OfJhpsVtW1gd4Wa1fnQc9YLiTfAjn0312eMKimbdIQzuZl9aa9xUGaRlP9T/CJE/ditQ==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/JSONStream": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.5.tgz", @@ -25632,15 +25725,13 @@ "@bugsnag/js": "^7.0.0", "@netlify/cache-utils": "^5.0.2", "@netlify/config": "^20.0.1", - "@netlify/edge-bundler": "4.3.2", + "@netlify/edge-bundler": "4.4.0", "@netlify/functions-utils": "^5.0.4", "@netlify/git-utils": "^5.0.2", "@netlify/plugins-list": "^6.54.0", "@netlify/run-utils": "^5.0.2", "@netlify/zip-it-and-ship-it": "^7.1.2", "@sindresorhus/slugify": "^2.0.0", - "ajv": "^8.11.0", - "ajv-errors": "^3.0.0", "ansi-escapes": "^5.0.0", "chalk": "^5.0.0", "clean-stack": "^4.0.0", @@ -26898,6 +26989,11 @@ "integrity": "sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA==", "dev": true }, + "@humanwhocodes/momoa": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/@humanwhocodes/momoa/-/momoa-2.0.4.tgz", + "integrity": "sha512-RE815I4arJFtt+FVeU1Tgp9/Xvecacji8w/V6XtXsWWH/wz/eNkNbhb+ny/+PlVZjV0rxQpRSQKNKE3lcktHEA==" + }, "@humanwhocodes/object-schema": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz", @@ -31227,7 +31323,7 @@ "@bugsnag/js": "^7.0.0", "@netlify/cache-utils": "^5.0.2", "@netlify/config": "^20.0.1", - "@netlify/edge-bundler": "4.3.2", + "@netlify/edge-bundler": "4.4.0", "@netlify/functions-utils": "^5.0.4", "@netlify/git-utils": "^5.0.2", "@netlify/nock-udp": "^3.0.1", @@ -31237,8 +31333,6 @@ "@sindresorhus/slugify": "^2.0.0", "@types/node": "^14.18.31", "@types/statsd-client": "^0.4.3", - "ajv": "^8.11.0", - "ajv-errors": "^3.0.0", "ansi-escapes": "^5.0.0", "atob": "^2.1.2", "ava": "^4.0.0", @@ -31449,11 +31543,14 @@ } }, "@netlify/edge-bundler": { - "version": "4.3.2", - "resolved": "https://registry.npmjs.org/@netlify/edge-bundler/-/edge-bundler-4.3.2.tgz", - "integrity": "sha512-wHAeLe6IAxf0DB3eqW3YWcjJoIGsOT5j/GlnIGtWCSEwl0TkwUTolThcY2FWLZyPJNv0jD+4XeLy/05Yw8FNCg==", + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/@netlify/edge-bundler/-/edge-bundler-4.4.0.tgz", + "integrity": "sha512-jJvoMA4UUB8wGzEH43z6uiE4/K/D/auO7CH3f8cgNlT8V885agT21nnXapIpSfugGemfghvP6ld/Ul+nI8GIxQ==", "requires": { "@import-maps/resolve": "^1.0.1", + "ajv": "^8.11.2", + "ajv-errors": "^3.0.0", + "better-ajv-errors": "^1.2.0", "common-path-prefix": "^3.0.0", "del": "^7.0.0", "env-paths": "^3.0.0", @@ -33388,9 +33485,9 @@ } }, "ajv": { - "version": "8.11.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.11.0.tgz", - "integrity": "sha512-wGgprdCvMalC0BztXvitD2hC04YffAvtsUn93JbGXYLAtCUO4xd17mCCZQxUOItiBwZvJScWo8NIvQMQ71rdpg==", + "version": "8.11.2", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.11.2.tgz", + "integrity": "sha512-E4bfmKAhGiSTvMfL1Myyycaub+cUEU2/IvpylXkUu7CHBkBj1f/ikdzbD7YQ6FKUbixDxeYvB/xY4fvyroDlQg==", "requires": { "fast-deep-equal": "^3.1.1", "json-schema-traverse": "^1.0.0", @@ -33889,6 +33986,58 @@ "integrity": "sha512-NzUnlZexiaH/46WDhANlyR2bXRopNg4F/zuSA3OpZnllCUgRaOF2znDioDWrmbNVsuZk6l9pMquQB38cfBZwkQ==", "dev": true }, + "better-ajv-errors": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/better-ajv-errors/-/better-ajv-errors-1.2.0.tgz", + "integrity": "sha512-UW+IsFycygIo7bclP9h5ugkNH8EjCSgqyFB/yQ4Hqqa1OEYDtb0uFIkYE0b6+CjkgJYVM5UKI/pJPxjYe9EZlA==", + "requires": { + "@babel/code-frame": "^7.16.0", + "@humanwhocodes/momoa": "^2.0.2", + "chalk": "^4.1.2", + "jsonpointer": "^5.0.0", + "leven": "^3.1.0 < 4" + }, + "dependencies": { + "ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "requires": { + "color-convert": "^2.0.1" + } + }, + "chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + }, + "supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "requires": { + "has-flag": "^4.0.0" + } + } + } + }, "bin-links": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/bin-links/-/bin-links-3.0.3.tgz", @@ -39406,6 +39555,11 @@ "integrity": "sha1-P02uSpH6wxX3EGL4UhzCOfE2YoA=", "dev": true }, + "jsonpointer": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/jsonpointer/-/jsonpointer-5.0.1.tgz", + "integrity": "sha512-p/nXbhSEcu3pZRdkW1OfJhpsVtW1gd4Wa1fnQc9YLiTfAjn0312eMKimbdIQzuZl9aa9xUGaRlP9T/CJE/ditQ==" + }, "JSONStream": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.5.tgz", diff --git a/packages/build/package.json b/packages/build/package.json index 309e606374..53df9afe6d 100644 --- a/packages/build/package.json +++ b/packages/build/package.json @@ -66,15 +66,13 @@ "@bugsnag/js": "^7.0.0", "@netlify/cache-utils": "^5.0.2", "@netlify/config": "^20.0.1", - "@netlify/edge-bundler": "4.3.2", + "@netlify/edge-bundler": "4.4.0", "@netlify/functions-utils": "^5.0.4", "@netlify/git-utils": "^5.0.2", "@netlify/plugins-list": "^6.54.0", "@netlify/run-utils": "^5.0.2", "@netlify/zip-it-and-ship-it": "^7.1.2", "@sindresorhus/slugify": "^2.0.0", - "ajv": "^8.11.0", - "ajv-errors": "^3.0.0", "ansi-escapes": "^5.0.0", "chalk": "^5.0.0", "clean-stack": "^4.0.0", diff --git a/packages/build/src/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js b/packages/build/src/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js deleted file mode 100644 index 197af433f7..0000000000 --- a/packages/build/src/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +++ /dev/null @@ -1,110 +0,0 @@ -import { promises as fs } from 'fs' -import { join, resolve } from 'path' - -import Ajv from 'ajv' -import ajvErrors from 'ajv-errors' - -import { addErrorInfo } from '../../../error/info.js' - -const ajv = new Ajv({ allErrors: true }) -ajvErrors(ajv) - -// regex pattern for manifest route pattern -// checks if the pattern string starts with ^ and ends with $ -// we define this format in edge-bundler: -// https://github.com/netlify/edge-bundler/blob/main/src/manifest.ts#L66 -const normalizedPatternRegex = /^\^.*\$$/ -ajv.addFormat('regexPattern', { - async: true, - validate: (data) => normalizedPatternRegex.test(data), -}) - -const bundlesSchema = { - $async: true, - type: 'object', - required: ['asset', 'format'], - properties: { - asset: { type: 'string' }, - format: { type: 'string' }, - }, - additionalProperties: false, -} - -const routesSchema = { - $async: true, - type: 'object', - required: ['function', 'pattern'], - properties: { - name: { type: 'string' }, - function: { type: 'string' }, - pattern: { type: 'string', format: 'regexPattern', errorMessage: `must match format ${normalizedPatternRegex}` }, - }, - additionalProperties: false, -} - -const layersSchema = { - $async: true, - type: 'object', - required: ['flag', 'name'], - properties: { - flag: { type: 'string' }, - name: { type: 'string' }, - local: { type: 'string' }, - }, - additionalProperties: false, -} - -const edgeManifestSchema = { - $async: true, - type: 'object', - required: ['bundles', 'routes', 'bundler_version'], - properties: { - bundles: { - type: 'array', - items: bundlesSchema, - }, - routes: { - type: 'array', - items: routesSchema, - }, - post_cache_routes: { - type: 'array', - items: routesSchema, - }, - layers: { - type: 'array', - items: layersSchema, - }, - bundler_version: { type: 'string' }, - }, - additionalProperties: false, - errorMessage: "Couldn't validate Edge Functions manifest.json", -} - -const validateManifest = async (manifestData) => { - const validate = ajv.compile(edgeManifestSchema) - - await validate(manifestData) -} - -export const validateEdgeFunctionsManifest = async function ({ - buildDir, - constants: { EDGE_FUNCTIONS_DIST: distDirectory }, -}) { - try { - const edgeFunctionsDistPath = resolve(buildDir, distDirectory) - const manifestPath = join(edgeFunctionsDistPath, 'manifest.json') - const data = await fs.readFile(manifestPath) - const manifestData = JSON.parse(data) - - await validateManifest(manifestData) - } catch (error) { - const isValidationErr = error instanceof Ajv.ValidationError - const parsedErr = isValidationErr ? error.errors : error - - addErrorInfo(parsedErr, { type: 'coreStep' }) - throw new Error(isValidationErr ? JSON.stringify(parsedErr, null, 2) : parsedErr) - } - - return {} -} diff --git a/packages/build/src/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.ts b/packages/build/src/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.ts new file mode 100644 index 0000000000..eb155fcaa5 --- /dev/null +++ b/packages/build/src/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.ts @@ -0,0 +1,32 @@ +import { promises as fs } from 'fs' +import { join, resolve } from 'path' + +import { ManifestValidationError, validateManifest } from '@netlify/edge-bundler' + +import { addErrorInfo } from '../../../error/info.js' + +export const validateEdgeFunctionsManifest = async function ({ + buildDir, + constants: { EDGE_FUNCTIONS_DIST: distDirectory }, +}: { + buildDir: string + constants: { EDGE_FUNCTIONS_DIST: string } +}) { + const edgeFunctionsDistPath = resolve(buildDir, distDirectory) + const manifestPath = join(edgeFunctionsDistPath, 'manifest.json') + const data = await fs.readFile(manifestPath) + // @ts-expect-error TypeScript is not aware that parse can handle Buffer + const manifestData = JSON.parse(data) + + try { + validateManifest(manifestData) + } catch (error) { + if (error instanceof ManifestValidationError) { + addErrorInfo(error, { type: 'coreStep' }) + } + + throw error + } + + return {} +} diff --git a/packages/build/tests/edge_functions/snapshots/tests.js.snap b/packages/build/tests/edge_functions/snapshots/tests.js.snap index 73585d7837..29b869e9e7 100644 Binary files a/packages/build/tests/edge_functions/snapshots/tests.js.snap and b/packages/build/tests/edge_functions/snapshots/tests.js.snap differ diff --git a/packages/build/tests/unit/validate_edge_manifest/snapshots/tests.js.md b/packages/build/tests/unit/validate_edge_manifest/snapshots/tests.js.md index 54354b41b5..6bb2f6b34f 100644 --- a/packages/build/tests/unit/validate_edge_manifest/snapshots/tests.js.md +++ b/packages/build/tests/unit/validate_edge_manifest/snapshots/tests.js.md @@ -4,83 +4,22 @@ The actual snapshot is saved in `tests.js.snap`. Generated by [AVA](https://avajs.dev). -## should detect invalid route pattern in manifest +## should print error on invalid manifest > Snapshot 1 - `[␊ - {␊ - "instancePath": "/routes/2/pattern",␊ - "schemaPath": "#/properties/routes/items/properties/pattern/errorMessage",␊ - "keyword": "errorMessage",␊ - "params": {␊ - "errors": [␊ - {␊ - "instancePath": "/routes/2/pattern",␊ - "schemaPath": "#/properties/routes/items/properties/pattern/format",␊ - "keyword": "format",␊ - "params": {␊ - "format": "regexPattern"␊ - },␊ - "message": "must match format \\"regexPattern\\"",␊ - "emUsed": true␊ - }␊ - ]␊ - },␊ - "message": "must match format /^\\\\^.*\\\\$$/"␊ - }␊ - ]` + `Validation of Edge Functions manifest failed␊ + TYPE must be object␊ + ␊ + > 1 | "json"␊ +   | ^^^^^^ 👈🏽 type must be object` -## should detect missing property in manifest +## should print error on empty manifest > Snapshot 1 - `[␊ - {␊ - "instancePath": "",␊ - "schemaPath": "#/errorMessage",␊ - "keyword": "errorMessage",␊ - "params": {␊ - "errors": [␊ - {␊ - "instancePath": "/bundles/0",␊ - "schemaPath": "#/properties/bundles/items/required",␊ - "keyword": "required",␊ - "params": {␊ - "missingProperty": "format"␊ - },␊ - "message": "must have required property 'format'",␊ - "emUsed": true␊ - }␊ - ]␊ - },␊ - "message": "Couldn't validate Edge Functions manifest.json"␊ - }␊ - ]` - -## should detect extra property in manifest - -> Snapshot 1 - - `[␊ - {␊ - "instancePath": "",␊ - "schemaPath": "#/errorMessage",␊ - "keyword": "errorMessage",␊ - "params": {␊ - "errors": [␊ - {␊ - "instancePath": "/routes/0",␊ - "schemaPath": "#/properties/routes/items/additionalProperties",␊ - "keyword": "additionalProperties",␊ - "params": {␊ - "additionalProperty": "extra"␊ - },␊ - "message": "must NOT have additional properties",␊ - "emUsed": true␊ - }␊ - ]␊ - },␊ - "message": "Couldn't validate Edge Functions manifest.json"␊ - }␊ - ]` + `Validation of Edge Functions manifest failed␊ + REQUIRED must have required property 'bundler_version'␊ + ␊ + > 1 | {}␊ +   | ^ ☹️ bundler_version is missing here!` diff --git a/packages/build/tests/unit/validate_edge_manifest/snapshots/tests.js.snap b/packages/build/tests/unit/validate_edge_manifest/snapshots/tests.js.snap index f8c49b2a53..493c5159d1 100644 Binary files a/packages/build/tests/unit/validate_edge_manifest/snapshots/tests.js.snap and b/packages/build/tests/unit/validate_edge_manifest/snapshots/tests.js.snap differ diff --git a/packages/build/tests/unit/validate_edge_manifest/tests.js b/packages/build/tests/unit/validate_edge_manifest/tests.js index 1d0d49fec8..9e76d62f7a 100644 --- a/packages/build/tests/unit/validate_edge_manifest/tests.js +++ b/packages/build/tests/unit/validate_edge_manifest/tests.js @@ -15,33 +15,22 @@ test('should validate valid manifest', async (t) => { ) }) -test('should detect invalid route pattern in manifest', async (t) => { +test('should print error on invalid manifest', async (t) => { const error = await t.throwsAsync( validateEdgeFunctionsManifest({ buildDir: FIXTURES_DIR, - constants: { EDGE_FUNCTIONS_DIST: 'invalid_manifest_wrong_route_pattern' }, + constants: { EDGE_FUNCTIONS_DIST: 'invalid_manifest' }, }), ) t.snapshot(error.message) }) -test('should detect missing property in manifest', async (t) => { +test('should print error on empty manifest', async (t) => { const error = await t.throwsAsync( validateEdgeFunctionsManifest({ buildDir: FIXTURES_DIR, - constants: { EDGE_FUNCTIONS_DIST: 'invalid_manifest_missing_property' }, - }), - ) - - t.snapshot(error.message) -}) - -test('should detect extra property in manifest', async (t) => { - const error = await t.throwsAsync( - validateEdgeFunctionsManifest({ - buildDir: FIXTURES_DIR, - constants: { EDGE_FUNCTIONS_DIST: 'invalid_manifest_extra_property' }, + constants: { EDGE_FUNCTIONS_DIST: 'empty_manifest' }, }), ) diff --git a/packages/build/tests/unit/validate_edge_manifest/unit_fixtures/empty_manifest/manifest.json b/packages/build/tests/unit/validate_edge_manifest/unit_fixtures/empty_manifest/manifest.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/packages/build/tests/unit/validate_edge_manifest/unit_fixtures/empty_manifest/manifest.json @@ -0,0 +1 @@ +{} diff --git a/packages/build/tests/unit/validate_edge_manifest/unit_fixtures/invalid_manifest/manifest.json b/packages/build/tests/unit/validate_edge_manifest/unit_fixtures/invalid_manifest/manifest.json new file mode 100644 index 0000000000..90817d4296 --- /dev/null +++ b/packages/build/tests/unit/validate_edge_manifest/unit_fixtures/invalid_manifest/manifest.json @@ -0,0 +1 @@ +"json" diff --git a/packages/build/tests/unit/validate_edge_manifest/unit_fixtures/invalid_manifest_extra_property/manifest.json b/packages/build/tests/unit/validate_edge_manifest/unit_fixtures/invalid_manifest_extra_property/manifest.json deleted file mode 100644 index bde758c772..0000000000 --- a/packages/build/tests/unit/validate_edge_manifest/unit_fixtures/invalid_manifest_extra_property/manifest.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "bundles": [ - { - "asset": "f35baff44129a8f6be7db68590b2efd86ed4ba29000e2edbcaddc5d620d7d043.js", - "format": "js" - } - ], - "routes": [ - { - "function": "hello", - "pattern": "^/hello/?$", - "extra": "I'm extra!" - }, - { - "function": "geolocation", - "pattern": "^/geolocation/?$" - }, - { - "function": "json", - "pattern": "^/json/?$" - } - ], - "bundler_version": "1.6.0" -} diff --git a/packages/build/tests/unit/validate_edge_manifest/unit_fixtures/invalid_manifest_missing_property/manifest.json b/packages/build/tests/unit/validate_edge_manifest/unit_fixtures/invalid_manifest_missing_property/manifest.json deleted file mode 100644 index 2fbf3814d5..0000000000 --- a/packages/build/tests/unit/validate_edge_manifest/unit_fixtures/invalid_manifest_missing_property/manifest.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "bundles": [ - { - "asset": "f35baff44129a8f6be7db68590b2efd86ed4ba29000e2edbcaddc5d620d7d043.js" - } - ], - "routes": [ - { - "function": "hello", - "pattern": "^/hello/?$" - }, - { - "function": "geolocation", - "pattern": "^/geolocation/?$" - }, - { - "function": "json", - "pattern": "^/json/?$" - } - ], - "bundler_version": "1.6.0" -} diff --git a/packages/build/tests/unit/validate_edge_manifest/unit_fixtures/invalid_manifest_wrong_route_pattern/manifest.json b/packages/build/tests/unit/validate_edge_manifest/unit_fixtures/invalid_manifest_wrong_route_pattern/manifest.json deleted file mode 100644 index 6d8ba8ae1c..0000000000 --- a/packages/build/tests/unit/validate_edge_manifest/unit_fixtures/invalid_manifest_wrong_route_pattern/manifest.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "bundles": [ - { - "asset": "f35baff44129a8f6be7db68590b2efd86ed4ba29000e2edbcaddc5d620d7d043.js", - "format": "js" - } - ], - "routes": [ - { - "function": "hello", - "pattern": "^/hello/?$" - }, - { - "function": "geolocation", - "pattern": "^/geolocation/?$" - }, - { - "function": "json", - "pattern": "^/json/?" - } - ], - "bundler_version": "1.6.0" -}