1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | const assert = require('assert');
|
14 | const { AssertionError } = require('assert');
|
15 | const fs = require('fs-extra');
|
16 | const path = require('path');
|
17 | const cli = require('../lib/index');
|
18 |
|
19 | describe('Integration Test', () => {
|
20 | let oldargs = [];
|
21 | let oldexit;
|
22 |
|
23 | beforeEach(async () => {
|
24 | oldargs = process.argv;
|
25 | oldexit = process.exit;
|
26 | await fs.remove(path.resolve(__dirname, '..', 'tmp'));
|
27 | });
|
28 |
|
29 | afterEach(async () => {
|
30 | process.argv = oldargs;
|
31 | process.exit = oldexit;
|
32 | await fs.remove(path.resolve(__dirname, '..', 'tmp'));
|
33 | });
|
34 |
|
35 | it('CLI needs arguments to run', async (done) => {
|
36 | process.exit = () => {
|
37 | done();
|
38 | throw new Error('Intercepted Exit');
|
39 | };
|
40 |
|
41 | try {
|
42 | await cli();
|
43 | assert.fail('CLI called without args should exit');
|
44 | } catch (e) {
|
45 | if (e instanceof AssertionError) {
|
46 | throw e;
|
47 | }
|
48 | assert.equal(e.message, 'Intercepted Exit');
|
49 | }
|
50 | });
|
51 |
|
52 | ['arrays', 'cyclic'].forEach((dir) => it(`CLI processes ${dir} directory`, async () => {
|
53 | const res = await cli((`jsonschema2md -d test/fixtures/${dir} -o tmp -x tmp`).split(' '));
|
54 | console.log('done!', res);
|
55 | const readme = await fs.stat(path.resolve(__dirname, '..', 'tmp', 'README.md'));
|
56 | assert.ok(readme.isFile());
|
57 | }));
|
58 |
|
59 | ['json-logic-js/schemas'].forEach((dir) => it(`CLI processes ${dir} directory`, async () => {
|
60 | const res = await cli((`jsonschema2md -d node_modules/${dir} -o tmp -x tmp -e json`).split(' '));
|
61 | console.log('done!', res);
|
62 | const readme = await fs.stat(path.resolve(__dirname, '..', 'tmp', 'README.md'));
|
63 | assert.ok(readme.isFile());
|
64 | }));
|
65 | });
|