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 | 1× 1× 1× 1× 1× 11× 11× 9× 9× 5× 5× 5× 4× 2× 2× 2× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× | #!/usr/bin/env node /*jshint node: true */ 'use strict'; var path = require('path'); var exec = require('child_process').exec; var app = path.resolve('bin/cli.js'); var should = require('should'); var checkCmdExecution = function(argsStr, checkSuccess, expectedOut, done) { exec(app + ' ' + argsStr, function(error, stdout, stderr) { if (checkSuccess) { Eif (error === null) { if (expectedOut) { var outRegExp = new RegExp(expectedOut); Eif (stdout.match(outRegExp)) { done(); } } else { done(); } } } else { Eif (error !== null) { error.code.should.eql(1); if (expectedOut) { var outRegExp = new RegExp(expectedOut); Eif (stderr.match(outRegExp)) { done(); } } else { done(); } } } }); }; describe('Test scmt', function() { it('Shows the general help', function(done) { checkCmdExecution('-h', true, '.*Usage: scmt.*', done); }) it('Shows the json2schema help', function(done) { checkCmdExecution('json2schema -h', true, '.*Usage: json2schema.*', done); }) it('Shows the json2yaml help', function(done) { checkCmdExecution('json2yaml -h', true, '.*Usage: json2yaml.*', done); }) it('Shows the yaml2json help', function(done) { checkCmdExecution('yaml2json -h', true, '.*Usage: yaml2json.*', done); }) it('Shows the validate help', function(done) { checkCmdExecution('validate -h', true, '.*Usage: validate.*', done); }) it('Detects unknown option', function(done) { checkCmdExecution(' -x', false, '.*error: unknown option.*', done); }) it('Converts json2schema', function(done) { checkCmdExecution('json2schema ' + path.resolve('test/array.json'), true, null, done); }) it('Converts json2yaml', function(done) { checkCmdExecution('json2yaml ' + path.resolve('test/array.json'), true, null, done); }) it('Converts yaml2json', function(done) { checkCmdExecution('yaml2json ' + path.resolve('test/array.json'), true, null, done); }) it('Validate json with schema', function(done) { checkCmdExecution('validate ' + path.resolve('test/array.json') + ' ' + path.resolve('test/array-schema.json'), true, null, done); }) it('Validate json with wrong schema name', function(done) { checkCmdExecution('validate ' + path.resolve('test/array.json') + ' ' + path.resolve('wrong-schema-name'), false, null, done); }) }); |