Skip to content

Commit 2e0a7f9

Browse files
Merge conflicts resolved
2 parents 6347939 + e6446dc commit 2e0a7f9

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pythagora",
3-
"version": "0.0.78",
3+
"version": "0.0.79",
44
"author": {
55
"name": "Zvonimir Sabljic",
66
"email": "[email protected]"

src/helpers/api.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,18 @@ function setOptions({path, method, headers}) {
4141

4242
async function makeRequest(data, options, customLogFunction) {
4343
let gptResponse = '';
44-
let end = false;
4544
let httpModule = options.protocol === 'http' ? require('http') : require('https');
45+
let timeout;
4646

4747
return new Promise((resolve, reject) => {
4848
const req = httpModule.request(_.omit(options, ['protocol']), function(res){
4949
res.on('data', (chunk) => {
5050
try {
51+
clearTimeout(timeout);
52+
timeout = setTimeout(() => {
53+
reject(new Error("Request timeout"));
54+
}, 30000);
55+
5156
let stringified = chunk.toString();
5257
try {
5358
let json = JSON.parse(stringified);
@@ -58,11 +63,14 @@ async function makeRequest(data, options, customLogFunction) {
5863
} catch (e) {}
5964

6065
gptResponse += stringified;
66+
if (gptResponse.indexOf('pythagora_end:') > -1) return;
6167
if (customLogFunction) customLogFunction(gptResponse);
6268
else process.stdout.write(stringified);
6369
} catch (e) {}
6470
});
6571
res.on('end', async function () {
72+
clearTimeout(timeout);
73+
6674
process.stdout.write('\n');
6775
if (res.statusCode >= 400) return reject(new Error(`Response status code: ${res.statusCode}. Error message: ${gptResponse}`));
6876
if (gptResponse.error) return reject(new Error(`Error: ${gptResponse.error.message}. Code: ${gptResponse.error.code}`));
@@ -73,6 +81,7 @@ async function makeRequest(data, options, customLogFunction) {
7381
});
7482

7583
req.on('error', (e) => {
84+
clearTimeout(timeout);
7685
console.error("problem with request:"+e.message);
7786
reject(e);
7887
});

src/helpers/starting.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ const {
77
EXPORTED_TESTS_DATA_DIR,
88
PYTHAGORA_METADATA_DIR,
99
METADATA_FILENAME,
10-
EXPORT_METADATA_FILENAME
10+
EXPORT_METADATA_FILENAME,
11+
PYTHAGORA_UNIT_DIR
1112
} = require("../const/common");
1213
let args = require('../utils/getArgs.js');
1314

@@ -91,10 +92,19 @@ function startPythagora(args, app) {
9192

9293
function setUpPythagoraDirs() {
9394
let root = args.pythagora_root;
94-
if (!fs.existsSync(path.resolve(root, PYTHAGORA_TESTS_DIR))) fs.mkdirSync(path.resolve(root, PYTHAGORA_TESTS_DIR));
95-
if (!fs.existsSync(path.resolve(root, EXPORTED_TESTS_DIR))) fs.mkdirSync(path.resolve(root, EXPORTED_TESTS_DIR));
96-
if (!fs.existsSync(path.resolve(root, EXPORTED_TESTS_DATA_DIR))) fs.mkdirSync(path.resolve(root, EXPORTED_TESTS_DATA_DIR));
97-
if (!fs.existsSync(path.resolve(root, PYTHAGORA_METADATA_DIR))) fs.mkdirSync(path.resolve(root, PYTHAGORA_METADATA_DIR));
95+
const directories = [
96+
PYTHAGORA_TESTS_DIR,
97+
EXPORTED_TESTS_DIR,
98+
EXPORTED_TESTS_DATA_DIR,
99+
PYTHAGORA_UNIT_DIR,
100+
PYTHAGORA_METADATA_DIR
101+
];
102+
103+
directories.forEach(directory => {
104+
const directoryPath = path.resolve(root, directory);
105+
if (!fs.existsSync(directoryPath)) fs.mkdirSync(directoryPath);
106+
});
107+
98108
if (!fs.existsSync(path.resolve(root, PYTHAGORA_METADATA_DIR, METADATA_FILENAME))) fs.writeFileSync(path.resolve(root, PYTHAGORA_METADATA_DIR, METADATA_FILENAME), '{}');
99109
if (!fs.existsSync(path.resolve(root, PYTHAGORA_METADATA_DIR, EXPORT_METADATA_FILENAME))) fs.writeFileSync(path.resolve(root, PYTHAGORA_METADATA_DIR, EXPORT_METADATA_FILENAME), '{}');
100110
}

src/helpers/unitTests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ async function createTests(filePath, funcToTest, processingFunction = 'getUnitTe
157157
try {
158158
let extension = path.extname(filePath);
159159
let ast = await getAstFromFilePath(filePath);
160-
const fileIndex = folderStructureTree.findIndex(item => item.absolutePath === filePath);
161160

162161
const foundFunctions = [];
163162

@@ -188,6 +187,7 @@ async function createTests(filePath, funcToTest, processingFunction = 'getUnitTe
188187

189188
sortFolderTree(folderStructureTree);
190189

190+
const fileIndex = folderStructureTree.findIndex(item => item.absolutePath === filePath);
191191
for (const [i, funcData] of uniqueFoundFunctions.entries()) {
192192
let indexToPush = fileIndex + 1 + i;
193193
let prefix = folderStructureTree[fileIndex].line.split(path.basename(folderStructureTree[fileIndex].absolutePath))[0];

0 commit comments

Comments
 (0)