forked from asyncapi/bundler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.spec.ts
73 lines (63 loc) · 1.91 KB
/
index.spec.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { describe, expect, test, jest } from '@jest/globals';
import bundle from '../../src';
import fs from 'fs';
import path from 'path';
import type { ReferenceObject } from '../../src/spec-types';
describe('bundler should ', () => {
test('should return bundled doc', async () => {
const files = ['./tests/camera.yml', './tests/audio.yml'];
const response = await bundle(
files.map(file =>
fs.readFileSync(path.resolve(process.cwd(), file), 'utf-8')
),
{
base: fs.readFileSync(
path.resolve(process.cwd(), './tests/base.yml'),
'utf-8'
),
validate: false,
}
);
expect(response).toBeDefined();
});
test('should bundle references into components', async () => {
const files = ['./tests/asyncapi.yaml'];
const doc = await bundle(
files.map(file =>
fs.readFileSync(path.resolve(process.cwd(), file), 'utf-8')
),
{
referenceIntoComponents: true,
}
);
const asyncapiObject = doc.json();
const message = asyncapiObject.channels?.['user/signedup']?.subscribe?.message as ReferenceObject;
expect(message.$ref).toMatch('#/components/messages/UserSignedUp');
});
test('should not throw if value of `$ref` is not a string', async () => {
const files = ['./tests/wrong-ref-not-string.yaml'];
expect(
await bundle(
files.map(file =>
fs.readFileSync(path.resolve(process.cwd(), file), 'utf-8')
),
{
referenceIntoComponents: true,
}
)
).resolves;
});
test('should not throw if value of `$ref` is absent', async () => {
const files = ['./tests/wrong-ref-absent.yaml'];
expect(
await bundle(
files.map(file =>
fs.readFileSync(path.resolve(process.cwd(), file), 'utf-8')
),
{
referenceIntoComponents: true,
}
)
).resolves;
});
});