Skip to content

Commit e6567cc

Browse files
committed
cover local/global installs on mac, linux
1 parent b0cbf21 commit e6567cc

File tree

5 files changed

+147
-120
lines changed

5 files changed

+147
-120
lines changed

‎lib/create-runner.js

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
1-
"use strict";
2-
var child = require('child_process');
3-
function createRunner(config, testFile) {
4-
var python = '/usr/local/bin/python';
5-
return child.exec([
6-
python,
7-
'-m pytest',
8-
'--tap-stream',
9-
'-x',
10-
'--tb=no',
11-
testFile
12-
].join(' '));
13-
}
14-
Object.defineProperty(exports, "__esModule", { value: true });
15-
exports.default = createRunner;
1+
"use strict";
2+
var exists_1 = require('./exists');
3+
var child = require('child_process');
4+
var python = 'python';
5+
var localPath = '/usr/local/bin/python';
6+
var globalPath = '/usr/bin/python';
7+
if (process.platform === 'darwin' && process.resourcesPath) {
8+
if (exists_1.default(localPath)) {
9+
python = localPath;
10+
}
11+
else if (exists_1.default(globalPath)) {
12+
python = globalPath;
13+
}
14+
else {
15+
throw 'Python not found. Python may not be installed';
16+
}
17+
}
18+
function createRunner(config, testFile) {
19+
return child.exec([
20+
python,
21+
'-m pytest',
22+
'--tap-stream',
23+
'-x',
24+
'--tb=no',
25+
testFile
26+
].join(' '));
27+
}
28+
Object.defineProperty(exports, "__esModule", { value: true });
29+
exports.default = createRunner;

‎lib/exists.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
"use strict";
2-
var fs = require('fs');
3-
function fileExists(path) {
4-
try {
5-
fs.accessSync(path, fs.F_OK);
6-
}
7-
catch (e) {
8-
if (e) {
9-
if (e.code !== 'ENOENT') {
10-
console.log(e);
11-
}
12-
return false;
13-
}
14-
}
15-
return true;
16-
}
17-
Object.defineProperty(exports, "__esModule", { value: true });
18-
exports.default = fileExists;
1+
"use strict";
2+
var fs = require('fs');
3+
function fileExists(path) {
4+
try {
5+
fs.accessSync(path, fs.F_OK);
6+
}
7+
catch (e) {
8+
if (e) {
9+
if (e.code !== 'ENOENT') {
10+
console.log(e);
11+
}
12+
return false;
13+
}
14+
}
15+
return true;
16+
}
17+
Object.defineProperty(exports, "__esModule", { value: true });
18+
exports.default = fileExists;

‎lib/parse-tap.js

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
1-
"use strict";
2-
var isTap = /^# TAP/m;
3-
var finalTestNumber = /^1..([0-9+])$/m;
4-
var testError = /^# E\s+(.+)$/m;
5-
function formatFailureMessage(message) {
6-
return message.split('_').join(' ');
7-
}
8-
function parseTap(data) {
9-
if (!data.match(isTap)) {
10-
console.log('No TAP output: ', data);
11-
return;
12-
}
13-
if (!data.match(finalTestNumber)) {
14-
console.log('Could not parse final test number: ', data);
15-
return;
16-
}
17-
var finalTest = parseInt(data.match(finalTestNumber)[1], 10);
18-
var final = null;
19-
if (data.match(testError)) {
20-
var failingLineRegex = new RegExp("^not ok " + finalTest + " - (.+)$", 'm');
21-
var line = data.match(failingLineRegex)[1];
22-
if (!line) {
23-
console.log('Error matching failing test line: ', data);
24-
}
25-
var taskPosition = parseInt(line.match(/Test([0-9]+)/)[1], 10);
26-
if (!taskPosition) {
27-
console.log('No matching taskPosition', data);
28-
}
29-
var message = formatFailureMessage(line.match(/\.test_(.+)$/)[1]);
30-
if (!message) {
31-
console.log('Error with test. There is no valid test message: ', data);
32-
message = '';
33-
}
34-
final = {
35-
completed: false,
36-
msg: formatFailureMessage(message),
37-
taskPosition: taskPosition - 1,
38-
timedOut: false
39-
};
40-
}
41-
else {
42-
var finalPassRegex = new RegExp("^ok " + finalTest + " - (.+)$", 'm');
43-
var line = data.match(finalPassRegex)[1];
44-
var taskPosition = parseInt(line.match(/Test([0-9]+)/)[1], 10);
45-
final = {
46-
completed: true,
47-
msg: "Task " + taskPosition + " Complete",
48-
taskPosition: taskPosition
49-
};
50-
}
51-
return final;
52-
}
53-
Object.defineProperty(exports, "__esModule", { value: true });
54-
exports.default = parseTap;
1+
"use strict";
2+
var isTap = /^# TAP/m;
3+
var finalTestNumber = /^1..([0-9+])$/m;
4+
var testError = /^# E\s+(.+)$/m;
5+
function formatFailureMessage(message) {
6+
return message.split('_').join(' ');
7+
}
8+
function parseTap(data) {
9+
if (!data.match(isTap)) {
10+
console.log('No TAP output: ', data);
11+
return;
12+
}
13+
if (!data.match(finalTestNumber)) {
14+
console.log('Could not parse final test number: ', data);
15+
return;
16+
}
17+
var finalTest = parseInt(data.match(finalTestNumber)[1], 10);
18+
var final = null;
19+
if (data.match(testError)) {
20+
var failingLineRegex = new RegExp("^not ok " + finalTest + " - (.+)$", 'm');
21+
var line = data.match(failingLineRegex)[1];
22+
if (!line) {
23+
console.log('Error matching failing test line: ', data);
24+
}
25+
var taskPosition = parseInt(line.match(/Test([0-9]+)/)[1], 10);
26+
if (!taskPosition) {
27+
console.log('No matching taskPosition', data);
28+
}
29+
var message = formatFailureMessage(line.match(/\.test_(.+)$/)[1]);
30+
if (!message) {
31+
console.log('Error with test. There is no valid test message: ', data);
32+
message = '';
33+
}
34+
final = {
35+
completed: false,
36+
msg: formatFailureMessage(message),
37+
taskPosition: taskPosition - 1,
38+
timedOut: false
39+
};
40+
}
41+
else {
42+
var finalPassRegex = new RegExp("^ok " + finalTest + " - (.+)$", 'm');
43+
var line = data.match(finalPassRegex)[1];
44+
var taskPosition = parseInt(line.match(/Test([0-9]+)/)[1], 10);
45+
final = {
46+
completed: true,
47+
msg: "Task " + taskPosition + " Complete",
48+
taskPosition: taskPosition
49+
};
50+
}
51+
return final;
52+
}
53+
Object.defineProperty(exports, "__esModule", { value: true });
54+
exports.default = parseTap;

