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. 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;