Skip to content

Commit e5080a1

Browse files
authored
Merge pull request #1 from gemini-testing/users/rocketraccoon/TESTPLANE-635.publish-testing-library
Testplane testing library
2 parents d6e2f53 + 0730f2e commit e5080a1

File tree

15 files changed

+14177
-0
lines changed

15 files changed

+14177
-0
lines changed

.github/workflows/ci.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
test:
15+
name: Run tests on Node.js ${{ matrix.node-version }}
16+
runs-on: self-hosted-arc
17+
18+
strategy:
19+
matrix:
20+
node-version: [18, 20, 22, 24]
21+
fail-fast: false
22+
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v4
26+
27+
- name: Setup Node.js ${{ matrix.node-version }}
28+
uses: actions/setup-node@v4
29+
with:
30+
node-version: ${{ matrix.node-version }}
31+
cache: "npm"
32+
33+
- name: Install dependencies
34+
run: npm ci
35+
36+
- name: Run lint
37+
run: npm run lint
38+
39+
- name: Check formatting
40+
run: npm run check-formatting
41+
42+
- name: Run build
43+
run: npm run build

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
build
3+
tmp
4+
.vscode
5+
.idea

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
22

.prettierignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.idea
2+
build
3+
LICENSE
4+
package.json
5+
package-lock.json
6+
*.md
7+
.gitignore
8+
.nvmrc
9+
.prettierignore
10+
.github

.prettierrc.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
printWidth: 120,
3+
useTabs: false,
4+
tabWidth: 4,
5+
semi: true,
6+
singleQuote: false,
7+
trailingComma: "all",
8+
bracketSpacing: true,
9+
arrowParens: "avoid",
10+
};

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 YANDEX LLC
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<p align="center">
2+
<picture>
3+
<source media="(prefers-color-scheme: dark)" srcset="./docs/images/logo-light.svg" width="600">
4+
<source media="(prefers-color-scheme: light)" srcset="./docs/images/logo-dark.svg" width="600">
5+
<img alt="testplane testing library logo" src="./docs/images/logo-dark.svg" width="600">
6+
</picture>
7+
</p>
8+
9+
<p align="center">
10+
<a href="https://testplane.io/docs/v8/guides/how-to-add-testing-library/"><img src="https://img.shields.io/badge/Docs-Website-6c47ff" alt="Total Downloads"></a>
11+
<a href="https://www.npmjs.com/Яpackage/@testplane/testing-library"><img src="https://img.shields.io/npm/v/@testplane/testing-library.svg" alt="Latest Release"></a>
12+
<a href="https://github.com/gemini-testing/testplane-testing-library/blob/master/LICENSE"><img src="https://img.shields.io/npm/l/@testplane/testing-library.svg" alt="License"></a>
13+
<a href="https://t.me/testplane"><img src="https://img.shields.io/badge/community-chat-blue?logo=telegram" alt="Community Chat"></a>
14+
</p>
15+
16+
17+
## Introduction
18+
[Testing-library](https://testing-library.com/) is a collection of tools for testing web application user interfaces, focused on creating reliable and maintainable tests by emphasizing user behavior. The main advantage of `testing-library` is its focus on interaction with interface elements. And in testplane, you can use the element search methods provided by the `testing-library` itself.
19+
20+
## Installation
21+
22+
1. Install the npm package `@testplane/testing-library`:
23+
```shell
24+
npm i -D @testplane/testing-library
25+
```
26+
27+
2. Include it in the Testplane config in the `prepareBrowser` section:
28+
```js
29+
// .testplane.conf.js
30+
const { setupBrowser } = require("@testplane/testing-library");
31+
32+
module.exports = {
33+
prepareBrowser(browser) {
34+
setupBrowser(browser);
35+
},
36+
37+
// other Testplane settings...
38+
};
39+
```
40+
41+
If you are using TypeScript and experiencing issues with testing-library types, you may add the following line to your tsconfig.json
42+
43+
```json
44+
{
45+
"compilerOptions": {
46+
"types": [
47+
"@testplane/testing-library"
48+
]
49+
}
50+
}
51+
```
52+
53+
## Usage
54+
55+
After configuring, you will be able to use the search by selectors from `testing-library`, as described in the [official documentation](https://testing-library.com/docs/queries/about/). For example, searching for an element by its text:
56+
57+
```js
58+
it("example", async ({ browser }) => {
59+
await browser.url("https://github.com/");
60+
61+
const newRepoButton = await browser.getByText("New");
62+
63+
await newRepoButton.click();
64+
});
65+
66+
67+
```
68+
69+
This feature will also be available in the context of found elements:
70+
71+
```js
72+
it("example", async ({ browser }) => {
73+
await browser.url("https://github.com/");
74+
75+
const sidebar = await browser.$(".dashboard-sidebar");
76+
const newRepoButton = await sidebar.getByText("New");
77+
78+
await newRepoButton.click();
79+
});
80+
```
81+
82+
Disclaimer:
83+
All testing-library selectors return a promise and cannot be chained (like `browser.getByText().click()` — this is not possible).
84+
Each testing-library selector must be awaited before performing any actions on it.

docs/images/logo-dark.svg

Lines changed: 1 addition & 0 deletions
Loading

docs/images/logo-light.svg

Lines changed: 1 addition & 0 deletions
Loading

eslint.config.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const js = require("@eslint/js");
2+
const globals = require("globals");
3+
const tseslint = require("typescript-eslint");
4+
const { defineConfig } = require("eslint/config");
5+
6+
module.exports = defineConfig([
7+
{
8+
ignores: ["node_modules/**", "build/**", "eslint.config.js"],
9+
},
10+
{
11+
files: ["**/*.{js,mjs,cjs,ts}"],
12+
plugins: { js },
13+
extends: ["js/recommended"],
14+
},
15+
{
16+
files: ["**/*.{js,mjs,cjs,ts}"],
17+
languageOptions: {
18+
globals: globals.node,
19+
},
20+
},
21+
tseslint.configs.recommended,
22+
]);

0 commit comments

Comments
 (0)