1- "use strict" ;
2- //@ts -check
1+ // @ts -check
2+ 'use strict'
3+ /** @typedef {import("tap") } Tap */
34
4- const test = require ( "tap" ) . test ;
5- const execFile = require ( "child_process" ) . execFile ;
6- const path = require ( "path" ) ;
7- const { stderr } = require ( "process" ) ;
5+ const test = require ( 'tap' ) . test
6+ const execFile = require ( 'child_process' ) . execFile
7+ const path = require ( 'path' )
88
9- require ( " npmlog" ) . level = " warn" ;
9+ require ( ' npmlog' ) . level = ' warn'
1010
11- //! tests: {path: string, name: string}[]
12- //*can use name as short descriptions
13- const tests = [ { path : process . env . PYTHON , name : "env var PYTHON" } , { path : process . env [ "python2" ] , name : "env var python2" } , { path : "python3" , name : "env var python3" } ] ;
14- const args = [ path . resolve ( "./lib/find-python-script.py" ) ] ;
11+ //* can use name as short descriptions
12+
13+ /**
14+ * @typedef Check
15+ * @property {string } path - path to execurtable or command
16+ * @property {string } name - very little description
17+ */
18+
19+ /**
20+ * @type {Check[] }
21+ */
22+ const checks = [
23+ { path : process . env . PYTHON , name : 'env var PYTHON' } ,
24+ { path : process . env . python2 , name : 'env var python2' } ,
25+ { path : 'python3' , name : 'env var python3' }
26+ ]
27+ const args = [ path . resolve ( './lib/find-python-script.py' ) ]
1528const options = {
16- windowsHide : true ,
17- } ;
29+ windowsHide : true
30+ }
1831
1932/**
2033 Getting output from find-python-script.py,
2134 compare it to path provided to terminal.
2235 If equale - test pass
2336
24- runs for all tests
25-
26- //!this must contain t: Test and exec: {path: string, name: string} fields
37+ runs for all checks
2738
2839 @private
2940 @argument {Error} err - exec error
30- @argument {Buffer} stdout - stdout buffer of child process
31- @argument {stderr} stderr
41+ @argument {string} stdout - stdout buffer of child process
42+ @argument {string} stderr
43+ @this {{t, exec: Check}}
3244 */
33- function check ( err , stdout , stderr ) {
34- let { t, exec } = this ;
45+ function check ( err , stdout , stderr ) {
46+ const { t, exec } = this
3547 if ( ! err && ! stderr ) {
36- t . strictEqual ( stdout . trim ( ) , exec . path , `${ exec . name } : check path ${ exec . path } equals ${ stdout . trim ( ) } ` ) ;
48+ t . strictEqual (
49+ stdout . trim ( ) ,
50+ exec . path ,
51+ `${ exec . name } : check path ${ exec . path } equals ${ stdout . trim ( ) } `
52+ )
3753 } else {
54+ // @ts -ignore
3855 if ( err . code === 9009 ) {
3956 t . skip ( `skipped: ${ exec . name } file not found` )
4057 } else {
@@ -43,24 +60,24 @@ function check(err, stdout, stderr) {
4360 }
4461}
4562
46- test ( " find-python-script" , ( t ) => {
47- t . plan ( tests . length ) ;
63+ test ( ' find-python-script' , ( t ) => {
64+ t . plan ( checks . length )
4865
4966 // context for check functions
50- let ctx = {
67+ const ctx = {
5168 t : t ,
52- exec : { } ,
53- } ;
69+ exec : { }
70+ }
5471
55- for ( let exec of tests ) {
56- //checking if env var exist
72+ for ( const exec of checks ) {
73+ // checking if env var exist
5774 if ( ! ( exec . path === undefined || exec . path === null ) ) {
58- ctx . exec = exec ;
59- //passing ctx as coppied object to make properties immutable from here
60- let boundedCheck = check . bind ( Object . assign ( { } , ctx ) )
61- execFile ( exec . path , args , options , boundedCheck ) ;
75+ ctx . exec = exec
76+ // passing ctx as coppied object to make properties immutable from here
77+ const boundedCheck = check . bind ( Object . assign ( { } , ctx ) )
78+ execFile ( exec . path , args , options , boundedCheck )
6279 } else {
6380 t . skip ( `skipped: ${ exec . name } doesn't exist or unavailable` )
6481 }
6582 }
66- } ) ;
83+ } )
0 commit comments