@s-ui/test

8.34.0 • Public • Published

sui-test

Zero config testing tool

Motivation

(1) Setup properly a testing environment in JavaScript is hard. There is a lot deps and it would be easy to install different setups in different projects. To avoid that, you could run this test suit over your code to install only one tool.

Folder Structure

Your tests must be in a test folder in your project root. Each test file should follow the patter: *Spec.js.

.
├── package.json <- Project package.json
└── src
│   ├── detail.js
│   └── user.js
└── test
    ├── detail
    │   └── detailSpec.js
    └── user
        └── userSpec.js

Installation

npm install @s-ui/test --save-dev

CLI Options

  Usage: sui-test [options] [command]


  Options:

        --version  output the version number
    -h, --help     output usage information


  Commands:

    browser|b   Run tests in the browser
    server|s    Run tests in node
    help [cmd]  display help for [cmd]

Browser options

  Usage: sui-test browser [options]


  Options:

    -H, --headless Run in headless mode
    -W, --watch    Run in watch mode
    -C, --ci       Run a Firefox headless for CI testing (deprecated, use --headless instead)
    -P, --pattern <pattern>               Path pattern to include (default: test/**/*Spec.js)
    -I, --ignore-pattern <ignorePattern>  Path pattern to ignore for testing (default: false)
    --src-pattern <srcPattern>  Define the source directory (default: src/**/*.js)
    -h, --help   output usage information
  Description:

  Run tests in a browser

  Examples:

    $ sui-test browser

Server options

  Usage: sui-test server [options]


    Options:

        -I, --inspect Inspect node process
        -W, --watch  Run in watch mode
        -T, --timeout Customize test timeout
        -P, --pattern <pattern>  Path pattern to include (default: test)
        -h, --help   output usage information
    Description:

    Run tests in node

    Examples:

      $ sui-test server -W

Tools

Describers

describeOnLocal: It will only run wrapped tests on local environment and won't be executed in CI.

import { describeOnLocal } from '@s-ui/test/lib/describers'

describeOnLocal(() => {
  describe('Some test', () => {
    it('should do something', () => {
      expect(true).toBe(true)
    })
  })
})

Descriptor by environment patcher

The descriptor by environment is a patch with the purpose of add some extra functionality to our mocha describe and it methods.

How to import it?

First of all, the patcher MUST BE APPLIED on each test that we want to have the extra methods so at the top of ourExampleSpec.js we will add the next code:

import { descriptorsByEnvironmentPatcher } from '@s-ui/test/lib/descriptor-environment-patcher'
descriptorsByEnvironmentPatcher()

And that's it, from that line you will have the next methods added to the base of the mocha lib:

  • describe.client
  • describe.server
  • describe.client.only
  • describe.server.only
  • it.client
  • it.server
  • it.client.only
  • it.server.only

How can I use it?

Just in the same way as you have been using the describe or it functions earlier:

describe.client('Users use case', () => {
  it('should....', () => {
    // ...
  })
})

describe.server('Users use case', () => {
  it('should....', () => {
    // ...
  })
})

You can also have it() by environment:

describe('Another use case', () => {
  it.client('should....', () => {
    // ...
  })

  it.server('should....', () => {
    // ...
  })
})

What about if you want to run only one describe but only for client? You can use the .only function in the same way as you've been using earlier.

describe.client.only('Another use case', () => {
  it('should....', () => {
    // ...
  })
})

Contributing

Please refer to the main repo contributing info.

Dependents (4)

Package Sidebar

Install

npm i @s-ui/test

Weekly Downloads

3,294

Version

8.34.0

License

MIT

Unpacked Size

49.8 kB

Total Files

24

Last publish

Collaborators

  • daniel.perez.ext
  • albert.peiro
  • frandelacasa-adevinta
  • mariapaula.forero.ext
  • hpintos_adevinta
  • sziauberyte
  • victor.perez.adevinta
  • oscar-raig-adevinta
  • carlos.gonzalezl
  • carolina.mallo.ext
  • david.nieto
  • ferran.simon
  • xavi_conejo
  • sergi.quintela
  • jamile.radloff
  • xavi_ballestar
  • luz_adv
  • ignacio.rodriguez
  • carlosvillu-adevinta
  • diegomr
  • arturo.vicente
  • adria.velardos
  • emiliovz
  • dann41
  • ruben-martin
  • pol.valls
  • cristina.rodriguez.duque
  • sergio.escano
  • marc.benito
  • azahara
  • patricio.sartore
  • giovanny.sayas.ext
  • david.cuadrado.ext
  • alex.castells
  • beatrizip
  • pablo.rey-adevinta
  • sergiocollado
  • mango.sanchezredondo
  • cristhianb
  • alisa_bayanova
  • davidmartin2108
  • ferrangbtw
  • estefania_garcia
  • belen.santos
  • alfredo.arronte
  • joanleon-adv
  • giodelabarrera.adevinta
  • luis-garrido
  • aitor.rodriguez
  • jordi.munoz
  • oscar_ramirez
  • ignacio_navarro
  • a.ferrer
  • gfabregoadv
  • izeller
  • salvador.juan
  • oriol.egea
  • ivanmlaborda
  • alejandro.ferrante
  • pa.chruscinski.ext
  • isabelgomez87
  • jenifer.lopez
  • daniela.aguilera
  • pablogs
  • javier.miguel
  • oscar.gomez
  • marian.lucaci
  • alverd004
  • oriol.puig
  • nacho_torrella
  • xavi.murcia
  • chloe.leteinturier
  • javiauso
  • alfredo.zimperz
  • francisco.ruiz.lloret
  • fermin.adevinta
  • andresadv
  • schibstedspain