deflake 1.2.6 → 1.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/cli.js +43 -19
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -960,6 +960,27 @@ async function analyzeFailures(artifacts, fullLog, client) {
960
960
  if (results.length > 0 && argv.fix && argv.report) {
961
961
  showFrameworkReport();
962
962
  }
963
+
964
+ return results.length;
965
+ }
966
+
967
+ /**
968
+ * Helper to run a shell command and capture output.
969
+ */
970
+ async function runCommand(cmd, args) {
971
+ return new Promise((resolve) => {
972
+ console.log(`šŸš€ Running command: ${cmd} ${args.join(' ')}`);
973
+ const child = spawn(cmd, args, { shell: true, stdio: 'pipe' });
974
+ let stdout = '';
975
+ let stderr = '';
976
+
977
+ child.stdout.on('data', (data) => { process.stdout.write(data); stdout += data.toString(); });
978
+ child.stderr.on('data', (data) => { process.stderr.write(data); stderr += data.toString(); });
979
+
980
+ child.on('close', (code) => {
981
+ resolve({ code, output: stdout + "\n" + stderr });
982
+ });
983
+ });
963
984
  }
964
985
 
965
986
  async function main() {
@@ -976,26 +997,29 @@ async function main() {
976
997
  if (command.length > 0) {
977
998
  const cmd = command[0];
978
999
  const args = command.slice(1);
979
- console.log(`šŸš€ Running command: ${cmd} ${args.join(' ')}`);
980
-
981
- const child = spawn(cmd, args, { shell: true, stdio: 'pipe' });
982
- let stdout = '';
983
- let stderr = '';
984
-
985
- child.stdout.on('data', (data) => { process.stdout.write(data); stdout += data.toString(); });
986
- child.stderr.on('data', (data) => { process.stderr.write(data); stderr += data.toString(); });
987
-
988
- child.on('close', async (code) => {
989
- if (code !== 0) {
990
- console.log(`\nšŸ”“ Command failed with code ${code}. Activating DeFlake...`);
991
- const artifacts = detectAllArtifacts(null, argv.html);
992
- await analyzeFailures(artifacts, stdout + "\n" + stderr, client);
993
- process.exit(code);
994
- } else {
995
- console.log("\n🟢 Command passed successfully.");
996
- process.exit(0);
1000
+
1001
+ let { code, output } = await runCommand(cmd, args);
1002
+
1003
+ if (code !== 0) {
1004
+ console.log(`\nšŸ”“ Command failed with code ${code}. Activating DeFlake...`);
1005
+ const artifacts = detectAllArtifacts(null, argv.html);
1006
+ const fixesApplied = await analyzeFailures(artifacts, output, client);
1007
+
1008
+ // AUTO-VERIFICATION
1009
+ if (fixesApplied > 0 && argv.fix) {
1010
+ console.log(`\n${C.BRIGHT}šŸ’‰ Fixes applied. Re-running tests to verify...${C.RESET}`);
1011
+ const secondRun = await runCommand(cmd, args);
1012
+ if (secondRun.code === 0) {
1013
+ console.log(`\n${C.GREEN}${C.BRIGHT}āœ… All tests passed after DeFlake healing!${C.RESET}`);
1014
+ } else {
1015
+ console.log(`\n${C.YELLOW}āš ļø Some tests still failing after fixes. Check the report for details.${C.RESET}`);
1016
+ }
997
1017
  }
998
- });
1018
+ process.exit(code);
1019
+ } else {
1020
+ console.log("\n🟢 Command passed successfully.");
1021
+ process.exit(0);
1022
+ }
999
1023
  } else {
1000
1024
  const artifacts = detectAllArtifacts(argv.log, argv.html);
1001
1025
  const fullLog = argv.log && fs.existsSync(argv.log) ? fs.readFileSync(argv.log, 'utf8') : null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deflake",
3
- "version": "1.2.6",
3
+ "version": "1.2.8",
4
4
  "description": "AI-powered self-healing tool for Playwright, Cypress, and WebdriverIO tests.",
5
5
  "main": "client.js",
6
6
  "bin": {