Skip to content

Commit 3f61785

Browse files
authored
Fix: Update figures test fixtures test data imports
1 parent ddeeec5 commit 3f61785

File tree

2 files changed

+47
-27
lines changed

2 files changed

+47
-27
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,55 @@
1+
import { fileURLToPath } from 'node:url'
2+
import { readFileSync } from 'node:fs'
3+
import { dirname, resolve } from 'node:path'
4+
5+
const resolver = (path) => {
6+
const __dirname = dirname(fileURLToPath(import.meta.url))
7+
return resolve(__dirname, path)
8+
}
9+
10+
const readJson = (path) => {
11+
try {
12+
return JSON.parse(readFileSync(resolver(path)))
13+
} catch (error) {
14+
console.error(error)
15+
}
16+
}
17+
118
/**
2-
* Export all figure JSON
19+
* Export all figures fixture data
320
*/
421
export default {
522
annotationsCheckbox: {
623
dimensions: { height: 1455, width: 1200 },
7-
figure: require('./annotations-checkbox/figure.json'),
8-
manifest: require('./annotations-checkbox/manifest.json')
24+
figure: readJson('./annotations-checkbox/figure.json'),
25+
manifest: readJson('./annotations-checkbox/manifest.json')
926
},
1027
annotationsRadio: {
1128
dimensions: { height: 2868, width: 2082 },
12-
figure: require('./annotations-radio/figure.json'),
13-
manifest: require('./annotations-radio/manifest.json')
29+
figure: readJson('./annotations-radio/figure.json'),
30+
manifest: readJson('./annotations-radio/manifest.json')
1431
},
1532
sequence: {
1633
dimensions: { height: 2160, width: 1827 },
17-
figure: require('./sequence/figure.json'),
18-
files: require('./sequence/files.json'),
19-
manifest: require('./sequence/manifest.json')
34+
figure: readJson('./sequence/figure.json'),
35+
files: readJson('./sequence/files.json'),
36+
manifest: readJson('./sequence/manifest.json')
2037
},
2138
sequenceWithAnnotations: {
2239
dimensions: { height: 2048, width: 1536 },
23-
figure: require('./sequence-with-annotations/figure.json'),
24-
files: require('./sequence-with-annotations/files.json'),
25-
manifest: require('./sequence-with-annotations/manifest.json')
40+
figure: readJson('./sequence-with-annotations/figure.json'),
41+
files: readJson('./sequence-with-annotations/files.json'),
42+
manifest: readJson('./sequence-with-annotations/manifest.json')
2643
},
2744
zoomable: {
2845
dimensions: { height: 3221, width: 4096 },
29-
figure: require('./zoomable/figure.json'),
30-
manifest: require('./zoomable/manifest.json')
46+
figure: readJson('./zoomable/figure.json'),
47+
manifest: readJson('./zoomable/manifest.json')
3148
},
3249
zoomableSequence: {
3350
dimensions: { height: 2160, width: 1827 },
34-
figure: require('./zoomable-sequence/figure.json'),
35-
files: require('./zoomable-sequence/files.json'),
36-
manifest: require('./zoomable-sequence/manifest.json')
51+
figure: readJson('./zoomable-sequence/figure.json'),
52+
files: readJson('./zoomable-sequence/files.json'),
53+
manifest: readJson('./zoomable-sequence/manifest.json')
3754
}
3855
}

packages/11ty/_plugins/figures/test/index.js packages/11ty/_plugins/figures/test/figures.spec.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11
import { describe, test } from 'node:test'
2-
import { readFile } from 'node:fs/promises'
3-
import { resolve } from 'node:path'
2+
import { dirname, resolve } from 'node:path'
3+
import { fileURLToPath } from 'node:url'
4+
import { readFileSync } from 'node:fs'
45
import Ajv from 'ajv'
5-
import Figure from '../figure.js'
6-
import Manifest from '../iiif/manifest.js'
6+
import Figure from '../figure/index.js'
7+
import Manifest from '../iiif/manifest/index.js'
78
import assert from 'assert/strict'
89
import figureFixtures from './__fixtures__/figures/index.js'
9-
require('module-alias/register')
1010

11-
const loadJson = async (filepath) => {
11+
const resolver = (path) => {
12+
const __dirname = dirname(fileURLToPath(import.meta.url))
13+
return resolve(__dirname, path)
14+
}
15+
16+
const readJson = (path) => {
1217
try {
13-
// const fileUrl = new URL(filepath, import.meta.url)
14-
const json = await readFile(resolve(filepath))
15-
return JSON.parse(json)
18+
return JSON.parse(readFileSync(resolver(path)))
1619
} catch (error) {
1720
console.error(error)
1821
}
1922
}
2023

21-
const iiifConfig = await loadJson('./__fixtures__/iiif-config.json')
22-
const manifestSchema = await loadJson('../iiif/manifest/schema.json')
24+
const iiifConfig = readJson('./__fixtures__/iiif-config.json')
25+
const manifestSchema = readJson('../iiif/manifest/schema.json')
2326

2427
const createManifestFromFigureFixture = async (figureFixtureName) => {
2528
const {

0 commit comments

Comments
 (0)