forked from stdlib-js/stdlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a9a065
commit 4e751ac
Showing
7 changed files
with
233 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
lib/node_modules/@stdlib/_tools/markdown/to-vdom/docs/usage.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
|
||
Usage: markdown-to-vdom [options] [markdown] | ||
Usage: markdown-to-vdom [options] [<markdown>] | ||
|
||
Options: | ||
|
||
|
1 change: 1 addition & 0 deletions
1
lib/node_modules/@stdlib/_tools/markdown/to-vdom/test/fixtures/expected1.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"tagName":"DIV","properties":{},"children":[{"tagName":"H1","properties":{"id":"user-content-beep"},"children":[{"text":"Beep"}],"key":"h-2","namespace":null,"count":1,"hasWidgets":false,"hasThunks":false,"descendantHooks":false}],"key":"h-1","namespace":null,"count":2,"hasWidgets":false,"hasThunks":false,"descendantHooks":false} |
1 change: 1 addition & 0 deletions
1
lib/node_modules/@stdlib/_tools/markdown/to-vdom/test/fixtures/expected2.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"tagName":"DIV","properties":{},"children":[{"tagName":"H1","properties":{"id":"user-content-beep"},"children":[{"text":"Beep"}],"key":"h-2","namespace":null,"count":1,"hasWidgets":false,"hasThunks":false,"descendantHooks":false},{"text":"\n"},{"tagName":"BLOCKQUOTE","properties":{},"children":[{"text":"\n"},{"tagName":"P","properties":{},"children":[{"text":"Boop!"}],"key":"h-4","namespace":null,"count":1,"hasWidgets":false,"hasThunks":false,"descendantHooks":false},{"text":"\n"}],"key":"h-3","namespace":null,"count":4,"hasWidgets":false,"hasThunks":false,"descendantHooks":false}],"key":"h-1","namespace":null,"count":8,"hasWidgets":false,"hasThunks":false,"descendantHooks":false} |
14 changes: 14 additions & 0 deletions
14
lib/node_modules/@stdlib/_tools/markdown/to-vdom/test/fixtures/stdin_error.js.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
var resolve = require( 'path' ).resolve; | ||
var proxyquire = require( 'proxyquire' ); | ||
|
||
var fpath = resolve( __dirname, '..', 'bin', 'cli' ); | ||
|
||
process.stdin.isTTY = false; | ||
|
||
proxyquire( fpath, { | ||
'@stdlib/utils/read-stdin': stdin | ||
}); | ||
|
||
function stdin( clbk ) { | ||
clbk( new Error( 'beep' ) ); | ||
} |
214 changes: 214 additions & 0 deletions
214
lib/node_modules/@stdlib/_tools/markdown/to-vdom/test/test.cli.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,214 @@ | ||
'use strict'; | ||
|
||
// MODULES // | ||
|
||
var resolve = require( 'path' ).resolve; | ||
var exec = require( 'child_process' ).exec; | ||
var tape = require( 'tape' ); | ||
var IS_BROWSER = require( '@stdlib/assert/is-browser' ); | ||
var IS_WINDOWS = require( '@stdlib/assert/is-windows' ); | ||
var readFileSync = require( '@stdlib/fs/read-file' ).sync; | ||
var replace = require( '@stdlib/string/replace' ); | ||
|
||
|
||
// VARIABLES // | ||
|
||
var fpath = resolve( __dirname, '..', 'bin', 'cli' ); | ||
var opts = { | ||
'skip': IS_BROWSER || IS_WINDOWS | ||
}; | ||
|
||
|
||
// FIXTURES // | ||
|
||
var PKG_VERSION = require( './../package.json' ).version; | ||
|
||
|
||
// TESTS // | ||
|
||
tape( 'command-line interface', function test( t ) { | ||
t.ok( true, __filename ); | ||
t.end(); | ||
}); | ||
|
||
tape( 'when invoked with a `--help` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { | ||
var expected; | ||
var cmd; | ||
|
||
expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { | ||
'encoding': 'utf8' | ||
}); | ||
cmd = [ | ||
process.execPath, | ||
fpath, | ||
'--help' | ||
]; | ||
|
||
exec( cmd.join( ' ' ), done ); | ||
|
||
function done( error, stdout, stderr ) { | ||
if ( error ) { | ||
t.fail( error.message ); | ||
} else { | ||
t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); | ||
t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); | ||
} | ||
t.end(); | ||
} | ||
}); | ||
|
||
tape( 'when invoked with a `-h` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { | ||
var expected; | ||
var cmd; | ||
|
||
expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { | ||
'encoding': 'utf8' | ||
}); | ||
cmd = [ | ||
process.execPath, | ||
fpath, | ||
'-h' | ||
]; | ||
|
||
exec( cmd.join( ' ' ), done ); | ||
|
||
function done( error, stdout, stderr ) { | ||
if ( error ) { | ||
t.fail( error.message ); | ||
} else { | ||
t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); | ||
t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); | ||
} | ||
t.end(); | ||
} | ||
}); | ||
|
||
tape( 'when invoked with a `--version` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { | ||
var cmd = [ | ||
process.execPath, | ||
fpath, | ||
'--version' | ||
]; | ||
|
||
exec( cmd.join( ' ' ), done ); | ||
|
||
function done( error, stdout, stderr ) { | ||
if ( error ) { | ||
t.fail( error.message ); | ||
} else { | ||
t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); | ||
t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); | ||
} | ||
t.end(); | ||
} | ||
}); | ||
|
||
tape( 'when invoked with a `-V` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { | ||
var cmd = [ | ||
process.execPath, | ||
fpath, | ||
'-V' | ||
]; | ||
|
||
exec( cmd.join( ' ' ), done ); | ||
|
||
function done( error, stdout, stderr ) { | ||
if ( error ) { | ||
t.fail( error.message ); | ||
} else { | ||
t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); | ||
t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); | ||
} | ||
t.end(); | ||
} | ||
}); | ||
|
||
tape( 'the command-line interface prints a virtual DOM representation of a Markdown string', opts, function test( t ) { | ||
var expected; | ||
var file; | ||
var cmd; | ||
|
||
cmd = [ | ||
process.execPath, | ||
'-e', | ||
'"process.stdin.isTTY = true; process.argv[ 2 ] = \'# Beep\'; require( \''+fpath+'\' );"' | ||
]; | ||
|
||
file = resolve( __dirname, 'fixtures', 'expected1.txt' ); | ||
expected = readFileSync( file ); | ||
|
||
exec( cmd.join( ' ' ), done ); | ||
|
||
function done( error, stdout, stderr ) { | ||
if ( error ) { | ||
t.fail( error.message ); | ||
} else { | ||
t.strictEqual( stdout.toString(), expected.toString(), 'expected value' ); | ||
t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); | ||
} | ||
t.end(); | ||
} | ||
}); | ||
|
||
tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { | ||
var expected; | ||
var file; | ||
var cmd; | ||
|
||
cmd = [ | ||
'echo \'# Beep\n\n> Boop!\'', | ||
'|', | ||
process.execPath, | ||
fpath | ||
]; | ||
|
||
file = resolve( __dirname, 'fixtures', 'expected2.txt' ); | ||
expected = readFileSync( file ); | ||
|
||
exec( cmd.join( ' ' ), done ); | ||
|
||
function done( error, stdout, stderr ) { | ||
if ( error ) { | ||
t.fail( error.message ); | ||
} else { | ||
t.strictEqual( stdout.toString(), expected.toString(), 'expected value' ); | ||
t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); | ||
} | ||
t.end(); | ||
} | ||
}); | ||
|
||
tape( 'when used as a standard stream, if an error is encountered when reading from `stdin`, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { | ||
var script; | ||
var opts; | ||
var cmd; | ||
|
||
script = readFileSync( resolve( __dirname, 'fixtures', 'stdin_error.js.txt' ), { | ||
'encoding': 'utf8' | ||
}); | ||
|
||
// Replace single quotes with double quotes: | ||
script = replace( script, '\'', '"' ); | ||
|
||
cmd = [ | ||
process.execPath, | ||
'-e', | ||
'\''+script+'\'' | ||
]; | ||
|
||
opts = { | ||
'cwd': __dirname | ||
}; | ||
|
||
exec( cmd.join( ' ' ), opts, done ); | ||
|
||
function done( error, stdout, stderr ) { | ||
if ( error ) { | ||
t.pass( error.message ); | ||
t.strictEqual( error.code, 1, 'expected exit code' ); | ||
} | ||
t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); | ||
t.strictEqual( stderr.toString(), 'Error: beep\n', 'expected value' ); | ||
t.end(); | ||
} | ||
}); |