Skip to content

Commit

Permalink
Merge pull request #20 from hyperskill/master
Browse files Browse the repository at this point in the history
Upgrade dependencies
  • Loading branch information
polischuks authored Sep 8, 2023
2 parents 92ce34e + 0de7530 commit fc6f7ff
Show file tree
Hide file tree
Showing 12 changed files with 3,313 additions and 9,945 deletions.
7 changes: 7 additions & 0 deletions dist/hstest/environment/page.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/hstest/environment/page.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dist/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hs-test-web-ts",
"version": "1.0.0",
"version": "4.0.1",
"description": "Hyperskill Testing Library on TypeScript",
"main": "dist/hstest/index.js",
"scripts": {
Expand Down Expand Up @@ -36,8 +36,8 @@
"style-loader": "^1.2.1",
"ts-node": "^10.4.0",
"typescript": "^4.5.4",
"webpack": "^4.43.0",
"webpack": "^4.46.0",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.10.3"
"webpack-dev-server": "^4.11.1"
}
}
9 changes: 9 additions & 0 deletions hstest/environment/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ class Page {
isOpened: boolean;
pageInstance!: puppeteer.Page;
gotoOptions: puppeteer.WaitForOptions;
requests: Array<puppeteer.HTTPRequest>;

constructor(url: string, browser: Browser, gotoOptions: puppeteer.WaitForOptions) {
this.url = url;
this.browser = browser;
this.isOpened = false;
this.gotoOptions = gotoOptions;
this.requests = [];
}

async open(): Promise<void> {
Expand All @@ -29,9 +31,16 @@ class Page {
await this.pageInstance.goto(this.url, this.gotoOptions);
await BrowserPageHandler.initHyperskillContext(this.pageInstance);
await BrowserPageHandler.initKeyboardEvents(this.pageInstance);
await this.setUpRequestInterceptor();
this.isOpened = true;
}

setUpRequestInterceptor(): void {
this.pageInstance.on('request', async request => {
this.requests.push(request);
});
}

execute(func: NoArgsFunction): NoArgsFunction {
return async () => {
await this.open();
Expand Down
51 changes: 51 additions & 0 deletions hstest/stage/checkerLibraryVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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<void>} - A promise that resolves when the check is complete.
*/
async checkLibraryVersion(throwError = false): Promise<void> {

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.
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 {
console.error(errorMsg);
}
}
} catch (error) {
console.error("Error while checking library version:\n", error);
if (throwError) {
throw error;
}
}
}
}

export default CheckerLibraryVersion;
10 changes: 10 additions & 0 deletions hstest/stage/stageTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
Expand Down
Loading

0 comments on commit fc6f7ff

Please # to comment.