From 540893cd3cdadcdd25cfc4d2a0b6a114a77cc164 Mon Sep 17 00:00:00 2001 From: Roman Kuznetsov Date: Wed, 27 Mar 2024 14:18:02 +0300 Subject: [PATCH 1/2] feat: add ability to extend hermione.ctx typings --- src/types/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/types/index.ts b/src/types/index.ts index cb93dbdfd..e7cdb480e 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -133,8 +133,10 @@ export interface TestResultWithRetries extends TestResult { retriesLeft: number; } +export interface HermioneCtx extends Record {} + export interface GlobalHelper { - ctx: Record; + ctx: HermioneCtx; skip: SkipController; only: OnlyController; browser: (browserName: string) => BrowserVersionController; From ffda61b6979e4c74f8bb11bbca745e42fbfabf5d Mon Sep 17 00:00:00 2001 From: Roman Kuznetsov Date: Wed, 27 Mar 2024 15:07:22 +0300 Subject: [PATCH 2/2] docs: add basic typescript usage docs --- README.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/README.md b/README.md index 04885344a..557b18131 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,8 @@ Hermione is a utility for integration testing of web pages using [WebdriverIO](h - [AssertView](#assertview) - [RunStep](#runstep) - [OpenAndWait](#openandwait) +- [Typescript usage](#typescript-usage) + - [hermione.ctx typings](#hermionectx-typings) - [.hermione.conf.js](#hermioneconfjs) - [sets](#sets) - [browsers](#browsers) @@ -826,6 +828,48 @@ Parameters: - ignoreNetworkErrorsPatterns (optional) `Array` - Array of url patterns to ignore network requests errors. Has a priority over `shouldThrowError` - timeout (optional) `Number` - Page load timeout. [pageLoadTimeout](#pageloadtimeout) by default. Throws an error, if selectors are still not exist after timeout, or predicate is still resolving false. +## Typescript usage + +To write hermione tests on typescript, you would need to install `ts-node`: + +```bash +npm i -D ts-node +``` + +And include hermione types in your `tsconfig.json` file: + +```js +// tsconfig.json +{ + // other tsconfig options + "compilerOptions": { + // other compiler options + "types": [ + // other types + "hermione", + ] + } +} +``` + +Now you will be able to write hermione tests using typescript. + +### hermione.ctx typings + +If you want to extend hermione.ctx typings, you could use module augmentation: + +```ts +import type { HermioneCtx } from "hermione"; + +declare module "hermione" { + interface HermioneCtx { + someVariable: string; + } +} +``` + +Now `hermione.ctx` will have `someVariable` typings + ## .hermione.conf.js `hermione` is tuned using a configuration file. By default, it uses `.hermione.conf.js`, but you can use the `--config` option to specify a path to the configuration file.