lets-test
v2.0.1
Published
configuration for running component, performance and security tests
Downloads
5
Readme
lets-test
It lets you test without doing all the nasty configuration. It has support for running:
- integration tests using WebdriverIO 5
- performance tests using Google Lighthouse
- security tests using ZAP
- SSR tests using Puppeteer
Coming soon:
- tool for mocking api
- visual regression tests
Installation
npm i lets-test --save-dev
How to run wdio tests
WebdriverIO is configured to run with Mocha and Jest Expect.
- After installing the package, create the following folder structure for your *.spec.js test files.
test/ -- wdio/ -- -- *.spec.js
- For running your tests use:
- to run tests in mobile, tablet and desktop using headless
npx lets-run-wdio
- to run on mobile only use DEVICE, it can be "mobile", "tablet" or "desktop"
DEVICE=mobile npx lets-run-wdio
- if you don't what to run headless use NOT_HEADLESS
NOT_HEADLESS=true npx lets-run-wdio
How to run performance tests
- After installing the package, create the following folder structure.
test/ -- lighthouse/
- Inside test/lighthouse/ you need to create an urls.json file, this will tell lighthouse what URLs to test and what values to expect.
Here is an example:
As you can see, "urls" it's an array so you can specify multiple URLs to be tested.{ "urls": [ { "name": "The name of the page (for the report)", "url": "http://localhost:8080", "optimal": { "mobile": { "speedIndex": 3500, "firstMeaningfulPaint": 3800, "domSize": 1500, "estimatedInputLatency": 2400, "totalByteWeight": 1638400, "criticalRequestChains": 2 }, "tablet": { "speedIndex": 3700, "firstMeaningfulPaint": 4200, "domSize": 1500, "estimatedInputLatency": 4800, "totalByteWeight": 1638400, "criticalRequestChains": 2 }, "desktop": { "speedIndex": 2400, "firstMeaningfulPaint": 4400, "domSize": 1500, "estimatedInputLatency": 2400, "totalByteWeight": 1638400, "criticalRequestChains": 2 } } } ] }
Feel free to set your optimal values (speedIndex, domSize...) as you consider best for your application. - For running your tests use:
DEVICE can be "mobile", "tablet" or "desktop"DEVICE=mobile npx lets-run-lighthouse
How to run security tests
- After installing the package, create the following folder structure.
test/ -- zap/
- Inside test/zap/ you need to create an alerts.json file, this will tell zap how many "high", "medium" and "low" alerts you expect to have on each device (mobile, tablet and desktop).
Here is an example:{ "mobile": { "high": 0, "medium": 1, "low": 2 }, "tablet": { "high": 0, "medium": 1, "low": 2 }, "desktop": { "high": 0, "medium": 1, "low": 2 } }
- Generate the ZAP report:
- first you need to install zap on you machine, just download the Cross Platform Package. This runs with JAVA so make sure you also have JAVA installed.
- to simplify the command line it's best to create an env variable in you system that points to the ZAP installation folder something like: $ZAP_PATH
- now go to your project root and run ZAP like this: (replace localhost:8080 with your application homepage)
java -jar $ZAP_PATH/zap-2.7.0.jar -cmd -installdir $ZAP_PATH -quickurl http://localhost:8080 -quickout $PWD/zap-report.xml
- So step 3 will generate a zap-report.xml file in the root of you project.
To see if the zap report contains the same number of alerts that you expect, hopefully 0, run:
DEVICE can be "mobile", "tablet" or "desktop"DEVICE=mobile npx lets-run-zap
How to run SSR (Server side rendering) tests
- After installing the package, create the following folder structure.
test/ -- ssr/
- Inside test/ssr/ you need to create an urls.json file, this will tell our script what URLs to test.
Here is an example:
As you can see, "urls" it's an array so you can specify multiple URLs to be tested.{ "urls": [ { "name": "The name of the page (for the report)", "url": "http://localhost:8080" } ] }
- To run the tests use:
DEVICE can be "mobile", "tablet" or "desktop"DEVICE=mobile npx lets-run-ssr