@@ -5,6 +5,7 @@ const path = require('path');
55const expect = require ( 'expect.js' ) ;
66const http = require ( 'http' ) ;
77const express = require ( 'express' ) ;
8+ const child_process = require ( 'child_process' ) ;
89const markdownLinkCheck = require ( '../' ) ;
910const dirname = process . platform === 'win32' ? __dirname . replace ( / \\ / g, '/' ) : __dirname ;
1011
@@ -442,4 +443,21 @@ describe('markdown-link-check', function () {
442443 done ( ) ;
443444 } ) ;
444445 } ) ;
446+
447+ describe ( "CLI" , function ( ) {
448+ const cliPath = path . join ( __dirname , '..' , 'markdown-link-check' ) ;
449+
450+ it ( "exits with 0 if all links are ok" , function ( ) {
451+ const { status, output } = child_process . spawnSync ( process . execPath , [ cliPath , path . join ( __dirname , 'alive-links-only.md' ) ] ) ;
452+ expect ( status ) . to . be ( 0 ) ;
453+ expect ( output . toString ( ) ) . to . contain ( 'links checked.' ) ;
454+ } ) ;
455+
456+ it ( "exits with 1 if any link is broken" , function ( ) {
457+ this . timeout ( 60000 )
458+ const { status, output } = child_process . spawnSync ( process . execPath , [ cliPath , [ path . join ( __dirname , 'section-links.md' ) ] ] ) ;
459+ expect ( status ) . to . be ( 1 ) ;
460+ expect ( output . toString ( ) ) . to . contain ( 'dead links found!' ) ;
461+ } ) ;
462+ } ) ;
445463} ) ;
0 commit comments