Repository: marmelab/gremlins.js
Branch: master
Commit: cbcd182f2d76
Files: 59
Total size: 104.8 KB
Directory structure:
gitextract__jhz54jw/
├── .babelrc
├── .eslintignore
├── .eslintrc.js
├── .github/
│ ├── ISSUE_TEMPLATE/
│ │ ├── bug_report.md
│ │ ├── config.yml
│ │ ├── feature_request.md
│ │ └── question.md
│ ├── ISSUE_TEMPLATE.md
│ └── PULL_REQUEST_TEMPLATE.md
├── .gitignore
├── .npmrc
├── .prettierignore
├── .prettierrc
├── .travis.yml
├── CHANGELOG.md
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── Makefile
├── README.md
├── bookmarklet/
│ ├── index.css
│ └── index.html
├── cypress/
│ ├── fixtures/
│ │ └── example.json
│ ├── integration/
│ │ └── formFiller.spec.js
│ ├── pages/
│ │ └── formFiller.html
│ ├── plugins/
│ │ └── index.js
│ └── support/
│ ├── commands.js
│ └── index.js
├── cypress.json
├── jest.config.js
├── package.json
├── rollup.config.js
└── src/
├── index.js
├── mogwais/
│ ├── alert.js
│ ├── alert.spec.js
│ ├── fps.js
│ ├── fps.spec.js
│ ├── gizmo.js
│ └── gizmo.spec.js
├── species/
│ ├── clicker.js
│ ├── clicker.spec.js
│ ├── formFiller.js
│ ├── formFiller.spec.js
│ ├── scroller.js
│ ├── scroller.spec.js
│ ├── toucher.js
│ ├── toucher.spec.js
│ ├── typer.js
│ └── typer.spec.js
├── strategies/
│ ├── allTogether.js
│ ├── allTogether.spec.js
│ ├── bySpecies.js
│ ├── bySpecies.spec.js
│ ├── distribution.js
│ └── distribution.spec.js
└── utils/
├── executeInSeries.js
├── executeInSeries.spec.js
├── wait.js
└── wait.spec.js
================================================
FILE CONTENTS
================================================
================================================
FILE: .babelrc
================================================
{
"env": {
"test": {
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
]
]
}
},
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "usage",
"shippedProposals": true,
"corejs": 3,
"targets": {
"browsers": ["last 2 major versions", "not dead", "not IE 11"]
}
}
]
]
}
================================================
FILE: .eslintignore
================================================
node_modules
dist
package-lock.json
================================================
FILE: .eslintrc.js
================================================
module.exports = {
env: {
node: true,
browser: true,
es2020: true,
},
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},
plugins: ['prettier', 'babel'],
extends: [
'eslint:recommended',
'prettier',
'plugin:prettier/recommended',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:jest/recommended',
'plugin:jest/style',
'plugin:cypress/recommended',
],
rules: {
'prettier/prettier': 'error',
'babel/no-unused-expressions': 'error',
},
overrides: [
{
files: ['cypress/integration/*.spec.js'],
rules: {
'jest/expect-expect': 'off',
},
},
],
};
================================================
FILE: .github/ISSUE_TEMPLATE/bug_report.md
================================================
---
name: '🐛 Bug Report'
about: Bugs, missing documentation, or unexpected behavior 🤔.
title: 'Bug: '
---
- `gremlins.js` version:
- `node` version:
- `npm` (or `yarn`) version:
- browser version:
## Steps To Reproduce
1. 2.
Link to code example:
## The current behavior
## The expected behavior
### Suggested solution:
================================================
FILE: .github/ISSUE_TEMPLATE/config.yml
================================================
blank_issues_enabled: false
contact_links:
- name: 📝 Code of Conduct
url: https://github.com/marmelab/gremlins.js/blob/master/CODE_OF_CONDUCT.md
about: ❤ Be nice to other members of the community. ☮ Behave.
================================================
FILE: .github/ISSUE_TEMPLATE/feature_request.md
================================================
---
name: 💡 Feature Request
about: I have a suggestion (and might want to implement myself 🙂)!
---
### Describe the feature you'd like:
### Suggested implementation:
### Describe alternatives you've considered:
### Teachability, Documentation, Adoption, Migration Strategy:
================================================
FILE: .github/ISSUE_TEMPLATE/question.md
================================================
---
name: ❓ Question
about: Ask a question not related to implementation here
label: question
---
🚨 The issue tracker is not for implementation questions 🚨
================================================
FILE: .github/ISSUE_TEMPLATE.md
================================================
👉 Please follow one of these issue templates:
- https://github.com/marmelab/gremlins.js/issues/new/choose
Note: to keep the backlog clean and actionable, issues may be immediately closed if they do not follow one of the above issue templates.
================================================
FILE: .github/PULL_REQUEST_TEMPLATE.md
================================================
**What**:
**Why**:
**How**:
**Checklist**:
- [ ] Documentation added to the README.md file
- [ ] Tests
- [ ] Typescript definitions updated
- [ ] RFR, Ready for review label
================================================
FILE: .gitignore
================================================
dist
node_modules
npm-debug.log
cypress/screenshots
================================================
FILE: .npmrc
================================================
registry=https://registry.npmjs.org/
================================================
FILE: .prettierignore
================================================
node_modules
dist
package-lock.json
================================================
FILE: .prettierrc
================================================
{
"tabWidth": 4,
"singleQuote": true,
"printWidth": 120
}
================================================
FILE: .travis.yml
================================================
language: node_js
node_js:
- node # Current stable
- lts/* # Most recent LTS version
install:
- npm ci
script:
- npm run test
- npm run cypress:run
branches:
only:
- master
- next
================================================
FILE: CHANGELOG.md
================================================
# Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
## [2.2.0](https://github.com/marmelab/gremlins.js/compare/v2.1.1...v2.2.0) (2020-07-21)
### Features
- add formFiller cypress test ([e278b5b](https://github.com/marmelab/gremlins.js/commit/e278b5bf10eec1ed7e71cae0dc7a641e7971540f))
- allow to pass a custom window to gremlins ([9a2084c](https://github.com/marmelab/gremlins.js/commit/9a2084c668f68be3285633e987889839dab190da))
- bump standard-version to 8.0.2 ([ed60ec6](https://github.com/marmelab/gremlins.js/commit/ed60ec6b0f1a498479c2eb29205eaaa81a2c5341))
- update readme with cypress usage ([005373e](https://github.com/marmelab/gremlins.js/commit/005373efd3cd52427b7220b3c3befe5a3d08053b))
### Bug Fixes
- bad practice in readme ([d0528ab](https://github.com/marmelab/gremlins.js/commit/d0528ab60b1887c55a5226cf7a6d95b121fdf942))
- cypress plugins ([8ec3047](https://github.com/marmelab/gremlins.js/commit/8ec304755a3a8d1ae3d86da688c81b658d8158d3))
- linter conf ([22ca500](https://github.com/marmelab/gremlins.js/commit/22ca500d1d0d82e01ada08a800fbea37bc40d6d8))
- pass window to gremlins ([9898e41](https://github.com/marmelab/gremlins.js/commit/9898e41d53fe82a4b26145757816e07a754d7da5))
- remove useless command in package.json ([c7f3243](https://github.com/marmelab/gremlins.js/commit/c7f3243ee04d49c14efcabc9078c76e82e18ad16))
- remove useless fixture ([1166503](https://github.com/marmelab/gremlins.js/commit/11665031ef341d4bee9c5208604c7334bd27c3de))
- remove useless make command ([b00e703](https://github.com/marmelab/gremlins.js/commit/b00e703c74f3659246af627adf6476993fc92f70))
### [2.1.1](https://github.com/marmelab/gremlins.js/compare/v2.1.0...v2.1.1) (2020-04-27)
### Bug Fixes
- add hmtl prototype for numbers elements ([e415936](https://github.com/marmelab/gremlins.js/commit/e4159365515fb1068e6f0a98e4c008e79d7e6653))
## [2.1.0](https://github.com/marmelab/gremlins.js/compare/v2.0.1...v2.1.0) (2020-04-22)
### Features
- make scroll signal unclickable ([e526549](https://github.com/marmelab/gremlins.js/commit/e52654911dc2c3d7b6d8adb134ba916a6937a938))
### Bug Fixes
- chance RangeError ([3856336](https://github.com/marmelab/gremlins.js/commit/38563366603c39a759a5df6c04195ffb5217738a))
### [2.0.1](https://github.com/marmelab/gremlins.js/compare/v2.0.0...v2.0.1) (2020-04-08)
## [2.0.0](https://github.com/marmelab/gremlins.js/compare/v2.0.0-next.2...v2.0.0) (2020-04-08)
### Features
- add customisable bookmarklet ([96db4be](https://github.com/marmelab/gremlins.js/commit/96db4be3608068a0ff56390859d6c2e0c54dce10))
- add guide, issue, bug template ([16016df](https://github.com/marmelab/gremlins.js/commit/16016df1219aab461d0a79d2e9fc3059ae286212))
- expose gremlins in bookmarklet page ([a03d429](https://github.com/marmelab/gremlins.js/commit/a03d429ad95e87f45889aa2bd0f1db1fc44aef86))
- refaco executeInSeries function ([aa03316](https://github.com/marmelab/gremlins.js/commit/aa03316df05419bfa811cda3d4800570dce6ac5b))
- update babel and rolup dep ([d6b439b](https://github.com/marmelab/gremlins.js/commit/d6b439b8637d8057673cd61c7b21b091dc8b4fa1))
- update readme ([ae11c93](https://github.com/marmelab/gremlins.js/commit/ae11c937f7f3bc92aff61644dca60998df971ca1))
- update seed, stop and custom logger documentation ([13c9920](https://github.com/marmelab/gremlins.js/commit/13c99203cf2712248ffceb4cde80d705096c1787))
- update to prettier 2.0 and eslint last version ([af374d4](https://github.com/marmelab/gremlins.js/commit/af374d4a5dd5789eacec5d543f6d0fe7ec335e62))
### Bug Fixes
- change next to master branch ([f66ffeb](https://github.com/marmelab/gremlins.js/commit/f66ffebc20715c386b087f88c35b75e4b0112cf3))
- illegal invocation on text area ([a877e46](https://github.com/marmelab/gremlins.js/commit/a877e46245292fa068eb209ed69f6a1f88d5b337))
- simulated on change usage ([24ea017](https://github.com/marmelab/gremlins.js/commit/24ea017b0b20e00403adace3caf17df1ea4b416a))
- toucher log test ([c7f2abd](https://github.com/marmelab/gremlins.js/commit/c7f2abdbc7c8a870241144d34675de4fa4d7a61f))
- typo in readme ([9cbb8e5](https://github.com/marmelab/gremlins.js/commit/9cbb8e553047739e7ff8b77f5f3ce20804afb144))
- update babel to fix test on node 13.10.1 ([ffc6542](https://github.com/marmelab/gremlins.js/commit/ffc654235c577d54e69bfbbc02b2b55242525a52))
- use fake timers usage ([c404ed8](https://github.com/marmelab/gremlins.js/commit/c404ed81941d361e6fb1845573054336f10a1462))
## [2.0.0-next.2](https://github.com/marmelab/gremlins.js/compare/v2.0.0-next.1...v2.0.0-next.2) (2020-02-26)
### Features
- add bookmarklet.html file ([96b26a0](https://github.com/marmelab/gremlins.js/commit/96b26a080605d42149afa669447523ff774b5b1a))
- deploy to gh-pages ([2399363](https://github.com/marmelab/gremlins.js/commit/2399363ac114037a5292d520eeb55e5883cdaaeb))
### Bug Fixes
- custom config, logger & exceptions ([fc1ca4b](https://github.com/marmelab/gremlins.js/commit/fc1ca4b7728227f463a4c49706c66f237df24c88))
## [2.0.0-next.1](https://github.com/marmelab/gremlins.js/compare/v2.0.0-next...v2.0.0-next.1) (2020-02-26)
### Features
- add standard-version package ([137eb96](https://github.com/marmelab/gremlins.js/commit/137eb96e4f635fb6f5a1bc348dce430dfa31c990))
- change bundle name to gremlins and fix strategies stop ([6203ed4](https://github.com/marmelab/gremlins.js/commit/6203ed4f34040247672f1e436b19278c84759ecb))
- clean up code and use object for config ([a12e779](https://github.com/marmelab/gremlins.js/commit/a12e77983d19f8951261a5dd9e694ae75943694e))
- migrate form filler ([f9a7698](https://github.com/marmelab/gremlins.js/commit/f9a7698c88ead3f9b908e57e58f1e45bb2b8a999))
- migrate mogwais and delete configurable ([e87de74](https://github.com/marmelab/gremlins.js/commit/e87de74608510a9b8b5c96a3e50ffe6d0fdc9686))
- migrate scroller ([72ee515](https://github.com/marmelab/gremlins.js/commit/72ee515ed25a7694c6b9a5d79a67b7ac39619da4))
- migrate strategies ([b300076](https://github.com/marmelab/gremlins.js/commit/b3000764f5acf6623e969944152db640868220aa))
- migrate toucher ([bbec05c](https://github.com/marmelab/gremlins.js/commit/bbec05c221599d9dbf15628b465f27df45f38c7d))
- migrate typer ([50eaa3b](https://github.com/marmelab/gremlins.js/commit/50eaa3b54f3f3763234f153d31aefb5fc0c3886d))
- use object config ([7876644](https://github.com/marmelab/gremlins.js/commit/7876644f5d4cac10b4803d6c4c94177b47efe08d))
### Bug Fixes
- const names ([7d57872](https://github.com/marmelab/gremlins.js/commit/7d578723c447fccc6bd31776601ac407dc73c352))
- remove unused parameter from executeInSeries ([a85a9bf](https://github.com/marmelab/gremlins.js/commit/a85a9bf75897f8e3c690981ae19e459b9130de30))
## [2.0.0-next.0](https://github.com/marmelab/gremlins.js/compare/v2.0.0-next...v2.0.0-next.0) (2020-02-26)
### Features
- add standard-version package ([137eb96](https://github.com/marmelab/gremlins.js/commit/137eb96e4f635fb6f5a1bc348dce430dfa31c990))
## [2.0.0-next](https://github.com/marmelab/gremlins.js/compare/v0.1.0...v2.0.0-next) (2020-02-26)
### Features
- add commitlint convention ([b1e7d03](https://github.com/marmelab/gremlins.js/commit/b1e7d03aae45de6aa37c26e00fed59bd39600218))
- add sourcemap on production build ([275a296](https://github.com/marmelab/gremlins.js/commit/275a2961283ac0adafc45a662cfdc1886696f7ac))
- add travis CI ([1d5fc5e](https://github.com/marmelab/gremlins.js/commit/1d5fc5ece866fa1373ca224dde0a431221ba271c))
- bootstrap rollup ([677ba03](https://github.com/marmelab/gremlins.js/commit/677ba0318708da2780a1288124dc2d424f5130f1))
- bootstrap test with jest ([13398a6](https://github.com/marmelab/gremlins.js/commit/13398a680774e2035d1b9757f24f3999a96ae278))
- eslint update dep ([ab83723](https://github.com/marmelab/gremlins.js/commit/ab83723d82bcf423afd06a1f9294ad782a234b52))
- update babel, webpack and chance dep ([69b6567](https://github.com/marmelab/gremlins.js/commit/69b6567e4292e9cad2e8614fa7b26d10d58d680b))
# Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
================================================
FILE: CODE_OF_CONDUCT.md
================================================
# Contributor Covenant Code of Conduct
## Our Pledge
We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, religion, or sexual identity
and orientation.
We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.
## Our Standards
Examples of behavior that contributes to a positive environment for our
community include:
- Demonstrating empathy and kindness toward other people
- Being respectful of differing opinions, viewpoints, and experiences
- Giving and gracefully accepting constructive feedback
- Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
- Focusing on what is best not just for us as individuals, but for the
overall community
Examples of unacceptable behavior include:
- The use of sexualized language or imagery, and sexual attention or
advances of any kind
- Trolling, insulting or derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or email
address, without their explicit permission
- Other conduct which could reasonably be considered inappropriate in a
professional setting
## Enforcement Responsibilities
Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.
Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.
## Scope
This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
[INSERT CONTACT METHOD].
All complaints will be reviewed and investigated promptly and fairly.
All community leaders are obligated to respect the privacy and security of the
reporter of any incident.
## Enforcement Guidelines
Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:
### 1. Correction
**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.
**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.
### 2. Warning
**Community Impact**: A violation through a single incident or series
of actions.
**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or
permanent ban.
### 3. Temporary Ban
**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.
**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.
### 4. Permanent Ban
**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.
**Consequence**: A permanent ban from any sort of public interaction within
the community.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.0, available at
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
Community Impact Guidelines were inspired by [Mozilla's code of conduct
enforcement ladder](https://github.com/mozilla/diversity).
[homepage]: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at
https://www.contributor-covenant.org/translations.
================================================
FILE: CONTRIBUTING.md
================================================
# Contribution
Yeay! You want to contribute to gremlins.js. That's amazing!
To smoothen everyone's experience involved with the project please take note of the following guidelines and rules.
## Found an Issue?
Thank you for reporting any issues you find. We do our best to test and make gremlins.js as solid as possible, but any reported issue is a real help.
Please follow these guidelines when reporting issues:
- Tag your issue with the tag `bug`
- Provide a short summary of what you are trying to do
- Provide the log of the encountered error if applicable
- Provide the exact version of gremlins.js. Check `npm ls gremlins.js` when in doubt
- Be awesome and consider contributing a [pull request](#want-to-contribute)
## Want to contribute?
You consider contributing changes to gremlins.js – we dig that!
Please consider these guidelines when filing a pull request:
- Follow the [Coding Rules](#coding-rules)
- Follow the [Commit Rules](#commit-rules)
- Make sure you rebased the current master branch when filing the pull request
- Squash your commits when filing the pull request
- Provide a short title with a maximum of 100 characters
- Provide a more detailed description containing
_ What you want to achieve
_ What you changed
_ What you added
_ What you removed
## Coding Rules
To keep the code base of gremlins.js neat and tidy the following rules apply to every change
- `eslint` and `prettier` is king, use `make lint` and `make format`
- Be awesome
## Commit Rules
To help everyone with understanding the commit history of gremlins.js the following commit rules are enforced. We follow the [conventional commit messages](https://www.conventionalcommits.org/en/v1.0.0/) convention in order to automate CHANGELOG generation and to automate semantic versioning.
For example:
- `feat: A new feature`
- `fix: A bug fix`
Commits types such as as `docs:`,`style:`,`refactor:`,`perf:`,`test:` and `chore:` are valid but have no effect on versioning. **It would be great if you use them.**
All commits message are going to be validated when they are created using husky hooks.
**PRs that do not follow the commit message guidelines will not be merged.**
================================================
FILE: LICENSE
================================================
Copyright (c) 2014 marmelab
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.
================================================
FILE: Makefile
================================================
help:
@grep -P '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
install: ## Install dependencies
npm install
start: ## Rollup watch the project
npm run start
build: clear ## Rollup build the project
npm run build
clear: ## Clear dist directory
npm run clear
test: ## Run whole tests
npm run test
test-cypress: ## Run cypress tests
npm run cypress:run
test-watch: ## Watch whole test suites
npm run test:watch
lint: ## lint the code and check coding conventions
echo "Running linter..."
npm run lint
format: ## prettify the source code using prettier
echo "Running prettier..."
npm run format
serve: build ## Serve dist directory
npm run serve
publish: ## Publish
npm run release
publish-dry-run: ## Publish dry-run
npm run release -- --dry-run
publish-next: ## Publish on next tag
npm run release -- --prerelease next
deploy-gh-pages: ## Deploy bookmaklet to gh-pages
npm run deploy-gh-pages
================================================
FILE: README.md
================================================
gremlins.js
A monkey testing library written in JavaScript, for Node.js and the browser. Use it to check the robustness of web applications by unleashing a horde of undisciplined gremlins.
> Kate: _What are they, Billy?_
>
> Billy Peltzer: _They're gremlins, Kate, just like Mr. Futterman said._
## Table of Contents
- [Purpose](#purpose)
- [Installation](#installation)
- [Basic Usage](#basic-usage)
- [Advanced Usage](#advanced-usage)
- [Setting Gremlins and Mogwais To Use In A Test](#setting-gremlins-and-mogwais-to-use-in-a-test)
- [Configuring Gremlins](#configuring-gremlins)
- [Seeding The Randomizer](#seeding-the-randomizer)
- [Executing Code Before or After The Attack](#executing-code-before-or-after-the-attack)
- [Setting Up a Strategy](#setting-up-a-strategy)
- [Stopping The Attack](#stopping-the-attack)
- [Customizing The Logger](#customizing-the-logger)
- [Cypress](#cypress)
- [Playwright](#playwright)
- [Docs](#docs)
- [Issues](#issues)
- [🐛 Bugs](#-bugs)
- [💡 Feature Requests](#-feature-requests)
- [License](#license)
## Purpose
While developing an HTML5 application, did you anticipate uncommon user interactions? Did you manage to detect and patch all memory leaks? If not, the application may break sooner or later. If n random actions can make an application fail, it's better to acknowledge it during testing, rather than letting users discover it.
Gremlins.js simulates random user actions: gremlins click anywhere in the window, enter random data in forms, or move the mouse over elements that don't expect it. Their goal: triggering JavaScript errors, or making the application fail. If gremlins can't break an application, congrats! The application is robust enough to be released to real users.
This practice, also known as [Monkey testing](http://en.wikipedia.org/wiki/Monkey_test) or [Fuzz testing](http://en.wikipedia.org/wiki/Fuzz_testing), is very common in mobile application development (see for instance the [Android Monkey program](http://developer.android.com/tools/help/monkey.html)). Now that frontend (MV\*, d3.js, Backbone.js, Angular.js, etc.) and backend (Node.js) development use persistent JavaScript applications, this technique becomes valuable for web applications.
## Installation
This module is distributed via [npm](https://www.npmjs.com/) which is bundled with [node](https://nodejs.org/en/) and should be installed as one of your project's `dependencies`:
```
npm i gremlins.js
```
This library has `dependencies` listings for `chance`.
`gremlins.js` is also available as a **bookmarklet**. Go to [this page](https://marmelab.com/gremlins.js/), grab it, and unleash hordes on any web page.
## Basic Usage
A gremlins _horde_ is an army of specialized gremlins ready to mess up your application. _unleash_ the gremlins to start the stress test:
```js
const horde = gremlins.createHorde();
horde.unleash();
// gremlins will act randomly, at 10 ms interval, 1000 times
```
`gremlins.js` provides several gremlin _species_: some click everywhere on the page, others enter data in form inputs, others scroll the window in every possible direction, etc.
You will see traces of the gremlins actions on the screen (they leave red traces) and in the console log:
```
gremlin formFiller input 5 in
gremlin formFiller input pzdoyzshh0k9@o8cpskdb73nmi.r7r in
gremlin clicker click at 1219 301
gremlin scroller scroll to 100 25
...
```
A horde also contains _mogwais_, which are harmless gremlins (or, you could say that gremlins are harmful mogwais). Mogwais only monitor the activity of the application and record it on the logger. For instance, the "fps" mogwai monitors the number of frame per second, every 500ms:
```
mogwai fps 33.21
mogwai fps 59.45
mogwai fps 12.67
...
```
Mogwais also report when gremlins break the application. For instance, if the number of frames per seconds drops below 10, the fps mogwai will log an error:
```
mogwai fps 12.67
mogwai fps 23.56
err > mogwai fps 7.54 < err
mogwai fps 15.76
...
```
After 10 errors, a special mogwai stops the test. He's called _Gizmo_, and he prevents gremlins from breaking applications bad. After all, once gremlins have found the first 10 errors, you already know what you have to do to make your application more robust.
If not stopped by Gizmo, the default horde stops after roughly 1 minute. You can increase the number of gremlins actions to make the attack last longer:
```js
const horde = gremlins.createHorde({
strategies: [gremlins.strategies.allTogether({ nb: 10000 })],
});
horde.unleash();
// gremlins will attack at 10 ms interval, 10,000 times
```
Gremlins, just like mogwais, are simple JavaScript functions. If `gremlins.js` doesn't provide the gremlin that can break your application, it's very easy to develop it:
```js
// Create a new custom gremlin to blur an input randomly selected
function customGremlin({ logger, randomizer, window }) {
// Code executed once at initialization
logger.log('Input blur gremlin initialized');
// Return a function that will be executed at each attack
return function attack() {
var inputs = document.querySelectorAll('input');
var element = randomizer.pick(element);
element.blur();
window.alert('attack done');
};
}
// Add it to your horde
const horde = gremlins.createHorde({
species: [customGremlin],
});
```
Everything in `gremlins.js` is configurable ; you will find it very easy to extend and adapt to you use cases.
## Advanced Usage
### Setting Gremlins and Mogwais To Use In A Test
By default, all gremlins and mogwais species are added to the horde.
You can also choose to add only the gremlins species you want, using a custom configuration object:
```js
gremlins
.createHorde({
species: [
gremlins.species.formFiller(),
gremlins.species.clicker({
clickTypes: ['click'],
}),
gremlins.species.toucher(),
],
})
.unleash();
```
If you just want to add your own gremlins in addition to the default ones, use the `allSpecies` constant:
```js
gremlins
.createHorde({
species: [...gremlins.allSpecies, customGremlin],
})
.unleash();
```
To add just the mogwais you want, use the `mogwai` configuration and `allMogwais()` constant the same way.
`gremlins.js` currently provides a few gremlins and mogwais:
- [clickerGremlin](src/species/clicker.js) clicks anywhere on the visible area of the document
- [toucherGremlin](src/species/toucher.js) touches anywhere on the visible area of the document
- [formFillerGremlin](src/species/formFiller.js) fills forms by entering data, selecting options, clicking checkboxes, etc
- [scrollerGremlin](src/species/scroller.js) scrolls the viewport to reveal another part of the document
- [typerGremlin](src/species/typer.js) types keys on the keyboard
- [alertMogwai](src/mogwais/alert.js) prevents calls to alert() from blocking the test
- [fpsMogwai](src/mogwais/fps.js) logs the number of frames per seconds (FPS) of the browser
- [gizmoMogwai](src/mogwais/gizmo.js) can stop the gremlins when they go too far
### Configuring Gremlins
All the gremlins and mogwais provided by `gremlins.js` are _configurable_, i.e. you can alter the way they work by injecting a custom configuration.
For instance, the clicker gremlin is a function that take an object as custom configuration:
```js
const customClicker = gremlins.species.clicker({
// which mouse event types will be triggered
clickTypes: ['click'],
// Click only if parent is has class test-class
canClick: (element) => element.parentElement.className === 'test-class',
// by default, the clicker gremlin shows its action by a red circle
// overriding showAction() with an empty function makes the gremlin action invisible
showAction: (x, y) => {},
});
gremlins.createHorde({
species: [customClicker],
});
```
Each particular gremlin or mogwai has its own customization methods, check the source for details.
### Seeding The Randomizer
If you want the attack to be repeatable, you need to seed the random number generator :
```js
// seed the randomizer
horde.createHorde({
randomizer: new gremlins.Chance(1234);
});
```
### Executing Code Before or After The Attack
Before starting the attack, you may want to execute custom code. This is especially useful to:
- Start a profiler
- Disable some features to better target the test
- Bootstrap the application
Fortunately, `unleashHorde` is a Promise. So if you want to execute code before and after the unleash just do:
```js
const horde = gremlins.createHorde();
console.profile('gremlins');
horde.unleash().then(() => {
console.profileEnd();
});
```
### Setting Up a Strategy
By default, gremlins will attack in random order, in a uniform distribution, separated by a delay of 10ms. This attack strategy is called the [distribution](src/strategies/distribution.js) strategy. You can customize it using the strategies custom object:
```js
const distributionStrategy = gremlins.strategies.distribution({
distribution: [0.3, 0.3, 0.3, 0.1], // the first three gremlins have more chances to be executed than the last
delay: 50, // wait 50 ms between each action
});
```
Note that if using default gremlins, there are [five type of gremlins](https://github.com/marmelab/gremlins.js/blob/master/src/index.js#L52). The previous example would give a 0 value to last gremlin specie.
You can also use another strategy. A strategy is just a function expecting one parameter: an array of gremlins. Two other strategies are bundled ([allTogether](src/strategies/allTogether.js) and [bySpecies](src/strategies/bySpecies.js)), and it should be fairly easy to implement a custom strategy for more sophisticated attack scenarios.
### Stopping The Attack
The horde can stop the attack in case of emergency using the `horde.stop()` method Gizmo uses this method to prevent further damages to the application after 10 errors, and you can use it, too, if you don't want the attack to continue.
### Customizing The Logger
By default, gremlins.js logs all gremlin actions and mogwai observations in the console. If you prefer using an alternative logging method (for instance, storing gremlins activity in LocalStorage and sending it in Ajax once every 10 seconds), just provide a logger object with 4 methods (log, info, warn, and error) to the `logger()` method:
```js
const customLogger = {
log: function (msg) {
/* .. */
},
info: function (msg) {
/* .. */
},
warn: function (msg) {
/* .. */
},
error: function (msg) {
/* .. */
},
};
horde.createHorde({ logger: customLogger });
```
### Cypress
To run gremlins.js inside a cypress test, you need to provide the tested window:
```js
import { createHorde } from 'gremlins.js';
describe('Run gremlins.js inside a cypress test', () => {
let horde;
beforeEach(() =>
cy.window().then((testedWindow) => {
horde = createHorde({ window: testedWindow });
})
);
it('should run gremlins.js', () => {
return cy.wrap(horde.unleash()).then(() => {
/* ... */
});
});
});
```
### Playwright
To run gremlin.js with Playwright, you can load it as an init script.
```js
const { test } = require('@playwright/test');
test('run gremlins.js', async ({ page }) => {
await page.addInitScript({
path: './node_modules/gremlins.js/dist/gremlins.min.js',
});
await page.goto('https://playwright.dev');
await page.evaluate(() => gremlins.createHorde().unleash());
});
```
## Docs
### Issues
_Looking to contribute? Look for the [Good First Issue](https://github.com/marmelab/gremlins.js/issues?q=is%3aissue+is%3aopen+sort%3areactions-%2b1-desc)
label._
### 🐛 Bugs
Please file an issue for bugs, missing documentation, or unexpected behavior.
[**See Bugs**](https://github.com/marmelab/gremlins.js/issues?q=is%3aissue+is%3aopen+label%3abug+sort%3acreated-desc)
### 💡 Feature Requests
Please file an issue to suggest new features. Vote on feature requests by adding
a 👍. This helps maintainers prioritize what to work on.
[**See Feature Requests**](https://github.com/marmelab/gremlins.js/issues?q=is%3aissue+sort%3areactions-%2b1-desc+label%3aenhancement+is%3aopen)
## License
gremlins.js is licensed under the [MIT Licence](LICENSE), courtesy of [marmelab](http://marmelab.com).
================================================
FILE: bookmarklet/index.css
================================================
body {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 20px;
}
.bookmarklet {
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
}
.form {
display: flex;
justify-content: space-between;
margin-bottom: 20px;
width: 100%;
}
.bookmarklet-container {
display: flex;
flex-direction: column;
align-items: center;
}
.code-container {
background-color: antiquewhite;
}
.code {
white-space: pre-wrap;
color: darkslategrey;
}
.code-title {
text-align: center;
}
================================================
FILE: bookmarklet/index.html
================================================
Gremlins.js Bookmarklet
Drag and drop the link below to your bookmarks toolbar