-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.ts
55 lines (53 loc) · 1.6 KB
/
test.ts
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import type { ViewBlock } from './lib/types'
import { error } from './lib/utils'
import {
validateDatabaseConfigIntegrity,
validateDatabaseConfigSchema
} from './lib/database-config-validation/'
import { Experience } from './lib/'
import * as packages from './packages'
import camelCase from 'lodash/camelCase'
function test([
name,
{
loaderOptions: { files, disabled, databaseConfig },
viewerOptions: { viewBlocks, url }
}
]: [name: string, experience: Experience]): void {
if (!disabled && !url && !viewBlocks.length) {
error(`[${name}] viewBlocks should not be empty`)
}
if (files && !('$DYNAMIC_FILES' in files)) {
// validate file ids
viewBlocks.forEach(({ id, files: viewFiles }: Partial<ViewBlock>) => {
if (viewFiles) {
const fileId = viewFiles.find((f: string) => !(f in files))
if (fileId) {
error(
`[${name}] ViewBlock ${id} has an unconfigured file id ${fileId}`
)
}
}
})
if (databaseConfig) {
validateDatabaseConfigSchema(name, databaseConfig)
validateDatabaseConfigIntegrity(name, databaseConfig, files)
}
}
}
if (process.argv.length > 2) {
// test one or more packages
const names: string[] = process.argv.slice(2)
names.map(camelCase).forEach(name => {
// we expect the name to be camelCased
const module = (packages as { [key: string]: Experience })[name]
if (module) {
test([name, module])
} else {
throw new Error(`The name "${name}" does not match any package.`)
}
})
} else {
// test all packages
Object.entries(packages).forEach(test)
}