Skip to content

Commit

Permalink
refactor(e2e): changes for inclusion in monorepo
Browse files Browse the repository at this point in the history
  • Loading branch information
Haroenv committed Nov 23, 2022
1 parent 1e31e06 commit 6c7b809
Show file tree
Hide file tree
Showing 27 changed files with 113 additions and 3,906 deletions.
44 changes: 44 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,50 @@ module.exports = {
],
},
},
{
files: ['tests/e2e/**/*'],
parserOptions: {
project: 'tests/e2e/tsconfig.json',
},
rules: {
'valid-jsdoc': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: 'WebdriverIOAsync',
ignoreRestSiblings: true,
},
],
'@typescript-eslint/no-floating-promises': 'error',
},
},
{
files: [
'tests/e2e/specs/**/*.spec.ts',
'tests/e2e/all-flavors.spec.ts',
'tests/e2e/helpers/**/*.ts',
'tests/e2e/wdio.*.conf.js',
],
extends: ['plugin:wdio/recommended'],
plugins: ['wdio'],
env: {
jasmine: true,
},
rules: {
// we are exporting test "factories", so we need to allow export
'jest/no-export': 0,
// we use jasmine
'jest/expect-expect': 0,
'@typescript-eslint/no-namespace': 0,
},
},
{
files: ['tests/e2e/**/*.js'],
rules: {
'import/no-commonjs': 0,
},
},
],
settings: {
react: {
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const config = {
testPathIgnorePatterns: [
'<rootDir>/packages/*/node_modules/',
'<rootDir>/packages/*/dist*',
'<rootDir>/tests/e2e/*',
],
watchPathIgnorePatterns: [
'<rootDir>/packages/*/cjs',
Expand Down
12 changes: 2 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"website:examples": "lerna run website:examples",
"lint": "eslint --ext .js,.ts,.tsx .",
"lint:fix": "eslint --ext .js,.ts,.tsx --fix .",
"type-check": "tsc",
"type-check": "tsc && lerna run type-check",
"type-check:v3": "tsc --project tsconfig.v3.json",
"test": "jest",
"test:size": "bundlesize",
Expand Down Expand Up @@ -46,14 +46,6 @@
"@types/storybook__addon-actions": "3.4.2",
"@typescript-eslint/eslint-plugin": "5.38.1",
"@typescript-eslint/parser": "4.15.1",
"@wdio/cli": "5.16.9",
"@wdio/jasmine-framework": "5.16.5",
"@wdio/junit-reporter": "5.16.11",
"@wdio/local-runner": "5.16.9",
"@wdio/sauce-service": "5.16.5",
"@wdio/selenium-standalone-service": "5.16.5",
"@wdio/spec-reporter": "5.16.5",
"@wdio/static-server-service": "5.16.5",
"algoliasearch": "4.11.0",
"algoliasearch-v3": "npm:[email protected]",
"babel-eslint": "10.0.3",
Expand All @@ -76,7 +68,7 @@
"eslint-plugin-prettier": "3.4.0",
"eslint-plugin-react": "7.18.0",
"eslint-plugin-react-hooks": "2.3.0",
"instantsearch-e2e-tests": "algolia/instantsearch-e2e-tests#feat/monorepo",
"eslint-plugin-wdio": "5.11.0",
"jest": "27.1.0",
"jest-diff": "27.1.0",
"jest-environment-jsdom": "27.1.0",
Expand Down
2 changes: 0 additions & 2 deletions packages/instantsearch.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@
"build:types": "scripts/typescript/extract.js",
"storybook": "start-storybook --quiet --port 6006 --ci --static-dir .storybook/static",
"storybook:build": "build-storybook --quiet --output-dir ../../website/stories/js --static-dir .storybook/static",
"type-check": "tsc",
"type-check:v3": "tsc --project tsconfig.v3.json",
"test": "jest",
"test:exports": "node test/module/is-es-module.mjs",
"version": "./scripts/version/update-version.js"
Expand Down
7 changes: 4 additions & 3 deletions scripts/wdio/local.conf.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable import/no-commonjs */

const { local } = require('instantsearch-e2e-tests');

exports.config = local;
exports.config = {
...require('@instantsearch/e2e-tests').local,
// you can override the default options if needed here
};
6 changes: 3 additions & 3 deletions scripts/wdio/saucelabs.conf.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable import/no-commonjs */

const { saucelabs } = require('instantsearch-e2e-tests');

exports.config = saucelabs;
exports.config = {
...require('@instantsearch/e2e-tests').saucelabs,
};
46 changes: 0 additions & 46 deletions tests/e2e/.circleci/config.yml

This file was deleted.

8 changes: 0 additions & 8 deletions tests/e2e/.editorconfig

This file was deleted.

2 changes: 0 additions & 2 deletions tests/e2e/.eslintignore

This file was deleted.

47 changes: 0 additions & 47 deletions tests/e2e/.eslintrc.js

This file was deleted.

5 changes: 0 additions & 5 deletions tests/e2e/.prettierrc

This file was deleted.

1 change: 0 additions & 1 deletion tests/e2e/.yarnrc

This file was deleted.

61 changes: 3 additions & 58 deletions tests/e2e/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,12 @@
# Contributing

This repository contains the end-to-end (e2e) test suite for [InstantSearch](https://github.com/algolia/instantsearch.js). This test suite is meant to be shared across all InstantSearch flavors, this is why it is stored in a separate repository.
This repository contains the end-to-end (e2e) test suite for InstantSearch. This test suite is meant to be shared across all InstantSearch flavors, this is why it is stored in the monorepo.

## Development

### Requirements

To run this project, you will need:

- Node.js >= v8.10.0, use nvm - [install instructions](https://github.com/creationix/nvm#install-script)
- Yarn >= v1.16.0 - [install instructions](https://yarnpkg.com/en/docs/install#alternatives-stable)

### Installation

The easiest way to work on the tests is to link them into an InstantSearch project using [`yarn link`](https://yarnpkg.com/en/docs/cli/link).

First, clone the `instantsearch-e2e-tests` repository, install its dependencies and link it.

```sh
git clone [email protected]:algolia/instantsearch-e2e-tests.git
cd instantsearch-e2e-tests
yarn
yarn link
```

Then, clone the [`instantsearch.js`](https://github.com/algolia/instantsearch.js/) repository (or any other flavor), install its dependencies and link `instantsearch-e2e-tests`.

```sh
git clone [email protected]:algolia/instantsearch.js
cd instantsearch.js
yarn
yarn link instantsearch-e2e-tests
```

You can now run your local end-2-end test suite using the `test:e2e:*` scripts from the InstantSearch project.
Running the tests

```sh
yarn test:e2e # Run the test suite on Chrome browser on your local machine
Expand All @@ -60,7 +33,7 @@ One spec file represents a scenario to test a behavior from a user point of view

Example of scenario:

1. Load the `examples/e-commerce/` page
1. Load the `examples/js/e-commerce/` page
2. Click on "Appliances" category
3. Click on rating "4 & up"
4. Check if the result list matches the expected one
Expand Down Expand Up @@ -122,31 +95,3 @@ A library of helpers is available in the [`helpers`](helpers) directory and are
These helpers are here to simplify the writing of tests, their readability and their maintenance. You are strongly encouraged to use them in your tests and to contribute to the helpers library.

You can find more information about helpers in [WebdriverIO documentation](https://webdriver.io/docs/customcommands.html#adding-custom-commands).

## Release

This project uses [AngularJS's commit message convention](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines) with [Commitizen](http://commitizen.github.io/cz-cli/).

### Commit current changes

```sh
yarn commit
```

### Release a new version

```sh
yarn version
```

### Updating dependents projects

This package is not published on the npm registry. To update the test suite in an InstantSearch project, run the following command in it:

```sh
yarn add -D "algolia/instantsearch-e2e-tests#XXX"
```

(`XXX` being the tag for the version you want to install)

If [Renovate](https://renovatebot.com/) is enabled on your project then it should update it automatically like any other dependency.
13 changes: 2 additions & 11 deletions tests/e2e/README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
# End-2-End test suite for InstantSearch

This repository contains the end-2-end test suite for [InstantSearch](https://github.com/algolia/instantsearch.js).
This repository contains the end-2-end test suite for InstantSearch.

## Installation

Install `instantsearch-e2e-tests` and its peerDependencies in your InstantSearch project:

```bash
yarn add --dev \
algolia/instantsearch-e2e-tests \
@wdio/cli @wdio/jasmine-framework @wdio/spec-reporter \
@wdio/junit-reporter @wdio/static-server-service \
@wdio/local-runner @wdio/selenium-standalone-service \
@wdio/sauce-service
```
The workspace automatically links the dependencies when you run `yarn` at the root of the repository.

## Running the test suite

Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/all-flavors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { pagination } from './specs/pagination.spec';
import { priceRange } from './specs/price-range.spec';
import { flavors } from './flavors';

flavors.forEach(flavor => {
describe(flavor, () => {
flavors.forEach((flavor) => {
describe(`${flavor}`, () => {
brandAndQuery(flavor);
category(flavor);
initialStateFromRoute(flavor);
Expand Down
9 changes: 7 additions & 2 deletions tests/e2e/helpers/dragAndDropByOffset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ browser.addCommand(
// so we create a dummy element in the document to use as a target
/* eslint-disable prefer-template */
const targetId = await browser.execute(
function(browserSourceX, browserSourceY, browserOffsetX, browserOffsetY) {
function (
browserSourceX,
browserSourceY,
browserOffsetX,
browserOffsetY
) {
const target = document.createElement('div');
target.id = 'tmp-' + Math.floor(Math.random() * 1e9);
target.style.position = 'absolute';
Expand All @@ -46,7 +51,7 @@ browser.addCommand(
await source.dragAndDrop(target);

// Cleaning
await browser.execute(function(browserTargetId) {
await browser.execute(function (browserTargetId) {
const el = document.getElementById(browserTargetId);
if (el) {
document.body.removeChild(el);
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/helpers/getTextFromSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ declare namespace WebdriverIOAsync {
}

browser.addCommand('getTextFromSelector', (selector: string) => {
return browser.execute(function(browserSelector) {
return browser.execute(function (browserSelector) {
const elements = document.querySelectorAll(browserSelector);

return Array.prototype.slice.call(elements).map(function(el) {
return Array.prototype.slice.call(elements).map(function (el) {
return el.innerText;
});
}, selector);
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/helpers/waitForElement.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
declare namespace WebdriverIOAsync {
interface Browser {
waitForElement(selector: string | Function): Promise<boolean>;
waitForElement(selector: string): Promise<boolean>;
}
}

Expand Down
Loading

0 comments on commit 6c7b809

Please sign in to comment.