lets-test

2.0.1 • Public • Published

lets-test

It lets you test without doing all the nasty configuration. It has support for running:

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.

  1. After installing the package, create the following folder structure for your *.spec.js test files.
    test/
    -- wdio/
    -- -- *.spec.js
  2. 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

  1. After installing the package, create the following folder structure.
    test/
    -- lighthouse/
  2. 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:
    {
      "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
            }
          }
        }
      ]
    }
    As you can see, "urls" it's an array so you can specify multiple URLs to be tested.
    Feel free to set your optimal values (speedIndex, domSize...) as you consider best for your application.
  3. For running your tests use:
    DEVICE=mobile npx lets-run-lighthouse
    DEVICE can be "mobile", "tablet" or "desktop"

How to run security tests

  1. After installing the package, create the following folder structure.
    test/
    -- zap/
  2. 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
      }
    }
  3. 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
  4. 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=mobile npx lets-run-zap
    DEVICE can be "mobile", "tablet" or "desktop"

How to run SSR (Server side rendering) tests

  1. After installing the package, create the following folder structure.
    test/
    -- ssr/
  2. Inside test/ssr/ you need to create an urls.json file, this will tell our script what URLs to test.
    Here is an example:
    {
      "urls": [
        {
          "name": "The name of the page (for the report)",
          "url": "http://localhost:8080"
        }
      ]
    }
    As you can see, "urls" it's an array so you can specify multiple URLs to be tested.
  3. To run the tests use:
    DEVICE=mobile npx lets-run-ssr
    DEVICE can be "mobile", "tablet" or "desktop"

Readme

Keywords

none

Package Sidebar

Install

npm i lets-test

Weekly Downloads

1

Version

2.0.1

License

ISC

Unpacked Size

34.4 kB

Total Files

20

Last publish

Collaborators

  • ctmihai