1
- "use strict" ;
2
- //@ts -check
1
+ // @ts -check
2
+ 'use strict'
3
+ /** @typedef {import("tap") } Tap */
3
4
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' )
8
8
9
- require ( " npmlog" ) . level = " warn" ;
9
+ require ( ' npmlog' ) . level = ' warn'
10
10
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' ) ]
15
28
const options = {
16
- windowsHide : true ,
17
- } ;
29
+ windowsHide : true
30
+ }
18
31
19
32
/**
20
33
Getting output from find-python-script.py,
21
34
compare it to path provided to terminal.
22
35
If equale - test pass
23
36
24
- runs for all tests
25
-
26
- //!this must contain t: Test and exec: {path: string, name: string} fields
37
+ runs for all checks
27
38
28
39
@private
29
40
@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}}
32
44
*/
33
- function check ( err , stdout , stderr ) {
34
- let { t, exec } = this ;
45
+ function check ( err , stdout , stderr ) {
46
+ const { t, exec } = this
35
47
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
+ )
37
53
} else {
54
+ // @ts -ignore
38
55
if ( err . code === 9009 ) {
39
56
t . skip ( `skipped: ${ exec . name } file not found` )
40
57
} else {
@@ -43,24 +60,24 @@ function check(err, stdout, stderr) {
43
60
}
44
61
}
45
62
46
- test ( " find-python-script" , ( t ) => {
47
- t . plan ( tests . length ) ;
63
+ test ( ' find-python-script' , ( t ) => {
64
+ t . plan ( checks . length )
48
65
49
66
// context for check functions
50
- let ctx = {
67
+ const ctx = {
51
68
t : t ,
52
- exec : { } ,
53
- } ;
69
+ exec : { }
70
+ }
54
71
55
- for ( let exec of tests ) {
56
- //checking if env var exist
72
+ for ( const exec of checks ) {
73
+ // checking if env var exist
57
74
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 )
62
79
} else {
63
80
t . skip ( `skipped: ${ exec . name } doesn't exist or unavailable` )
64
81
}
65
82
}
66
- } ) ;
83
+ } )
0 commit comments