11/* globals describe, it */
22
3- // Steps for using a plugin:
4- // First, you must load in ShellJS:
5- var shell = require ( 'shelljs' ) ;
6- // After that, you can load the plugin:
7- var pluginOpen = require ( '..' ) ;
83/*
4+ * Using ShellJS Plugins:
5+ *
6+ * To learn how to use a ShellJS plugin, look for the comments following the
7+ * slash-star/star-slash syntax.
8+ */
9+
10+ /*
11+ * Load all your plugins first:
912 * You can load a plugin with either of the following syntaxes:
1013 * `require('shelljs-plugin-open');` or
1114 * `var pluginOpen = require('shelljs-plugin-open');`
12- */
15+ *
16+ * Here, we've opted to save it in a variable, allowing us the option to use the
17+ * bare function in addition to shell.open() (which includes helpful ShellJS
18+ * features)
19+ */
20+ var pluginOpen = require ( '..' ) ;
21+ // If we were using additional plugins, we could load them here
22+
23+ /*
24+ * After that, you must load in ShellJS itself, either locally (recommended) or
25+ * globally (which still supported). For the purposes of testing this plugin,
26+ * we're actually testing both ways of importing ShellJS (but you would never
27+ * want to use ShellJS like this normally):
28+ */
29+ var shell = require ( 'shelljs' ) ; // recommended
30+ require ( 'shelljs/global' ) ; // not recommended
1331
14- // Now, require whichever other modules you want to require:
32+ /*
33+ * Now, require whichever other modules you want to require:
34+ */
1535require ( 'should' ) ;
36+ var assert = require ( 'assert' ) ;
1637
1738// override console.error() to cover up common.error() calls
1839console . error = function ( ) { } ;
1940
2041describe ( 'plugin-open' , function ( ) {
2142 it ( 'gets added to the shelljs instance' , function ( ) {
43+ /*
44+ * Plugins automatically add new commands to the ShellJS instance, such as
45+ * shell.open()
46+ */
2247 ( typeof shell . open ) . should . equal ( 'function' ) ;
2348 } ) ;
2449
50+ it ( 'gets added to the global namespace for shelljs/global' , function ( ) {
51+ /*
52+ * Plugins are also compatible with using require('shelljs/global');
53+ */
54+ ( typeof global . open ) . should . equal ( 'function' ) ;
55+ global . open . should . equal ( shell . open ) ;
56+ } ) ;
57+
58+ it ( 'does not override other commands or methods' , function ( ) {
59+ /*
60+ * Plugins shouldn't interfere with existing commands
61+ */
62+ ( typeof shell . cp ) . should . equal ( 'function' ) ;
63+ ( typeof shell . mv ) . should . equal ( 'function' ) ;
64+ shell . ls ( ) . should . have . property ( 'toEnd' ) ;
65+ shell . ls ( ) . should . have . property ( 'grep' ) ;
66+ shell . ls ( ) . should . have . property ( 'sed' ) ;
67+ } ) ;
68+
2569 it ( 'exports the plugin implementation' , function ( ) {
70+ /*
71+ * A plugin author can also export the implementation of their commands
72+ */
2673 ( typeof pluginOpen ) . should . equal ( 'object' ) ;
2774 pluginOpen . should . have . property ( 'open' ) ;
2875 ( typeof pluginOpen . open ) . should . equal ( 'function' ) ;
@@ -38,7 +85,7 @@ describe('plugin-open', function () {
3885 it ( 'opens URLs' , function ( ) {
3986 var ret = shell . open ( 'https://www.google.com' ) ;
4087 ret . code . should . equal ( 0 ) ;
41- ret . stderr . should . equal ( '' ) ;
88+ assert . ok ( ! ret . stderr ) ;
4289 } ) ;
4390
4491 it ( 'opens files asynchronously' , function ( ) {
@@ -47,13 +94,17 @@ describe('plugin-open', function () {
4794 // if this gets to this point, it must have been asynchronous
4895 ret . code . should . equal ( 0 ) ;
4996 ret . stdout . should . equal ( '' ) ;
50- ret . stderr . should . equal ( '' ) ;
97+ assert . ok ( ! ret . stderr ) ;
5198 } ) ;
5299
53100 it ( 'handles glob characters' , function ( ) {
101+ /*
102+ * Plugins can easily take advantage of ShellJS's built-in glob expansion.
103+ * This is indicated by the globStart option
104+ */
54105 var ret = shell . open ( 'te?t/*st.js' ) ;
55106 ret . code . should . equal ( 0 ) ;
56107 ret . stdout . should . equal ( '' ) ;
57- ret . stderr . should . equal ( '' ) ;
108+ assert . ok ( ! ret . stderr ) ;
58109 } ) ;
59110} ) ;
0 commit comments