From 5520e73ea3d5117612b42cc2f20856aa174bf6aa Mon Sep 17 00:00:00 2001 From: home1 Date: Sun, 16 Apr 2023 23:00:51 +0300 Subject: [PATCH 1/2] Added the checkerLibraryVersion class for compares the local library version with the remote version on GitHub --- hstest/stage/checkerLibraryVersion.ts | 49 +++++++++++++++++++++++++++ hstest/stage/stageTest.ts | 10 ++++++ 2 files changed, 59 insertions(+) create mode 100644 hstest/stage/checkerLibraryVersion.ts diff --git a/hstest/stage/checkerLibraryVersion.ts b/hstest/stage/checkerLibraryVersion.ts new file mode 100644 index 0000000..369ad05 --- /dev/null +++ b/hstest/stage/checkerLibraryVersion.ts @@ -0,0 +1,49 @@ +import packageJson from "../../package.json"; + +/** + * CheckerLibraryVersion is a class responsible for comparing the local library + * version with the remote version available on GitHub. + * + * It helps to ensure that the user is using the latest version of the library. + */ +class CheckerLibraryVersion { + + constructor() {} + + /** + * Compares the local library version with the remote version on GitHub. + * + * If the versions are different, an error message will be logged to the console, + * or an Error will be thrown if the throwError flag is set to true. + * + * @param throwError {boolean} - Optional flag to indicate if an Error should be + * thrown when versions are different. Default is false. + * @returns {Promise} - A promise that resolves when the check is complete. + */ + async checkLibraryVersion(throwError = false): Promise { + + const libraryVersionUrl = "https://github.com/hyperskill/hs-test-web/blob/master/package.json"; + try { + const response = await fetch(libraryVersionUrl); + const packageRemoteJson = await response.json(); + const remoteVersion = packageRemoteJson.version; + const localVersion = packageJson.version; + if (remoteVersion !== localVersion) { + const errorMsg = `The version of the local library (${localVersion}) is different from the version on GitHub (${remoteVersion}). + Please update your local version.`; + if (throwError) { + throw new Error(errorMsg); + } else { + console.error(errorMsg); + } + } + } catch (error) { + console.error("Error while checking library version:\n", error); + if (throwError) { + throw error; + } + } + } +} + +export default CheckerLibraryVersion; \ No newline at end of file diff --git a/hstest/stage/stageTest.ts b/hstest/stage/stageTest.ts index af9acd7..c04faa5 100644 --- a/hstest/stage/stageTest.ts +++ b/hstest/stage/stageTest.ts @@ -9,6 +9,7 @@ import Outcome from "../outcome/outcome.js"; import OutcomeFactory from "../outcome/outcomeFactory.js"; import WrongAnswer from "../exception/outcome/WrongAnswer.js"; import UnexpectedErrorOutcome from "../outcome/unexpectedErrorOutcome.js"; +import CheckerLibraryVersion from "./checkerLibraryVersion"; import puppeteer from "puppeteer"; class StageTest { @@ -17,6 +18,15 @@ class StageTest { runner: TestRunner = new JsRunner(); tests: NoArgsFunction[] = []; + checkerLibraryVersion: CheckerLibraryVersion = new CheckerLibraryVersion(); + + constructor() { + // Perform the library version check upon class instantiation + this.checkerLibraryVersion.checkLibraryVersion().catch((error) => { + console.error("Error while checking library version:", error); + }); + } + getPage(url: string, options: puppeteer.WaitForOptions = {}): Page { return new Page(url, this.runner.browser, options); } From b891c42493add2ceacd5dc982c0f2768f7fab6e5 Mon Sep 17 00:00:00 2001 From: home1 Date: Thu, 20 Apr 2023 23:00:08 +0300 Subject: [PATCH 2/2] Added the instruction in the comment for upgrade library --- hstest/stage/checkerLibraryVersion.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hstest/stage/checkerLibraryVersion.ts b/hstest/stage/checkerLibraryVersion.ts index 369ad05..024d3c9 100644 --- a/hstest/stage/checkerLibraryVersion.ts +++ b/hstest/stage/checkerLibraryVersion.ts @@ -30,7 +30,9 @@ class CheckerLibraryVersion { const localVersion = packageJson.version; if (remoteVersion !== localVersion) { const errorMsg = `The version of the local library (${localVersion}) is different from the version on GitHub (${remoteVersion}). - Please update your local version.`; + Please update your local version. + You can download the new version of the library at the link: https://github.com/hyperskill/hs-test-web/archive/release.tar.gz + To upgrade, install the new version using the command: npm install /path/to/your/archive/hs-test-web-release.tar.gz`; if (throwError) { throw new Error(errorMsg); } else {