Giter Site home page Giter Site logo

schrotie / mocha-headless-chrome Goto Github PK

View Code? Open in Web Editor NEW

This project forked from direct-adv-interfaces/mocha-headless-chrome

0.0 1.0 0.0 152 KB

Run client-side mocha tests in the command line through headless Chrome.

License: MIT License

JavaScript 92.21% HTML 5.20% TypeScript 2.59%

mocha-headless-chrome's Introduction

mocha-headless-chrome

npm license

This is the tool which runs client-side mocha tests in the command line through headless Chrome (puppeteer is used).

Node 14.0.0+ and Mocha 2.3.0+ are supported.

Getting Started

First you need to install mocha-headless-chrome:

npm i mocha-headless-chrome

Then prepare the test page (see the example).

Note. It is necessary to add the <meta charset="utf-8"> tag. Otherwise browser may use another encoding and test results will be shown incorrectly.

Then run the CLI and specify your test page path using -f parameter.

mocha-headless-chrome -f test-page.html

Options

  • -f, --file - Path or URL of the page which contains tests (required)
  • -r, --reporter - Mocha reporter name (defaults to "spec")
  • -o, --out - Path to the file where test result will be saved
  • -c, --coverage - Path to the file where coverage info will be saved
  • -e, --executablePath - Chrome executable path
  • -v, --visible - Show Chrome window
  • -a, --args - Chrome arguments ('--' prefix will be added)
  • -w, --width - Viewport width
  • -H, --height - Viewport height
  • -t, --timeout - Timeout in ms (defaults to 60000)
  • -p, --polling - Puppeteer polling mechanism
  • -h, --help - Output usage information

Examples

Run test on the "test.html" page:

mocha-headless-chrome -f test.html

Run tests on the remote page:

mocha-headless-chrome -f http://localhost:8080

Output test results using "nyan" reporter:

mocha-headless-chrome -f test.html -r nyan

Pass the Chrome --no-sandbox and --disable-setuid-sandbox arguments:

mocha-headless-chrome -f test.html -a no-sandbox -a disable-setuid-sandbox

Mocha reporters

All mocha reporters are supported. Specify the reporter name through -r parameter. All reporter output (include cursor manipulations) will be redirected to stdout as like it works in console.

For usage of third-party reporter just include it's code to the page by <script> tag and specify it's name in the -r parameter.

Also special reporter named "none" is available which does not output anything. This reporter will be useful when you want to process test result without output to console (for example, when saving data to a file).

Programmatically usage

You can use mocha-headless-chrome programmatically. Just require the mocha-headless-chrome node module and pass proper parameters into it. Function result is a Promise.

const {runner} = require('mocha-headless-chrome');

const options = {
    file: 'test.html',                           // test page path
    reporter: 'dot',                             // mocha reporter name
    width: 800,                                  // viewport width
    height: 600,                                 // viewport height
    timeout: 120000,                             // timeout in ms
    polling: 'raf',                              // polling mechanism
    executablePath: '/usr/bin/chrome-unstable',  // chrome executable path
    visible: true,                               // show chrome window
    args: ['no-sandbox']                         // chrome arguments
};

runner(options)
    .then(result => {
        let json = JSON.stringify(result);
        console.log(json);
    });

See also the TypeScript example.

mocha-headless-chrome's People

Contributors

dima117 avatar mishina2228 avatar tildedave avatar drochgenius avatar teknofiend avatar wonseop avatar dependabot[bot] avatar jburgy avatar odidev avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.