UNPKG

2.27 kBJavaScriptView Raw
1/*
2 * Copyright 2019 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12/* eslint-env mocha */
13const assert = require('assert');
14const { AssertionError } = require('assert');
15const fs = require('fs-extra');
16const path = require('path');
17const cli = require('../lib/index');
18
19describe('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});