From ce911d6fd5acaa58b671e94b827b178da27b8ee0 Mon Sep 17 00:00:00 2001 From: Opeyemi Ibrahim Date: Thu, 21 Nov 2024 11:10:48 +0100 Subject: [PATCH] :closes: #143 add process to rename and push test files to git --- package.json | 1 + report.ts | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 report.ts diff --git a/package.json b/package.json index 26841f3..26d3f2c 100755 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "test:lrc": "$npm_package_config_testCommand --tags @lrc", "test:performancehints": "$npm_package_config_testCommand --tags @performancehints", "healthcheck": "ts-node healthcheck.ts", + "push-report": "ts-node report.ts", "wp-env": "wp-env" }, "repository": { diff --git a/report.ts b/report.ts new file mode 100644 index 0000000..bda5d28 --- /dev/null +++ b/report.ts @@ -0,0 +1,39 @@ +import fs from 'fs'; +import path from "path"; +import {exec} from "child_process"; + + +const testResults = path.join(__dirname, 'test-results'); + +const args = process.argv.slice(2); +if(args.length < 1) { + console.error('Please provide the new naming for test folder') +} +const newTestDir = args[0]; + +const gitCommands = `git add . && git commit -m "Add test report" && git push origin test`; + +// Rename test folder and push +fs.rename(testResults, newTestDir, (err) => { + if (err) { + console.error('Error renaming/moving file:', err); + } else { + exec(gitCommands, { cwd: newTestDir }, (err, stdout, stderr) => { + if (err) { + console.error('Error executing git commands:', err); + } + + if (stderr) { + console.error('Git stderr output:', stderr); + return; + } + + //Revert the renaming of test folder to avoid tracking it in e2e + fs.rename(newTestDir, testResults, (err) => { + if (err) { + console.error('Error reverting the directory name:', err); + } + }); + }); + } +}); \ No newline at end of file