Skip to content

Commit 6387677

Browse files
committed
test: Ensure missing JSON contents do not break filename validation tests
1 parent 69b2312 commit 6387677

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/validators/validateFiles.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { assert, assertEquals } from '@std/assert'
22
import { filenameIdentify } from './filenameIdentify.ts'
33
import { filenameValidate } from './filenameValidate.ts'
44
import { BIDSContext, BIDSContextDataset } from '../schema/context.ts'
5+
import { makeBIDSContext } from '../schema/context.test.ts'
56
import { loadSchema } from '../setup/loadSchema.ts'
67
import type { GenericSchema, Schema } from '../types/schema.ts'
78
import type { DatasetIssues } from '../issues/datasetIssues.ts'
@@ -11,12 +12,12 @@ import { StringOpener } from '../files/openers.test.ts'
1112

1213
const schema = await loadSchema()
1314

14-
function makeContext(path: string, contents: string = ''): BIDSContext {
15+
async function makeContext(path: string, contents: string = ''): Promise<BIDSContext> {
1516
const tree = pathsToTree([path])
1617
const dataset = new BIDSContextDataset({ schema, tree })
1718
const file = tree.get(path) as BIDSFile
1819
file.opener = new StringOpener(contents)
19-
return new BIDSContext(file, dataset)
20+
return makeBIDSContext(file, dataset)
2021
}
2122

2223
Deno.test('test valid paths', async (t) => {
@@ -57,7 +58,7 @@ Deno.test('test valid paths', async (t) => {
5758
]
5859
for (const filename of validFiles) {
5960
await t.step(filename, async () => {
60-
const context = makeContext(filename)
61+
const context = await makeContext(filename, '{"valid": "json"}')
6162
await filenameIdentify(schema, context)
6263
await filenameValidate(schema as unknown as GenericSchema, context)
6364
assertEquals(
@@ -116,7 +117,7 @@ Deno.test('test invalid paths', async (t) => {
116117
]
117118
for (const filename of invalidFiles) {
118119
await t.step(filename, async () => {
119-
const context = makeContext(filename)
120+
const context = await makeContext(filename)
120121
await filenameIdentify(schema, context)
121122
await filenameValidate(schema as unknown as GenericSchema, context)
122123
assert(

0 commit comments

Comments
 (0)