Skip to content

Commit

Permalink
Merge pull request #888 from gemini-testing/feat/issue/883
Browse files Browse the repository at this point in the history
feat: add ability to extend hermione.ctx typings
  • Loading branch information
KuznetsovRoman authored Mar 27, 2024
2 parents 58aba75 + ffda61b commit 78fa5fa
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -826,6 +828,48 @@ Parameters:
- ignoreNetworkErrorsPatterns (optional) `Array<String | RegExp>` - 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.

Expand Down
4 changes: 3 additions & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,10 @@ export interface TestResultWithRetries extends TestResult {
retriesLeft: number;
}

export interface HermioneCtx extends Record<string, unknown> {}

export interface GlobalHelper {
ctx: Record<string, unknown>;
ctx: HermioneCtx;
skip: SkipController;
only: OnlyController;
browser: (browserName: string) => BrowserVersionController;
Expand Down

0 comments on commit 78fa5fa

Please sign in to comment.