‎lib/runner.js

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
"use strict";
2-
var create_runner_1 = require('./create-runner');
3-
var parse_tap_1 = require('./parse-tap');
4-
function runner(testFile, config, handleResult) {
5-
var runner = create_runner_1.default(config, testFile);
6-
var final = null;
7-
return new Promise(function (resolve, reject) {
8-
runner.stdout.on('data', function (data) {
9-
data = data.toString();
10-
final = parse_tap_1.default(data);
11-
final.change = final.taskPosition - config.taskPosition;
12-
final.pass = final.change > 0;
13-
handleResult(final);
14-
});
15-
runner.stderr.on('data', function (data) {
16-
if (data.length) {
17-
console.log('test error', data.toString());
18-
}
19-
});
20-
runner.on('end', function (code) {
21-
if (code === 0) {
22-
resolve(final);
23-
}
24-
else {
25-
resolve(final);
26-
}
27-
});
28-
});
29-
}
30-
Object.defineProperty(exports, "__esModule", { value: true });
31-
exports.default = runner;
1+
"use strict";
2+
var create_runner_1 = require('./create-runner');
3+
var parse_tap_1 = require('./parse-tap');
4+
function runner(testFile, config, handleResult) {
5+
var runner = create_runner_1.default(config, testFile);
6+
var final = null;
7+
return new Promise(function (resolve, reject) {
8+
runner.stdout.on('data', function (data) {
9+
data = data.toString();
10+
final = parse_tap_1.default(data);
11+
final.change = final.taskPosition - config.taskPosition;
12+
final.pass = final.change > 0;
13+
handleResult(final);
14+
});
15+
runner.stderr.on('data', function (data) {
16+
if (data.length) {
17+
console.log('test error', data.toString());
18+
}
19+
});
20+
runner.on('end', function (code) {
21+
if (code === 0) {
22+
resolve(final);
23+
}
24+
else {
25+
resolve(final);
26+
}
27+
});
28+
});
29+
}
30+
Object.defineProperty(exports, "__esModule", { value: true });
31+
exports.default = runner;

‎src/create-runner.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1+
import exists from './exists';
12
const child = require('child_process');
23

3-
export default function createRunner(config: CR.Config, testFile: string) {
4+
let python = 'python';
5+
let localPath = '/usr/local/bin/python';
6+
let globalPath = '/usr/bin/python';
7+
8+
if (process.platform === 'darwin' && process.resourcesPath) {
9+
if (exists(localPath)) {
10+
python = localPath;
11+
} else if (exists(globalPath)) {
12+
python = globalPath;
13+
} else {
14+
throw 'Python not found. Python may not be installed';
15+
}
16+
}
417

5-
let python = '/usr/local/bin/python';
18+
export default function createRunner(config: CR.Config, testFile: string) {
619

720
return child.exec([
821
python,

0 commit comments

Comments
 (0)