diff --git a/lib/Logs/FailedFileLog.ts b/lib/Logs/FailedFileLog.ts index ca31bfd6..1961e0a0 100644 --- a/lib/Logs/FailedFileLog.ts +++ b/lib/Logs/FailedFileLog.ts @@ -26,17 +26,23 @@ export class FailedFileLog { } this.downloadedScriptCheck = true; + await this.downloadFile(`approve_all`); + await this.downloadFile(`detect_and_remove_abandoned`); + } + + private static async downloadFile(baseScript: string) { try { const extension = process.platform === "win32" ? ".bat" : ".sh"; + const scriptPath = path.join( ApprovedFileLog.APPROVAL_TEMP_DIRECTORY, - `approve_all${extension}`, + `${baseScript}${extension}`, ); if (!fs.existsSync(scriptPath)) { const githubUrl = "https://raw.githubusercontent.com/approvals/ApprovalTests.Java/refs/heads/master/"; - const filePath = `resources/approve_all${extension}`; + const filePath = `resources/${baseScript}${extension}`; const response = await axios.get(`${githubUrl}${filePath}`); fs.writeFileSync(scriptPath, response.data); diff --git a/test-projects/mochajs-tests/test/nested_folder_tests.root_folder.approved.txt b/test-projects/mochajs-tests/test/nested_folder_tests.root_folder.approved.txt deleted file mode 100644 index 5a670f56..00000000 --- a/test-projects/mochajs-tests/test/nested_folder_tests.root_folder.approved.txt +++ /dev/null @@ -1 +0,0 @@ -root-folder diff --git a/test-projects/mochajs-tests/test/sub-folder-a/nested_folder_tests.sub_folder_a.approved.txt b/test-projects/mochajs-tests/test/sub-folder-a/nested_folder_tests.sub_folder_a.approved.txt deleted file mode 100644 index ed238fcd..00000000 --- a/test-projects/mochajs-tests/test/sub-folder-a/nested_folder_tests.sub_folder_a.approved.txt +++ /dev/null @@ -1 +0,0 @@ -sub-folder-a diff --git a/test-projects/mochajs-tests/test/sub-folder-b/nested_folder_tests.sub_folder_b.approved.txt b/test-projects/mochajs-tests/test/sub-folder-b/nested_folder_tests.sub_folder_b.approved.txt deleted file mode 100644 index e8269cd8..00000000 --- a/test-projects/mochajs-tests/test/sub-folder-b/nested_folder_tests.sub_folder_b.approved.txt +++ /dev/null @@ -1 +0,0 @@ -sub-folder-b diff --git a/test/Providers/Mocha/_before_each__hook_in___root__.approved.txt b/test/Providers/Mocha/_before_each__hook_in___root__.approved.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/test/Reporting/Reporters/_before_each__hook_in___root__.approved.txt b/test/Reporting/Reporters/_before_each__hook_in___root__.approved.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/test/commandLineTests.mts b/test/commandLineTests.mts index a857b023..40852647 100644 --- a/test/commandLineTests.mts +++ b/test/commandLineTests.mts @@ -1,12 +1,19 @@ import shelljs from "shelljs"; import path from "path"; +import fs from "fs"; +import * as os from "node:os"; +import assert from "assert"; describe("Command Line", function () { it("Should run approvals CLI with basic text input", function (done) { - var cliTestCommand = - 'echo "Hello\nWorld" | ' + - path.join("./", "bin", "index.js") + - " --reporter gitdiff --errorOnStaleApprovedFiles=false --outdir ./test commandlineTest"; + const pwd = process.cwd(); + const script = path.join(pwd, "/", "bin", "index.js"); + const testDirectory = pwd + "/test"; + const cliTestCommand = `echo "Hello +World" | ${script} --reporter gitdiff --errorOnStaleApprovedFiles=false --outdir ${testDirectory} commandlineTest`; + + const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "example-")); + process.chdir(tempDir); shelljs.exec(cliTestCommand, { async: true }, function (code, output) { if (code !== 0) { @@ -15,5 +22,7 @@ describe("Command Line", function () { } done(); }); + + process.chdir(pwd); }); });