-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
index.test.ts
55 lines (51 loc) · 1.52 KB
/
index.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 { join } from 'path';
import { Project } from 'ts-morph';
import { getConfig } from '../src';
describe('getConfig()', () => {
it('should parse config from Node.js file', () => {
const project = new Project();
const sourcePath = join(__dirname, 'fixtures/node.js');
const config = getConfig(project, sourcePath);
expect(config).toMatchInlineSnapshot(`
{
"maxDuration": 60,
"memory": 1024,
"runtime": "nodejs",
}
`);
});
it('should parse config from Deno file', () => {
const project = new Project();
const sourcePath = join(__dirname, 'fixtures/deno.ts');
const config = getConfig(project, sourcePath, {
type: 'object',
properties: {
location: { type: 'string' },
},
} as const);
expect(config).toMatchInlineSnapshot(`
{
"location": "https://example.com/page",
"maxDuration": 60,
"runtime": "deno",
}
`);
});
it('should return `null` when no config was exported', () => {
const project = new Project();
const sourcePath = join(__dirname, 'fixtures/no-config.js');
const config = getConfig(project, sourcePath);
expect(config).toBeNull();
});
it('should throw an error upon schema validation failure', () => {
const project = new Project();
const sourcePath = join(__dirname, 'fixtures/invalid-schema.js');
let err;
try {
getConfig(project, sourcePath);
} catch (_err) {
err = _err;
}
expect(err.message).toEqual('Invalid data');
});
});