Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/ci.yml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not related to this file: having .nvmrc is a must. Right now after checking out this repo it's not clear which Node version should be used for development.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another issue I've stumbled upon when trying to use this package is ENOENT error. Here's what I did:

  1. checked out this repo, npm ci + npm run build + npm pack to get tgz of this package.
  2. switched to my testing project and installed this tgz like this npm i -D @testplane/[email protected]
  3. Written this test:
it('should take a screenshot', async ({browser}) => {
    await browser.url('https://example.com/');

    const element = await (browser as any).getByText('Example Domain');

    await element.assertView('target-block');
});

Got this error:

Promise: Promise {
  <rejected> Error: ENOENT: no such file or directory, open '/Users/shadowusr/dev/tp-ts-playground/node_modules/@testplane/testing-library/node_modules/@testing-library/dom/dist/@testing-library/dom.umd.js'
      at Object.openSync (node:fs:573:18)
      at Object.readFileSync (node:fs:452:35)
      at Object.<anonymous> (/Users/shadowusr/dev/tp-ts-playground/node_modules/@testplane/testing-library/build/index.js:32:46)
      at Module._compile (node:internal/modules/cjs/loader:1469:14)
      at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)
      at Object.require.extensions.<computed> [as .js] (/Users/shadowusr/dev/tp-ts-playground/node_modules/ts-node/src/index.ts:1608:43)
      at Module.load (node:internal/modules/cjs/loader:1288:32)
      at Function.Module._load (node:internal/modules/cjs/loader:1104:12)
      at Module.require (node:internal/modules/cjs/loader:1311:19)
      at require (node:internal/modules/helpers:179:18)
      at Object.<anonymous> (/Users/shadowusr/dev/tp-ts-playground/.testplane.conf.ts:2:1)
      at Module._compile (node:internal/modules/cjs/loader:1469:14)
      at Module.m._compile (/Users/shadowusr/dev/tp-ts-playground/node_modules/ts-node/src/index.ts:1618:23)
      at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)
      at Object.require.extensions.<computed> [as .ts] (/Users/shadowusr/dev/tp-ts-playground/node_modules/ts-node/src/index.ts:1621:12)
      at Module.load (node:internal/modules/cjs/loader:1288:32) {
    errno: -2,
    code: 'ENOENT',
    syscall: 'open',
    path: '/Users/shadowusr/dev/tp-ts-playground/node_modules/@testplane/testing-library/node_modules/@testing-library/dom/dist/@testing-library/dom.umd.js'
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: CI

on:
push:
branches: [master]
pull_request:
branches: [master]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
test:
name: Run tests on Node.js ${{ matrix.node-version }}
runs-on: self-hosted-arc

strategy:
matrix:
node-version: [18, 20, 22, 24]
fail-fast: false

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "npm"

- name: Install dependencies
run: npm ci

- name: Run lint
run: npm run lint

- name: Check formatting
run: npm run check-formatting

- name: Run build
run: npm run build
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
build
tmp
.vscode
.idea
10 changes: 10 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.idea
build
LICENSE
package.json
package-lock.json
*.md
.gitignore
.nvmrc
.prettierignore
.github
10 changes: 10 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
printWidth: 120,
useTabs: false,
tabWidth: 4,
semi: true,
singleQuote: false,
trailingComma: "all",
bracketSpacing: true,
arrowParens: "avoid",
};
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2015 YANDEX LLC

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Testplane testing library
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's adopt a unified README style that we use across our repos. Here are logos for this repo:

Other things like badges you may copy from our mcp repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed for logo


## Introduction
[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.

## Connection
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think connection has a slightly different meaning, imo "installation" fits better here, but not critical to me

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


1. Install the npm package `@testplane/testing-library`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

colon is missing at the end of the line (not critical)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

```shell
npm i -D @testplane/testing-library
```

2. Include it in the Testplane config in the `prepareBrowser` section:
```js
// .testplane.conf.js
const { setupBrowser } = require("@testplane/testing-library");

module.exports = {
prepareBrowser(browser) {
setupBrowser(browser);
},

// other Testplane settings...
};
```

## Usage

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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a disclaimer here that as of now all testing-library selectors return a promise and cannot be chained (like browser.getByText().click() — this is not possible). Each testing-library selector must be awaited before performing any actions on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


```js
it("example", async ({ browser }) => {
await browser.url("https://github.com/");

const newRepoButton = await browser.getByText("New");

await newRepoButton.click();
});


```

This feature will also be available in the context of found elements:

```js
it("example", async ({ browser }) => {
await browser.url("https://github.com/");

const sidebar = await browser.$(".dashboard-sidebar");
const newRepoButton = await sidebar.getByText("New");

await newRepoButton.click();
});
```
22 changes: 22 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const js = require("@eslint/js");
const globals = require("globals");
const tseslint = require("typescript-eslint");
const { defineConfig } = require("eslint/config");

module.exports = defineConfig([
{
ignores: ["node_modules/**", "build/**", "eslint.config.js"],
},
{
files: ["**/*.{js,mjs,cjs,ts}"],
plugins: { js },
extends: ["js/recommended"],
},
{
files: ["**/*.{js,mjs,cjs,ts}"],
languageOptions: {
globals: globals.node,
},
},
tseslint.configs.recommended,
]);
Loading