Skip to content

Commit a88e193

Browse files
Merge branch 'main' into refactoring-export
2 parents 6d4e391 + 2b57c73 commit a88e193

File tree

4 files changed

+12
-55
lines changed

4 files changed

+12
-55
lines changed

pythagora_tests/unit/src/helpers/api/cleanupGPTResponse.test.js

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/helpers/api.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ async function makeRequest(data, options, customLogFunction) {
6767
if (res.statusCode >= 400) reject(new Error(`Response status code: ${res.statusCode}. Error message: ${gptResponse}`));
6868
if (gptResponse.error) reject(new Error(`Error: ${gptResponse.error.message}. Code: ${gptResponse.error.code}`));
6969
if (gptResponse.message) reject(new Error(`Error: ${gptResponse.message}. Code: ${gptResponse.code}`));
70-
gptResponse = cleanupGPTResponse(gptResponse);
70+
gptResponse = gptResponse.split('pythagora_end:').pop();
7171
resolve(gptResponse);
7272
});
7373
});
@@ -130,14 +130,6 @@ async function isEligibleForExport(test) {
130130
}
131131
}
132132

133-
function cleanupGPTResponse(gptResponse) {
134-
if (gptResponse.substring(0, 3) === "```") {
135-
gptResponse = gptResponse.substring(gptResponse.indexOf('\n') + 1, gptResponse.lastIndexOf('```'));
136-
}
137-
138-
return gptResponse;
139-
}
140-
141133
function checkForAPIKey() {
142134
if (!args.pythagora_api_key && !args.openai_api_key) {
143135
console.log(`${bold+red}No API key found!${reset}`);
@@ -155,7 +147,6 @@ module.exports = {
155147
getJestTest,
156148
getJestTestName,
157149
isEligibleForExport,
158-
cleanupGPTResponse,
159150
getUnitTests,
160151
checkForAPIKey
161152
}

src/helpers/unitTests.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ let functionList = {},
2929
testsGenerated = [],
3030
errors = [],
3131
ignoreFolders = ['node_modules', 'pythagora_tests'],
32-
processExtensions = ['.js']
32+
processExtensions = ['.js'],
33+
ignoreErrors = ['BABEL_PARSER_SYNTAX_ERROR'],
34+
force
3335
;
3436

3537
async function processFile(filePath) {
@@ -156,7 +158,7 @@ async function createTests(filePath, prefix, funcToTest) {
156158
spinner.start(folderStructureTree, indexToPush);
157159

158160
let testFilePath = path.join(getTestFilePath(filePath, rootPath), `/${funcData.functionName}.test.js`);
159-
if (fs.existsSync(testFilePath)) {
161+
if (fs.existsSync(testFilePath) && !force) {
160162
await spinner.stop();
161163
folderStructureTree[indexToPush].line = `${green}${folderStructureTree[indexToPush].line}${reset}`;
162164
continue;
@@ -190,8 +192,7 @@ async function createTests(filePath, prefix, funcToTest) {
190192
}
191193

192194
} catch (e) {
193-
errors.push(e);
194-
// writeLine(`Error parsing file ${filePath}: ${e}`);
195+
if (!ignoreErrors.includes(e.code)) errors.push(e);
195196
}
196197
}
197198

@@ -255,7 +256,11 @@ async function getFunctionsForExport(dirPath) {
255256
return functionList;
256257
}
257258

258-
async function generateTestsForDirectory(pathToProcess, funcName) {
259+
async function generateTestsForDirectory(args) {
260+
let pathToProcess = args.path,
261+
funcName = args.func;
262+
force = args.force;
263+
259264
checkForAPIKey();
260265
queriedPath = path.resolve(pathToProcess);
261266
rootPath = process.cwd();

src/scripts/unit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ if (!args.path && !args.func) {
66
process.exit(1);
77
}
88
if (!args.path) args.path = process.cwd();
9-
generateTestsForDirectory(args.path, args.func);
9+
generateTestsForDirectory(args);

0 commit comments

Comments
 (0)