@sanity/blueprints-parser 0.4.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.gitattributes ADDED
@@ -0,0 +1,2 @@
1
+ # Check out text files with LF on every platform
2
+ * text=auto eol=lf
@@ -11,15 +11,15 @@ concurrency:
11
11
  cancel-in-progress: true
12
12
 
13
13
  permissions:
14
- contents: read # for checkout
14
+ contents: read
15
15
 
16
16
  jobs:
17
17
  lint:
18
18
  name: Lint
19
19
  runs-on: ubuntu-latest
20
20
  steps:
21
- - uses: actions/checkout@v4
22
- - uses: actions/setup-node@v4
21
+ - uses: actions/checkout@v7
22
+ - uses: actions/setup-node@v7
23
23
  with:
24
24
  cache: npm
25
25
  node-version: lts/*
@@ -27,29 +27,33 @@ jobs:
27
27
  - run: npm run lint
28
28
 
29
29
  test:
30
- permissions:
31
- # Required to checkout the code
32
- contents: read
33
- # Required to put a comment into the pull-request
34
- pull-requests: write
35
30
  name: Test
36
31
  runs-on: ${{ matrix.os }}
37
32
  strategy:
38
33
  fail-fast: false
39
34
  matrix:
40
- # Run the testing suite on each major OS with the latest LTS release of Node.js
41
35
  os: [macos-latest, ubuntu-latest, windows-latest]
42
- node-version: [20, 22, 24]
36
+ node-version: [22, 24, 26]
43
37
  steps:
44
- - uses: actions/checkout@v4
45
- - uses: actions/setup-node@v4
38
+ - uses: actions/checkout@v7
39
+ - uses: actions/setup-node@v7
46
40
  with:
47
41
  cache: npm
48
42
  node-version: ${{ matrix.node-version }}
49
43
  - run: npm ci
50
44
  - run: cd test/integration; npm install
51
45
  - run: npm test
52
- - uses: vebr/jest-lcov-reporter@v0.2.1
46
+
47
+ coverage:
48
+ permissions:
49
+ contents: read
50
+ name: Coverage
51
+ runs-on: ubuntu-latest
52
+ steps:
53
+ - uses: actions/checkout@v7
54
+ - uses: actions/setup-node@v7
53
55
  with:
54
- github-token: ${{ secrets.GITHUB_TOKEN }}
55
- lcov-file: .tap/report/lcov.info
56
+ cache: npm
57
+ node-version: lts/*
58
+ - run: npm ci
59
+ - run: npm run test:unit:coverage
@@ -19,38 +19,35 @@ permissions:
19
19
  jobs:
20
20
  release-please:
21
21
  permissions:
22
- id-token: write # to enable use of OIDC for npm provenance
22
+ id-token: write # npm trusted publishing (OIDC)
23
23
  # permissions for pushing commits and opening PRs are handled by the `generate-token` step
24
24
  runs-on: ubuntu-latest
25
25
  steps:
26
- - uses: actions/create-github-app-token@v2
26
+ - uses: actions/create-github-app-token@v3
27
27
  id: app-token
28
28
  with:
29
29
  app-id: ${{ secrets.ECOSPARK_APP_ID }}
30
30
  private-key: ${{ secrets.ECOSPARK_APP_PRIVATE_KEY }}
31
31
  # This action will create a release PR when regular conventional commits are pushed to main, it'll also detect if a release PR is merged and npm publish should happen
32
- - uses: googleapis/release-please-action@v4
32
+ - uses: googleapis/release-please-action@v5
33
33
  id: release
34
34
  with:
35
35
  release-type: node
36
36
  token: ${{ steps.app-token.outputs.token }}
37
37
 
38
38
  # Publish to NPM on new releases
39
- - uses: actions/checkout@v4
39
+ - uses: actions/checkout@v7
40
40
  if: ${{ steps.release.outputs.release_created || github.event.inputs.publish == 'true' }}
41
- - uses: actions/setup-node@v4
41
+ - uses: actions/setup-node@v7
42
42
  if: ${{ steps.release.outputs.release_created || github.event.inputs.publish == 'true' }}
43
43
  with:
44
44
  cache: npm
45
45
  node-version: lts/*
46
- registry-url: "https://registry.npmjs.org"
47
46
  - run: npm ci --ignore-scripts
48
47
  if: ${{ steps.release.outputs.release_created || github.event.inputs.publish == 'true' }}
49
48
  #- run: npm audit signatures
50
49
  # if: ${{ steps.release.outputs.release_created || github.event.inputs.publish == 'true' }}
51
50
  # Release Please has already incremented versions and published tags, so we just
52
51
  # need to publish the new version to npm here
53
- - run: npm publish --provenance
52
+ - run: npm publish
54
53
  if: ${{ steps.release.outputs.release_created || github.event.inputs.publish == 'true' }}
55
- env:
56
- NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.5.1](https://github.com/sanity-io/blueprints-parser/compare/v0.5.0...v0.5.1) (2026-12-03)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **ci:** publish to npm with trusted publishing ([#21](https://github.com/sanity-io/blueprints-parser/issues/21)) ([3bc999c](https://github.com/sanity-io/blueprints-parser/commit/3bc999c4b3743b8d0fae557374f5b9139e04df0e))
9
+
10
+ ## [0.5.0](https://github.com/sanity-io/blueprints-parser/compare/v0.4.0...v0.5.0) (2026-08-13)
11
+
12
+
13
+ ### Features
14
+
15
+ * unresolvedRef gets source and target results ([#18](https://github.com/sanity-io/blueprints-parser/issues/18)) ([81c5bdd](https://github.com/sanity-io/blueprints-parser/commit/81c5bdd5f01bf1a2f54df7bb352bce4e917a99d9))
16
+
3
17
  ## [0.4.0](https://github.com/sanity-io/blueprints-parser/compare/v0.3.1...v0.4.0) (2026-02-11)
4
18
 
5
19
 
package/biome.jsonc CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
- "$schema": "https://biomejs.dev/schemas/2.3.14/schema.json",
2
+ "$schema": "https://biomejs.dev/schemas/2.5.8/schema.json",
3
3
  "vcs": {
4
- "enabled": false,
4
+ "enabled": true,
5
5
  "clientKind": "git",
6
- "useIgnoreFile": false
6
+ "useIgnoreFile": true
7
7
  },
8
8
  "files": {
9
9
  "ignoreUnknown": false,
@@ -24,10 +24,7 @@
24
24
  "linter": {
25
25
  "enabled": true,
26
26
  "rules": {
27
- "recommended": true,
28
- "complexity": {
29
- "noForEach": "off"
30
- }
27
+ "preset": "recommended"
31
28
  }
32
29
  },
33
30
  "javascript": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/blueprints-parser",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "A parser and validator for Sanity Blueprint documents.",
5
5
  "keywords": [
6
6
  "sanity",
@@ -18,22 +18,22 @@
18
18
  "main": "src/index.js",
19
19
  "types": "src/index.d.ts",
20
20
  "scripts": {
21
- "test": "npm run test:unit && npm run test:integration",
22
- "test:unit": "npx tap run --include=test/unit/**/* --coverage-report=text --coverage-report=lcov --no-browser",
21
+ "test": "npm run test:unit && npm run test:integration && npm run lint",
22
+ "test:unit": "node --test test/unit/index.test.js",
23
+ "test:unit:coverage": "node --test --experimental-test-coverage --test-coverage-exclude=\"test/**\" --test-coverage-lines=100 --test-coverage-branches=100 --test-coverage-functions=100 test/unit/index.test.js",
23
24
  "test:integration": "cd test/integration && npm test",
