@@ -35,6 +35,12 @@ function uncommentPythonCodeBlocks(content) {
3535 . join ( '\n' ) ;
3636}
3737
38+ // https://en.wikipedia.org/wiki/Shebang_(Unix)
39+ function parseShebang ( contents ) {
40+ const shebang = contents . toString ( ) . split ( / [ \r \n ] + / ) [ 0 ] ;
41+ return shebang . replace ( / ^ # ! / , '' ) ;
42+ }
43+
3844
3945// create a temporary directory and init an npm package there
4046const testDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'dredd-hooks-template-test-' ) ) ;
@@ -58,10 +64,10 @@ run('npx', ['dredd-hooks-template', 'init'], { cwd: testDir });
5864//
5965// (instead of 'dredd-hooks-python', the handler command is going to be
6066// something like '../…/bin/python ../…/bin/dredd-hooks-python')
61- const relativePathBase = path . join ( testDir , 'package.json ') ;
62- const pythonPath = path . relative ( relativePathBase , which . sync ( 'python' ) ) ;
63- const executablePath = path . relative ( relativePathBase , which . sync ( 'dredd-hooks-python' ) ) ;
64- const handlerCommand = `${ pythonPath } ${ executablePath } ` ;
67+ const executablePath = which . sync ( 'dredd-hooks-python ') ;
68+ const pythonPath = parseShebang ( fs . readFileSync ( executablePath ) ) ;
69+ const relativeBase = path . join ( testDir , 'package.json' ) ;
70+ const handlerCommand = `${ path . relative ( relativeBase , pythonPath ) } ${ path . relative ( relativeBase , executablePath ) } ` ;
6571
6672// make custom changes to the '*.feature' files so they're able to test
6773// the Python hooks (reference implementation)
0 commit comments