diff --git a/bids-validator/src/files/browser.test.ts b/bids-validator/src/files/browser.test.ts index 55478cf12..4e1529ee6 100644 --- a/bids-validator/src/files/browser.test.ts +++ b/bids-validator/src/files/browser.test.ts @@ -1,6 +1,6 @@ import { FileIgnoreRules } from './ignore.ts' import { FileTree } from '../types/filetree.ts' -import { assertEquals } from '../deps/asserts.ts' +import { assertEquals, assertObjectMatch } from '../deps/asserts.ts' import { BIDSFileBrowser, fileListToTree } from './browser.ts' class TestFile extends File { @@ -69,3 +69,21 @@ Deno.test('Browser implementation of FileTree', async (t) => { assertEquals(tree, expectedTree) }) }) + +Deno.test("Spread copies of BIDSFileBrowser contain name and path properties", async () => { + const ignore = new FileIgnoreRules([]) + const files = [ + new TestFile( + ['{}'], + 'dataset_description.json', + 'ds/dataset_description.json', + ), + new TestFile(['flat test dataset'], 'README.md', 'ds/README.md'), + ] + const tree = await fileListToTree(files) + const expectedTree = new FileTree('', '/', undefined) + expectedTree.files = files.map((f) => new BIDSFileBrowser(f, ignore)) + assertEquals(tree, expectedTree) + const spreadFile = {...expectedTree.files[0], evidence: "test evidence"} + assertObjectMatch(spreadFile, {name: "dataset_description.json", path: "/dataset_description.json", evidence: "test evidence"}) +}) \ No newline at end of file diff --git a/bids-validator/src/files/browser.ts b/bids-validator/src/files/browser.ts index 674eb341a..5c21698ae 100644 --- a/bids-validator/src/files/browser.ts +++ b/bids-validator/src/files/browser.ts @@ -9,21 +9,17 @@ import { parse, join, SEPARATOR } from '../deps/path.ts' export class BIDSFileBrowser implements BIDSFile { #ignore: FileIgnoreRules #file: File + name: string + path: string constructor(file: File, ignore: FileIgnoreRules) { this.#file = file this.#ignore = ignore - } - - get name(): string { - return this.#file.name - } - - get path(): string { - // @ts-expect-error webkitRelativePath is defined in the browser + this.name = file.name + // @ts-expect-error webkitRelativePath does exist in the browser const relativePath = this.#file.webkitRelativePath const prefixLength = relativePath.indexOf('/') - return relativePath.substring(prefixLength) + this.path = relativePath.substring(prefixLength) } get size(): number { diff --git a/bids-validator/src/schema/context.ts b/bids-validator/src/schema/context.ts index 2d93a93db..ea36dafa2 100644 --- a/bids-validator/src/schema/context.ts +++ b/bids-validator/src/schema/context.ts @@ -175,6 +175,7 @@ export class BIDSContext implements Context { if (this.extension !== '.tsv') { return } + this.columns = await this.file .text() .then((text) => parseTSV(text))