Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: add eslint command for generated test file #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions util/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import fs from 'fs';
import {exec} from 'child_process';

// eslint-disable-next-line no-unused-vars
import colors from '@colors/colors';

Expand All @@ -23,19 +25,20 @@ test('generated test', async ({ page }) => {
}

export function appendToTestFile(userInput, generatedCode, filePath) {
let formattedCode = `\t// ${userInput}\n`;
let formattedCode = `// ${userInput}\n`;

// Split the code into lines and format each line
const lines = generatedCode.split('\n');
for (const line of lines) {
formattedCode += `\t${line.trim()}\n`;
formattedCode += `${line.trim()}\n`;
}

fs.appendFileSync(filePath, `${formattedCode}\n`, 'utf8');
}

export function completeTestFile(filePath) {
fs.appendFileSync(filePath, '});', 'utf8');
runESLint(filePath);
}

export function gracefulExit(options) {
Expand All @@ -45,3 +48,9 @@ export function gracefulExit(options) {

console.log('Exiting'.red);
}

function runESLint(filePath) {
exec(`npx eslint ${filePath} --fix`, () => {
console.log(`ESLint ran on ${filePath}`.green);
});
}