24
25
  "lint": "biome ci",
25
26
  "lint:write": "biome check --write"
26
27
  },
27
28
  "license": "MIT",
28
29
  "engines": {
29
- "node": ">=20.19 <22 || >=22.12"
30
+ "node": ">=22.12"
30
31
  },
31
32
  "author": "Sanity.io <hello@sanity.io>",
32
33
  "devDependencies": {
33
- "@biomejs/biome": "^2.3.14",
34
+ "@biomejs/biome": "^2.5.8",
34
35
  "@sanity/blueprints-jsonschemas": "^0.1.1",
35
- "ajv": "^8.17.1",
36
- "tap": "^21.5.1"
36
+ "ajv": "^8.20.0"
37
37
  },
38
38
  "publishConfig": {
39
39
  "access": "public"
package/src/constants.js CHANGED
@@ -13,4 +13,4 @@ const versionFormat = /^\d{4}-\d{2}-\d{2}$/ // YYYY-MM-DD
13
13
  const nameFormat = /^[a-zA-Z][a-zA-Z0-9-_]*(?<![-_])$/
14
14
  const typeFormat = /^[a-zA-Z]([a-zA-Z0-9-_]+\.?)*(?<![-_.])$/
15
15
 
16
- export {firstVersion, formatProperties, parameterTypes, versionFormat, nameFormat, typeFormat}
16
+ export {firstVersion, formatProperties, nameFormat, parameterTypes, typeFormat, versionFormat}
package/src/index.d.ts CHANGED
@@ -83,16 +83,34 @@ export type ValidationError = {
83
83
  message: string
84
84
  }
85
85
 
86
- /** A reference that could not be resolved during parsing */
87
- export type UnresolvedReference = {
86
+ /** Where a reference points, or where it was found */
87
+ export type ReferenceEndpoint = {
88
+ /** The top-level collection, e.g. `resources`, `values`, `outputs` */
89
+ collection: string
90
+ /** The name of the item within that collection */
91
+ name: string
92
+ /** The path within that item, empty when the reference is to the item itself */
93
+ path: string
94
+ }
95
+
96
+ /** The location and content of a reference */
97
+ export type ReferenceLocation = {
88
98
  /** The location where the reference was found */
89
99
  path: string
90
100
  /** The content of the reference (e.g. $.resources.project-1.id) */
91
101
  ref: string
92
102
  }
93
103
 
104
+ /** A reference that could not be resolved during parsing */
105
+ export type UnresolvedReference = ReferenceLocation & {
106
+ /** `ref` in split form: where the value will come from */
107
+ source: ReferenceEndpoint
108
+ /** `path` in split form: where the value belongs */
109
+ target: ReferenceEndpoint
110
+ }
111
+
94
112
  /** A reference found during parsing */
95
- export type Reference = UnresolvedReference & {
113
+ export type Reference = ReferenceLocation & {
96
114
  /** The object or array containing the reference */
97
115
  container: object | Array
98
116
  /** The key or index of the reference in the container */
package/src/index.js CHANGED
@@ -63,7 +63,7 @@ export default function blueprintParserValidator(input, options = {}) {
63
63
 
64
64
  return output
65
65
 
66
- /* c8 ignore next 4 */
66
+ /* node:coverage ignore next 4 */
67
67
  } catch (error) {
68
68
  console.log('Unknown Blueprint error', error)
69
69
  throw error
package/src/refs.js CHANGED
@@ -2,13 +2,22 @@ import is from './is.js'
2
2
  export default {find, resolve}
3
3
 
4
4
  /**
5
- * @param {import('.').Blueprint} validatedBlueprint
6
- * @param {import('.').ParserOptions} options
7
- * @returns {Array<import('.').Reference>}
5
+ * @typedef {import('.').Blueprint} Blueprint
6
+ * @typedef {import('.').ParserOptions} ParserOptions
7
+ * @typedef {import('.').Reference} Reference
8
+ * @typedef {import('.').UnresolvedReference} UnresolvedReference
9
+ * @typedef {import('.').ReferenceError} ReferenceError
10
+ * @typedef {import('.').ReferenceEndpoint} ReferenceEndpoint
11
+ */
12
+
13
+ /**
14
+ * @param {Blueprint} validatedBlueprint
15
+ * @param {ParserOptions} options
16
+ * @returns {Array<Reference>}
8
17
  */
9
18
  function find(validatedBlueprint, options) {
10
19
  const {debug} = options
11
- /** @type {Array<import('.').Reference>} */
20
+ /** @type {Array<Reference>} */
12
21
  const foundRefs = []
13
22
 
14
23
  /**
@@ -45,7 +54,7 @@ function find(validatedBlueprint, options) {
45
54
  }
46
55
  }
47
56
 
48
- /* c8 ignore next 4 */
57
+ /* node:coverage ignore next 4 */
49
58
  if (debug) {
50
59
  console.log(`[Debug] Found ${foundRefs.length} references:`, foundRefs.length ? foundRefs : '')
51
60
  }
@@ -54,21 +63,21 @@ function find(validatedBlueprint, options) {
54
63
  }
55
64
 
56
65
  /**
57
- * @param {import('.').Blueprint} blueprint
58
- * @param {Array<import('.').Reference>} foundRefs
59
- * @param {import('.').ParserOptions} options
66
+ * @param {Blueprint} blueprint
67
+ * @param {Array<Reference>} foundRefs
68
+ * @param {ParserOptions} options
60
69
  * @returns {{
61
- * resolvedBlueprint: import('.').Blueprint
62
- * unresolvedRefs: Array<import('.').UnresolvedReference> | undefined
63
- * refErrors: Array<import('.').ReferenceError>
70
+ * resolvedBlueprint: Blueprint
71
+ * unresolvedRefs: Array<UnresolvedReference> | undefined
72
+ * refErrors: Array<ReferenceError>
64
73
  * }}
65
74
  */
66
75
  function resolve(blueprint, foundRefs, options) {
67
76
  const {parameters = {}, invalidReferenceTypes} = options
68
77
 
69
- /** @type {Record<string, import('.').Reference>} */
78
+ /** @type {Record<string, Reference>} */
70
79
  const refs = {}
71
- /** @type {Array<import('.').UnresolvedReference>} */
80
+ /** @type {Array<UnresolvedReference>} */
72
81
  const unresolvedRefs = []
73
82
  const refErrors = []
74
83
  for (const foundRef of foundRefs) {
@@ -81,7 +90,7 @@ function resolve(blueprint, foundRefs, options) {
81
90
  if (refs[ref]) {
82
91
  if (refType === 'resources') {
83
92
  // all resources references must be resolved during deployment
84
- unresolvedRefs.push({path: foundRef.path, ref: foundRef.ref})
93
+ unresolvedRefs.push(unresolvedReference(foundRef))
85
94
  } else {
86
95
  foundRef.container[foundRef.property] = refs[ref].container[refs[ref].property]
87
96
  }
@@ -129,7 +138,7 @@ function resolve(blueprint, foundRefs, options) {
129
138
  })
130
139
  } else {
131
140
  // all resources references must be resolved during deployment
132
- unresolvedRefs.push({path: foundRef.path, ref: foundRef.ref})
141
+ unresolvedRefs.push(unresolvedReference(foundRef))
133
142
  }
134
143
  } else {
135
144
  refErrors.push({
@@ -151,3 +160,28 @@ function resolve(blueprint, foundRefs, options) {
151
160
  refErrors,
152
161
  }
153
162
  }
163
+
164
+ /**
165
+ * Create an unresolved reference from a found reference.
166
+ * @param {Reference} foundRef
167
+ * @returns {UnresolvedReference}
168
+ */
169
+ function unresolvedReference(foundRef) {
170
+ return {
171
+ path: foundRef.path,
172
+ ref: foundRef.ref,
173
+ source: endpoint(foundRef.ref.slice(2)),
174
+ target: endpoint(foundRef.path),
175
+ }
176
+ }
177
+
178
+ /**
179
+ * Create a reference endpoint from a location string.
180
+ * @param {string} location
181
+ * @returns {ReferenceEndpoint}
182
+ */
183
+ function endpoint(location) {
184
+ const [collection, name, ...path] = location.split('.')
185
+
186
+ return {collection, name: name ?? '', path: path.join('.')}
187
+ }
@@ -235,6 +235,8 @@ export default {
235
235
  {
236
236
  path: 'resources.another-function.config.disk',
237
237
  ref: '$.resources.a-function.config.disk',
238
+ source: {collection: 'resources', name: 'a-function', path: 'config.disk'},
239
+ target: {collection: 'resources', name: 'another-function', path: 'config.disk'},
238
240
  },
239
241
  ],
240
242
  error: {
@@ -242,4 +244,44 @@ export default {
242
244
  message: "Reference error '$.parameters.memory': 'memory' not found in passed parameters",
243
245
  },
244
246
  },
247
+
248
+ // collection-only reference has no name to resolve
249
+ repeatedCollectionOnlyReference: {
250
+ input: {
251
+ resources: [
252
+ {
253
+ name: 'a-function',
254
+ type: 'cloud-function',
255
+ config: {
256
+ first: '$.resources',
257
+ second: '$.resources',
258
+ },
259
+ },
260
+ ],
261
+ },
262
+ expected: {
263
+ resources: [
264
+ {
265
+ name: 'a-function',
266
+ type: 'cloud-function',
267
+ config: {
268
+ first: '$.resources',
269
+ second: '$.resources',
270
+ },
271
+ },
272
+ ],
273
+ },
274
+ unresolved: [
275
+ {
276
+ path: 'resources.a-function.config.second',
277
+ ref: '$.resources',
278
+ source: {collection: 'resources', name: '', path: ''},
279
+ target: {collection: 'resources', name: 'a-function', path: 'config.second'},
280
+ },
281
+ ],
282
+ error: {
283
+ type: 'missing_resource',
284
+ message: "Reference error '$.resources': 'undefined' not found in blueprint resources",
285
+ },
286
+ },
245
287
  }
@@ -141,6 +141,8 @@ export default {
141
141
  {
142
142
  path: 'resources.a-function.config.memory',
143
143
  ref: '$.resources.another-function.config.env.memory',
144
+ source: {collection: 'resources', name: 'another-function', path: 'config.env.memory'},
145
+ target: {collection: 'resources', name: 'a-function', path: 'config.memory'},
144
146
  },
145
147
  ],
146
148
  },
@@ -178,6 +180,8 @@ export default {
178
180
  {
179
181
  path: 'resources.a-function.projects[1]',
180
182
  ref: '$.resources.a-project.name',
183
+ source: {collection: 'resources', name: 'a-project', path: 'name'},
184
+ target: {collection: 'resources', name: 'a-function', path: 'projects[1]'},
181
185
  },
182
186
  ],
183
187
  },
@@ -228,6 +232,12 @@ export default {
228
232
  {
229
233
  path: 'resources.a-function.config.settings[0].projects[2]',
230
234
  ref: '$.resources.a-project.name',
235
+ source: {collection: 'resources', name: 'a-project', path: 'name'},
236
+ target: {
237
+ collection: 'resources',
238
+ name: 'a-function',
239
+ path: 'config.settings[0].projects[2]',
240
+ },
231
241
  },
232
242
  ],
233
243
  },
@@ -358,14 +368,20 @@ export default {
358
368
  {
359
369
  path: 'resources.another-function.config.memory',
360
370
  ref: '$.resources.a-function.config.memory',
371
+ source: {collection: 'resources', name: 'a-function', path: 'config.memory'},
372
+ target: {collection: 'resources', name: 'another-function', path: 'config.memory'},
361
373
  },
362
374
  {
363
375
  path: 'outputs.configured-memory-1.value',
364
376
  ref: '$.resources.another-function.config.memory',
377
+ source: {collection: 'resources', name: 'another-function', path: 'config.memory'},
378
+ target: {collection: 'outputs', name: 'configured-memory-1', path: 'value'},
365
379
  },
366
380
  {
367
381
  path: 'outputs.configured-memory-2.value',
368
382
  ref: '$.resources.another-function.config.memory',
383
+ source: {collection: 'resources', name: 'another-function', path: 'config.memory'},
384
+ target: {collection: 'outputs', name: 'configured-memory-2', path: 'value'},
369
385
  },
370
386
  ],
371
387
  },
@@ -403,6 +419,8 @@ export default {
403
419
  {
404
420
  path: 'resources.a-function.projects[2]',
405
421
  ref: '$.resources.a-project.name',
422
+ source: {collection: 'resources', name: 'a-project', path: 'name'},
423
+ target: {collection: 'resources', name: 'a-function', path: 'projects[2]'},
406
424
  },
407
425
  ],
408
426
  },
@@ -452,6 +470,51 @@ export default {
452
470
  {
453
471
  path: 'resources.a-function.config.settings[0].projects[0]',
454
472
  ref: '$.resources.a-project.name',
473
+ source: {collection: 'resources', name: 'a-project', path: 'name'},
474
+ target: {
475
+ collection: 'resources',
476
+ name: 'a-function',
477
+ path: 'config.settings[0].projects[0]',
478
+ },
479
+ },
480
+ ],
481
+ },
482
+
483
+ unresolvedRootReference: {
484
+ input: {
485
+ resources: [
486
+ {
487
+ name: 'a-project',
488
+ type: 'cloud-project',
489
+ },
490
+ {
491
+ name: 'a-function',
492
+ type: 'cloud-function',
493
+ project: '$.resources.a-project',
494
+ },
495
+ ],
496
+ },
497
+
498
+ expected: {
499
+ resources: [
500
+ {
501
+ name: 'a-project',
502
+ type: 'cloud-project',
503
+ },
504
+ {
505
+ name: 'a-function',
506
+ type: 'cloud-function',
507
+ project: '$.resources.a-project',
508
+ },
509
+ ],
510
+ },
511
+
512
+ unresolved: [
513
+ {
514
+ path: 'resources.a-function.project',
515
+ ref: '$.resources.a-project',
516
+ source: {collection: 'resources', name: 'a-project', path: ''},
517
+ target: {collection: 'resources', name: 'a-function', path: 'project'},
455
518
  },
456
519
  ],
457
520
  },
@@ -1,12 +1,12 @@
1
+ import {test} from 'node:test'
1
2
  import schemas from '@sanity/blueprints-jsonschemas'
2
3
  import Ajv from 'ajv/dist/2020.js'
3
- import tap from 'tap'
4
4
  import blueprintParserValidator from '../../src/index.js'
5
5
  import mocks from '../mocks/all.js'
6
6
 
7
7
  const ajv = new Ajv()
8
8
 
9
- tap.test('Basic input', async (t) => {
9
+ test('Basic input', async (t) => {
10
10
  t.plan(8)
11
11
  const input = {blueprintVersion: '2024-10-01'}
12
12
  const inputJSON = JSON.stringify(input)
@@ -15,39 +15,39 @@ tap.test('Basic input', async (t) => {
15
15
  let output
16
16
 
17
17
  output = blueprintParserValidator(input)
18
- t.same(
18
+ t.assert.deepStrictEqual(
19
19
  output.result === 'valid' && output.blueprint,
20
20
  input,
21
21
  'Parser / validator accepted raw JS input',
22
22
  )
23
- t.notOk('errors' in output, 'Parser / validator found no issues')
23
+ t.assert.ok(!('errors' in output), 'Parser / validator found no issues')
24
24
 
25
25
  output = blueprintParserValidator(inputJSON)
26
- t.same(
26
+ t.assert.deepStrictEqual(
27
27
  output.result === 'valid' && output.blueprint,
28
28
  input,
29
29
  'Parser / validator accepted JSON input',
30
30
  )
31
- t.notOk('errors' in output, 'Parser / validator found no issues')
31
+ t.assert.ok(!('errors' in output), 'Parser / validator found no issues')
32
32
 
33
33
  output = blueprintParserValidator(Buffer.from(inputJSON))
34
- t.same(
34
+ t.assert.deepStrictEqual(
35
35
  output.result === 'valid' && output.blueprint,
36
36
  input,
37
37
  'Parser / validator accepted JSON buffer',
38
38
  )
39
- t.notOk('errors' in output, 'Parser / validator found no issues')
39
+ t.assert.ok(!('errors' in output), 'Parser / validator found no issues')
40
40
 
41
41
  output = blueprintParserValidator(input, {parameters: {ok: 'hello'}})
42
- t.same(
42
+ t.assert.deepStrictEqual(
43
43
  output.result === 'valid' && output.blueprint,
44
44
  input,
45
45
  'Parser / validator accepted raw JS input and scalar params',
46
46
  )
47
- t.notOk('errors' in output, 'Parser / validator found no issues')
47
+ t.assert.ok(!('errors' in output), 'Parser / validator found no issues')
48
48
  })
49
49
 
50
- tap.test('Basic input: errors', async (t) => {
50
+ test('Basic input: errors', async (t) => {
51
51
  t.plan(10)
52
52
  const input = {blueprintVersion: 'nah'}
53
53
  const invalidInput = '{'
@@ -57,24 +57,27 @@ tap.test('Basic input: errors', async (t) => {
57
57
  let result
58
58
 
59
59
  result = blueprintParserValidator(invalidInput)
60
- t.ok(result.result === 'parse_errors')
61
- t.same(
60
+ t.assert.ok(result.result === 'parse_errors')
61
+ t.assert.strictEqual(
62
62
  result.result === 'parse_errors' && result.errors.length,
63
63
  1,
64
64
  'Parser / validator returned error on invalid JSON',
65
65
  )
66
66
 
67
67
  result = blueprintParserValidator(undefined)
68
- t.ok(result.result === 'parse_errors')
69
- t.same(
68
+ t.assert.ok(result.result === 'parse_errors')
69
+ t.assert.strictEqual(
70
70
  result.result === 'parse_errors' && result.errors.length,
71
71
  1,
72
72
  'Parser / validator returned error on invalid input (undefined)',
73
73
  )
74
74
 
75
75
  result = blueprintParserValidator(input)
76
- t.ok(result.result === 'validation_errors', 'Parser / validator accepted invalid raw JS input')
77
- t.same(
76
+ t.assert.ok(
77
+ result.result === 'validation_errors',
78
+ 'Parser / validator accepted invalid raw JS input',
79
+ )
80
+ t.assert.strictEqual(
78
81
  result.result === 'validation_errors' && result.errors.length,
79
82
  1,
80
83
  'Parser / validator returned a basic format error',
@@ -82,8 +85,8 @@ tap.test('Basic input: errors', async (t) => {
82
85
 
83
86
  // @ts-expect-error Passing invalid input to the parameters attribute
84
87
  result = blueprintParserValidator(validInput, {parameters: 'hi'})
85
- t.ok(result.result === 'validation_errors', 'Parser / validator accepted result input')
86
- t.same(
88
+ t.assert.ok(result.result === 'validation_errors', 'Parser / validator accepted result input')
89
+ t.assert.strictEqual(
87
90
  result.result === 'validation_errors' && result.errors.length,
88
91
  1,
89
92
  'Parser / validator returned a basic format error',
@@ -91,15 +94,15 @@ tap.test('Basic input: errors', async (t) => {
91
94
 
92
95
  // @ts-expect-error Passing invalid input to the parameters attribute
93
96
  result = blueprintParserValidator(validInput, {parameters: {ok: {}}})
94
- t.ok(result.result === 'validation_errors', 'Parser / validator accepted result input')
95
- t.same(
97
+ t.assert.ok(result.result === 'validation_errors', 'Parser / validator accepted result input')
98
+ t.assert.strictEqual(
96
99
  result.result === 'validation_errors' && result.errors.length,
97
100
  1,
98
101
  'Parser / validator returned a basic format error',
99
102
  )
100
103
  })
101
104
 
102
- tap.test('Reference resolution', async (t) => {
105
+ test('Reference resolution', async (t) => {
103
106
  const references = Object.entries(mocks.references)
104
107
  const referenceErrors = Object.entries(mocks.referenceErrors)
105
108
  const tests = references.length * 4 + referenceErrors.length * 5
@@ -111,14 +114,18 @@ tap.test('Reference resolution', async (t) => {
111
114
  debug: true,
112
115
  parameters,
113
116
  })
114
- t.same(output.result, 'valid', `${name}: returned expected result`)
117
+ t.assert.strictEqual(output.result, 'valid', `${name}: returned expected result`)
115
118
  if (output.result === 'valid') {
116
119
  const {blueprint, unresolvedRefs} = output
117
- t.same(blueprint, expected, `${name}: returned expected blueprint`)
118
- t.same(unresolvedRefs, unresolved, `${name}: returned expected unresolved references`)
119
- t.notOk('errors' in output, `${name}: found no issues`)
120
+ t.assert.deepStrictEqual(blueprint, expected, `${name}: returned expected blueprint`)
121
+ t.assert.deepStrictEqual(
122
+ unresolvedRefs,
123
+ unresolved,
124
+ `${name}: returned expected unresolved references`,
125
+ )
126
+ t.assert.ok(!('errors' in output), `${name}: found no issues`)
120
127
  } else {
121
- t.notOk(output.errors, `${name}: ${JSON.stringify(output.errors)}`)
128
+ t.assert.ok(!output.errors, `${name}: ${JSON.stringify(output.errors)}`)
122
129
  }
123
130
  }
124
131
 
@@ -129,25 +136,29 @@ tap.test('Reference resolution', async (t) => {
129
136
  parameters: {},
130
137
  ...options,
131
138
  })
132
- t.ok(output.result, 'result is true despite reference errors')
139
+ t.assert.ok(output.result, 'result is true despite reference errors')
133
140
  if (output.result === 'reference_errors') {
134
141
  const {blueprint, unresolvedRefs, errors} = output
135
- t.same(blueprint, expected, `${name}: returned expected blueprint`)
136
- t.same(unresolvedRefs, unresolved, `${name}: returned expected unresolved references`)
137
- t.ok(errors && errors.length > 0, `${name}: parser / validator found an error`)
142
+ t.assert.deepStrictEqual(blueprint, expected, `${name}: returned expected blueprint`)
143
+ t.assert.deepStrictEqual(
144
+ unresolvedRefs,
145
+ unresolved,
146
+ `${name}: returned expected unresolved references`,
147
+ )
148
+ t.assert.ok(errors && errors.length > 0, `${name}: parser / validator found an error`)
138
149
  if (error && errors && errors.length > 0) {
139
- t.ok(
150
+ t.assert.ok(
140
151
  errors.some((err) => err.type === error.type && err.message === error.message),
141
152
  JSON.stringify(errors),
142
153
  )
143
154
  } else {
144
- t.ok(true) // makes planning easier
155
+ t.assert.ok(true) // makes planning easier
145
156
  }
146
157
  }
147
158
  }
148
159
  })
149
160
 
150
- tap.test('2024-10-01', async (t) => {
161
+ test('2024-10-01', async (t) => {
151
162
  const jsonSchema20241001 = schemas['2024-10-01'].sanity.blueprint
152
163
 
153
164
  const basic = Object.entries(mocks.basic)
@@ -161,25 +172,28 @@ tap.test('2024-10-01', async (t) => {
161
172
  // Check the basic structure of a document
162
173
  for (const [name, input] of basic) {
163
174
  const output = blueprintParserValidator(input)
164
- t.same(output.result, 'valid', `${name}: expected valid result`)
165
- t.notOk('errors' in output, `${name}: parser / validator found no issues`)
175
+ t.assert.strictEqual(output.result, 'valid', `${name}: expected valid result`)
176
+ t.assert.ok(!('errors' in output), `${name}: parser / validator found no issues`)
166
177
  if (output.result !== 'valid') console.log(`${name} errors:`, output.errors)
167
178
 
168
179
  const result = ajv.validate(jsonSchema20241001, input)
169
- t.ok(result, `${name}: JSON Schema validator found no issues`)
170
- t.notOk(ajv.errors, `${name}: JSON Schema validator found no issues`)
180
+ t.assert.ok(result, `${name}: JSON Schema validator found no issues`)
181
+ t.assert.ok(!ajv.errors, `${name}: JSON Schema validator found no issues`)
171
182
  if (ajv.errors?.length) console.log(`${name} errors (AJV):`, ajv.errors)
172
183
  }
173
184
 
174
185
  // Basic validation errors
175
186
  for (const [name, input] of basicErrors) {
176
187
  const output = blueprintParserValidator(input)
177
- t.ok(output.result !== 'valid' && output.errors, `${name}: parser / validator found an error`)
188
+ t.assert.ok(
189
+ output.result !== 'valid' && output.errors,
190
+ `${name}: parser / validator found an error`,
191
+ )
178
192
 
179
193
  if (!input.metadata?.ignore) {
180
194
  const result = ajv.validate(jsonSchema20241001, input)
181
- t.notOk(result, `${name}: JSON Schema validator found an error`)
182
- t.ok(ajv.errors, `${name}: JSON Schema validator found an error`)
195
+ t.assert.ok(!result, `${name}: JSON Schema validator found an error`)
196
+ t.assert.ok(ajv.errors, `${name}: JSON Schema validator found an error`)
183
197
  }
184
198
  }
185
199
  })