From ef2e6eed0994617fc70ae2c4fbe03b2395521805 Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Mon, 27 Jan 2025 21:42:53 +0600 Subject: [PATCH 01/12] . t clean up abandoned files --- .../test/nested_folder_tests.root_folder.approved.txt | 1 - .../sub-folder-a/nested_folder_tests.sub_folder_a.approved.txt | 1 - .../sub-folder-b/nested_folder_tests.sub_folder_b.approved.txt | 1 - test/Providers/Mocha/_before_each__hook_in___root__.approved.txt | 0 .../Reporters/_before_each__hook_in___root__.approved.txt | 0 5 files changed, 3 deletions(-) delete mode 100644 test-projects/mochajs-tests/test/nested_folder_tests.root_folder.approved.txt delete mode 100644 test-projects/mochajs-tests/test/sub-folder-a/nested_folder_tests.sub_folder_a.approved.txt delete mode 100644 test-projects/mochajs-tests/test/sub-folder-b/nested_folder_tests.sub_folder_b.approved.txt delete mode 100644 test/Providers/Mocha/_before_each__hook_in___root__.approved.txt delete mode 100644 test/Reporting/Reporters/_before_each__hook_in___root__.approved.txt 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 From 573e75dc4c67f01135003631f6d56dc11f2fe4be Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Mon, 27 Jan 2025 22:39:29 +0600 Subject: [PATCH 02/12] . t the command line test now runs in a temp directory --- test/commandLineTests.mts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/test/commandLineTests.mts b/test/commandLineTests.mts index a857b023..0f0bc178 100644 --- a/test/commandLineTests.mts +++ b/test/commandLineTests.mts @@ -1,12 +1,20 @@ import shelljs from "shelljs"; import path from "path"; +import fs from "fs"; +import * as os from "node:os"; describe("Command Line", function () { it("Should run approvals CLI with basic text input", function (done) { + // get the absolute path for ./ + // const pwd = process.cwd(); + const pwd = '/Users/il/Documents/git/Approvals.NodeJS'; var cliTestCommand = 'echo "Hello\nWorld" | ' + - path.join("./", "bin", "index.js") + - " --reporter gitdiff --errorOnStaleApprovedFiles=false --outdir ./test commandlineTest"; + path.join(pwd, "/", "bin", "index.js") + + " --reporter gitdiff --errorOnStaleApprovedFiles=false --outdir "+ pwd + "/test 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 +23,7 @@ describe("Command Line", function () { } done(); }); + + process.chdir(pwd); }); }); From 77f5345b63074eaf804c1dbb5e79e29b60d80d8e Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Mon, 27 Jan 2025 22:44:25 +0600 Subject: [PATCH 03/12] . t use cwd --- test/commandLineTests.mts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/commandLineTests.mts b/test/commandLineTests.mts index 0f0bc178..2070848a 100644 --- a/test/commandLineTests.mts +++ b/test/commandLineTests.mts @@ -2,12 +2,11 @@ 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) { - // get the absolute path for ./ - // const pwd = process.cwd(); - const pwd = '/Users/il/Documents/git/Approvals.NodeJS'; + const pwd = process.cwd(); var cliTestCommand = 'echo "Hello\nWorld" | ' + path.join(pwd, "/", "bin", "index.js") + From ef50c8bc1fdf10e686b963692f5485ce287ed791 Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Mon, 27 Jan 2025 22:45:52 +0600 Subject: [PATCH 04/12] . t prettify --- test/commandLineTests.mts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test/commandLineTests.mts b/test/commandLineTests.mts index 2070848a..44f46e32 100644 --- a/test/commandLineTests.mts +++ b/test/commandLineTests.mts @@ -6,14 +6,16 @@ import assert from "assert"; describe("Command Line", function () { it("Should run approvals CLI with basic text input", function (done) { - const pwd = process.cwd(); + const pwd = process.cwd(); var cliTestCommand = 'echo "Hello\nWorld" | ' + path.join(pwd, "/", "bin", "index.js") + - " --reporter gitdiff --errorOnStaleApprovedFiles=false --outdir "+ pwd + "/test commandlineTest"; + " --reporter gitdiff --errorOnStaleApprovedFiles=false --outdir " + + pwd + + "/test commandlineTest"; - const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'example-')); - process.chdir(tempDir); + const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "example-")); + process.chdir(tempDir); shelljs.exec(cliTestCommand, { async: true }, function (code, output) { if (code !== 0) { @@ -23,6 +25,6 @@ describe("Command Line", function () { done(); }); - process.chdir(pwd); + process.chdir(pwd); }); }); From a69b62188286c5f15dfd5ddc41d065941d311bc4 Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Mon, 27 Jan 2025 22:46:33 +0600 Subject: [PATCH 05/12] . t use const instead of var --- test/commandLineTests.mts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/commandLineTests.mts b/test/commandLineTests.mts index 44f46e32..453aa52f 100644 --- a/test/commandLineTests.mts +++ b/test/commandLineTests.mts @@ -7,7 +7,7 @@ import assert from "assert"; describe("Command Line", function () { it("Should run approvals CLI with basic text input", function (done) { const pwd = process.cwd(); - var cliTestCommand = + const cliTestCommand = 'echo "Hello\nWorld" | ' + path.join(pwd, "/", "bin", "index.js") + " --reporter gitdiff --errorOnStaleApprovedFiles=false --outdir " + From 61540a945d29702945a96d4d6af0a5a88be89af6 Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Mon, 27 Jan 2025 22:48:00 +0600 Subject: [PATCH 06/12] . t extract variable --- test/commandLineTests.mts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/commandLineTests.mts b/test/commandLineTests.mts index 453aa52f..6a4325c9 100644 --- a/test/commandLineTests.mts +++ b/test/commandLineTests.mts @@ -7,9 +7,10 @@ import assert from "assert"; describe("Command Line", function () { it("Should run approvals CLI with basic text input", function (done) { const pwd = process.cwd(); + const script = path.join(pwd, "/", "bin", "index.js"); const cliTestCommand = 'echo "Hello\nWorld" | ' + - path.join(pwd, "/", "bin", "index.js") + + script + " --reporter gitdiff --errorOnStaleApprovedFiles=false --outdir " + pwd + "/test commandlineTest"; From 3f1badb9e12a939adab7978bec8654d9ec818f89 Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Mon, 27 Jan 2025 22:48:59 +0600 Subject: [PATCH 07/12] . t extract variables --- test/commandLineTests.mts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/commandLineTests.mts b/test/commandLineTests.mts index 6a4325c9..53d83706 100644 --- a/test/commandLineTests.mts +++ b/test/commandLineTests.mts @@ -8,12 +8,13 @@ describe("Command Line", function () { it("Should run approvals CLI with basic text input", function (done) { const pwd = process.cwd(); const script = path.join(pwd, "/", "bin", "index.js"); + let testDirectory = pwd + "/test"; const cliTestCommand = 'echo "Hello\nWorld" | ' + script + " --reporter gitdiff --errorOnStaleApprovedFiles=false --outdir " + - pwd + - "/test commandlineTest"; + testDirectory + + " commandlineTest"; const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "example-")); process.chdir(tempDir); From 9009ecde371115a2d968c5504f3f312a69eed8a6 Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Mon, 27 Jan 2025 22:50:17 +0600 Subject: [PATCH 08/12] . t use backticks to compose string --- test/commandLineTests.mts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/test/commandLineTests.mts b/test/commandLineTests.mts index 53d83706..40852647 100644 --- a/test/commandLineTests.mts +++ b/test/commandLineTests.mts @@ -8,13 +8,9 @@ describe("Command Line", function () { it("Should run approvals CLI with basic text input", function (done) { const pwd = process.cwd(); const script = path.join(pwd, "/", "bin", "index.js"); - let testDirectory = pwd + "/test"; - const cliTestCommand = - 'echo "Hello\nWorld" | ' + - script + - " --reporter gitdiff --errorOnStaleApprovedFiles=false --outdir " + - testDirectory + - " commandlineTest"; + 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); From d612fc6f3ab05e9a7c4efe5d46d0535ae189e24c Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Mon, 27 Jan 2025 23:03:36 +0600 Subject: [PATCH 09/12] - r extract local variable --- lib/Logs/FailedFileLog.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/Logs/FailedFileLog.ts b/lib/Logs/FailedFileLog.ts index ca31bfd6..3c09db7c 100644 --- a/lib/Logs/FailedFileLog.ts +++ b/lib/Logs/FailedFileLog.ts @@ -26,17 +26,20 @@ export class FailedFileLog { } this.downloadedScriptCheck = true; + const baseScript = `approve_all`; + try { const extension = process.platform === "win32" ? ".bat" : ".sh"; - const scriptPath = path.join( + + 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); From b5206f6f486fa15356b74461d801bacf1d711cf2 Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Mon, 27 Jan 2025 23:04:30 +0600 Subject: [PATCH 10/12] . r extract method --- lib/Logs/FailedFileLog.ts | 44 ++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/lib/Logs/FailedFileLog.ts b/lib/Logs/FailedFileLog.ts index 3c09db7c..34c64e56 100644 --- a/lib/Logs/FailedFileLog.ts +++ b/lib/Logs/FailedFileLog.ts @@ -1,8 +1,8 @@ import * as fs from "fs"; import * as path from "path"; -import { ApprovedFileLog } from "./ApprovedFileLog"; +import {ApprovedFileLog} from "./ApprovedFileLog"; import axios from "axios"; -import { JestUtils } from "../Utilities/JestUtils"; +import {JestUtils} from "../Utilities/JestUtils"; let runOnce = false; export class FailedFileLog { @@ -26,31 +26,33 @@ export class FailedFileLog { } this.downloadedScriptCheck = true; - const baseScript = `approve_all`; + await this.downloadFile(`approve_all`); + } - try { - const extension = process.platform === "win32" ? ".bat" : ".sh"; + private static async downloadFile(baseScript: string) { + try { + const extension = process.platform === "win32" ? ".bat" : ".sh"; - const scriptPath = path.join( - ApprovedFileLog.APPROVAL_TEMP_DIRECTORY, - `${baseScript}${extension}`, - ); + const scriptPath = path.join( + ApprovedFileLog.APPROVAL_TEMP_DIRECTORY, + `${baseScript}${extension}`, + ); - if (!fs.existsSync(scriptPath)) { - const githubUrl = - "https://raw.githubusercontent.com/approvals/ApprovalTests.Java/refs/heads/master/"; - const filePath = `resources/${baseScript}${extension}`; - const response = await axios.get(`${githubUrl}${filePath}`); + if (!fs.existsSync(scriptPath)) { + const githubUrl = + "https://raw.githubusercontent.com/approvals/ApprovalTests.Java/refs/heads/master/"; + const filePath = `resources/${baseScript}${extension}`; + const response = await axios.get(`${githubUrl}${filePath}`); - fs.writeFileSync(scriptPath, response.data); - fs.chmodSync(scriptPath, 0o755); - } - } catch (error) { - // Do nothing + fs.writeFileSync(scriptPath, response.data); + fs.chmodSync(scriptPath, 0o755); + } + } catch (error) { + // Do nothing + } } - } - public static getLogFilePath(): string { + public static getLogFilePath(): string { return path.join( ApprovedFileLog.APPROVAL_TEMP_DIRECTORY, ".failed_comparison.log", From e6e3970e419197b192ff3a59782b8aaee7cdd35e Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Mon, 27 Jan 2025 23:05:08 +0600 Subject: [PATCH 11/12] . r prettify --- lib/Logs/FailedFileLog.ts | 44 +++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/Logs/FailedFileLog.ts b/lib/Logs/FailedFileLog.ts index 34c64e56..74352ea5 100644 --- a/lib/Logs/FailedFileLog.ts +++ b/lib/Logs/FailedFileLog.ts @@ -1,8 +1,8 @@ import * as fs from "fs"; import * as path from "path"; -import {ApprovedFileLog} from "./ApprovedFileLog"; +import { ApprovedFileLog } from "./ApprovedFileLog"; import axios from "axios"; -import {JestUtils} from "../Utilities/JestUtils"; +import { JestUtils } from "../Utilities/JestUtils"; let runOnce = false; export class FailedFileLog { @@ -26,33 +26,33 @@ export class FailedFileLog { } this.downloadedScriptCheck = true; - await this.downloadFile(`approve_all`); + await this.downloadFile(`approve_all`); } - private static async downloadFile(baseScript: string) { - try { - const extension = process.platform === "win32" ? ".bat" : ".sh"; + private static async downloadFile(baseScript: string) { + try { + const extension = process.platform === "win32" ? ".bat" : ".sh"; - const scriptPath = path.join( - ApprovedFileLog.APPROVAL_TEMP_DIRECTORY, - `${baseScript}${extension}`, - ); + const scriptPath = path.join( + ApprovedFileLog.APPROVAL_TEMP_DIRECTORY, + `${baseScript}${extension}`, + ); - if (!fs.existsSync(scriptPath)) { - const githubUrl = - "https://raw.githubusercontent.com/approvals/ApprovalTests.Java/refs/heads/master/"; - const filePath = `resources/${baseScript}${extension}`; - const response = await axios.get(`${githubUrl}${filePath}`); + if (!fs.existsSync(scriptPath)) { + const githubUrl = + "https://raw.githubusercontent.com/approvals/ApprovalTests.Java/refs/heads/master/"; + const filePath = `resources/${baseScript}${extension}`; + const response = await axios.get(`${githubUrl}${filePath}`); - fs.writeFileSync(scriptPath, response.data); - fs.chmodSync(scriptPath, 0o755); - } - } catch (error) { - // Do nothing - } + fs.writeFileSync(scriptPath, response.data); + fs.chmodSync(scriptPath, 0o755); + } + } catch (error) { + // Do nothing } + } - public static getLogFilePath(): string { + public static getLogFilePath(): string { return path.join( ApprovedFileLog.APPROVAL_TEMP_DIRECTORY, ".failed_comparison.log", From 0f303cdc6e85581bd79d2b9ac41fdea7cc4dd569 Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Mon, 27 Jan 2025 23:07:10 +0600 Subject: [PATCH 12/12] - F load detect_and_remove_abandoned script --- lib/Logs/FailedFileLog.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Logs/FailedFileLog.ts b/lib/Logs/FailedFileLog.ts index 74352ea5..1961e0a0 100644 --- a/lib/Logs/FailedFileLog.ts +++ b/lib/Logs/FailedFileLog.ts @@ -27,6 +27,7 @@ export class FailedFileLog { this.downloadedScriptCheck = true; await this.downloadFile(`approve_all`); + await this.downloadFile(`detect_and_remove_abandoned`); } private static async downloadFile(baseScript: string) {