-
Notifications
You must be signed in to change notification settings - Fork 221
/
Copy pathtest-schema-gen.js
37 lines (29 loc) · 1.07 KB
/
test-schema-gen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava.js';
import * as fsAmbient from 'fs/promises';
// XXX how to use devDependencies from tests??
// eslint-disable-next-line import/no-extraneous-dependencies
import { Value } from '@sinclair/typebox/value';
import { SwingSetConfig } from '@agoric/swingset-vat/src/typeGuards.js';
import { toTypeBox } from '../tools/schema-gen.js';
const makeTestContext = () => {
const asset = spec => fsAmbient.readFile(spec, 'utf8');
return {
asset,
writeFile: fsAmbient.writeFile,
};
};
test.before(async t => {
t.context = makeTestContext();
});
test('Generate JSON schema for editing swingset config files', async t => {
const { asset, writeFile } = t.context;
const schema = toTypeBox(SwingSetConfig);
t.truthy(schema);
// XXX KLUDGE: write schema during test
await writeFile('schema1.json', JSON.stringify(schema, null, 2));
const config = await asset('decentral-devnet-config.json').then(s =>
JSON.parse(s),
);
t.truthy(config);
t.deepEqual([...Value.Errors(schema, config)], []);
});