-
-
Notifications
You must be signed in to change notification settings - Fork 234
/
Copy pathfromTemplate.test.ts
183 lines (172 loc) · 5.03 KB
/
fromTemplate.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import * as fs from 'fs';
import * as path from 'path';
import { test } from '@oclif/test';
import rimraf from 'rimraf';
import { expect } from '@oclif/test';
const generalOptions = [
'generate:fromTemplate',
'./test/fixtures/specification.yml',
'@asyncapi/minimaltemplate',
];
const asyncapiv3 = './test/fixtures/specification-v3.yml';
function cleanup(filepath: string) {
rimraf.sync(filepath);
}
describe('template', () => {
after(() => {
cleanup('./test/docs');
});
test
.stdout()
.command([...generalOptions, '--output=./test/docs/1', '--force-write'])
.it('should generate minimal template', (ctx, done) => {
expect(ctx.stdout).to.contain(
'Check out your shiny new generated files at ./test/docs/1.\n\n'
);
cleanup('./test/docs/1');
done();
});
describe('should handle AsyncAPI v3 document correctly', () => {
test
.stderr()
.stdout()
.command([
'generate:fromTemplate',
asyncapiv3,
'@asyncapi/minimaltemplate'])
.it('give error on disabled template', (ctx, done) => {
expect(ctx.stderr).to.equal('Error: @asyncapi/minimaltemplate template does not support AsyncAPI v3 documents, please checkout some link\n');
expect(ctx.stdout).to.equal('');
done();
});
}).timeout(200000);
describe('git clash', () => {
const pathToOutput = './test/docs/2';
before(() => {
fs.mkdirSync(pathToOutput, { recursive: true });
// Write a random file to trigger that dir has unstaged changes.
fs.writeFileSync(path.join(pathToOutput, 'random.md'), '');
});
test
.stderr()
.command([...generalOptions, `--output=${pathToOutput}`])
.it(
'should throw error if output folder is in a git repository',
(ctx, done) => {
expect(ctx.stderr).to.contain(
`Error: "${pathToOutput}" is in a git repository with unstaged changes.`
);
cleanup(pathToOutput);
done();
}
);
});
describe('custom params', () => {
test
.stdout()
.command([
...generalOptions,
'-p=version=1.0.0 mode=development',
'--output=./test/docs/3',
'--force-write',
])
.it('should pass custom param in the template', (ctx, done) => {
expect(ctx.stdout).to.contain(
'Check out your shiny new generated files at ./test/docs/3.\n\n'
);
cleanup('./test/docs/3');
done();
});
});
describe('disable-hooks', () => {
test
.stdout()
.command([
...generalOptions,
'--output=./test/docs/4',
'--force-write',
'-d=generate:after',
])
.it('should not create asyncapi.yaml file', async (_, done) => {
const exits = fs.existsSync(path.resolve('./docs/asyncapi.yaml'));
expect(!!exits).to.equal(false);
cleanup('./test/docs/4');
done();
});
});
describe('debug', () => {
test
.stdout()
.command([
...generalOptions,
'--output=./test/docs/5',
'--force-write',
'--debug',
])
.it('should print debug logs', (ctx, done) => {
expect(ctx.stdout).to.contain(
`Template sources taken from ${path.resolve(
'./test/fixtures/minimaltemplate'
)}.`
);
cleanup('./test/docs/5');
done();
});
});
describe('no-overwrite', () => {
test
.stdout()
.command([
...generalOptions,
'--output=./test/docs/6',
'--force-write',
'--no-overwrite=./test/docs/asyncapi.md',
])
.it('should skip the filepath and generate normally', (ctx, done) => {
expect(ctx.stdout).to.contain(
'Check out your shiny new generated files at ./test/docs/6.\n\n'
);
cleanup('./test/docs/6');
done();
});
});
describe('should install template', () => {
test
.stdout()
.command([
'generate:fromTemplate',
'./test/fixtures/specification.yml',
'./test/fixtures/minimaltemplate',
'--install',
'--force-write',
'--output=./test/docs/7'
])
.it('should install template', (ctx, done) => {
expect(ctx.stdout).to.contain('Template installation started because you passed --install flag.');
cleanup('./test/docs/7');
done();
});
}).timeout(1000000);
describe('map-base-url', () => {
test
.stdout()
.command([
'generate:fromTemplate',
'./test/fixtures/dummyspec/apiwithref.json',
'@asyncapi/minimaltemplate',
'--output=./test/docs/8',
'--force-write',
'--map-base-url=https://schema.example.com/crm/:./test/fixtures/dummyspec',
])
.it(
'should resolve reference and generate from template',
(ctx, done) => {
expect(ctx.stdout).to.contain(
'Check out your shiny new generated files at ./test/docs/8.\n\n'
);
cleanup('./test/docs/8');
done();
}
);
});
});