Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit 3267ce7

Browse files
committed
test: use shebang for the Python path
1 parent 6b4de15 commit 3267ce7

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

scripts/smoke-test.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
4046
const 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

Comments
 (0)