gemini-core
Utility which contains common modules for gemini and hermione
Last updated 19 days ago by dudagod .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install gemini-core 
SYNC missed versions from official npm registry.

gemini-core

Build Status

Utility which contains common modules for gemini and hermione.

Table of Contents

SetsBuilder

Creates mapping of test files with browsers in which they should be run and vice versa.

Example of usage:

const SetsBuilder = require('gemini-core').SetsBuilder;
const sets = {
    desktop: {
        files: ['desktop/tests/**.js'],
        ignoreFiles: ['desktop/tests/fixtures/**'], // exclude directories from reading while test finding
        browsers: ['bro1'],
    },
    touch-phone: {
        files: ['touch-phone/tests'],
        browsers: ['bro2']
    }
};

SetsBuilder
    .create(sets, {defaultDir: 'default/path'}) // creates setsBuilder using specified tests and options
    .useSets(['desktop'])                       // use only the specified sets
    .useBrowsers(['bro1'])                      // use only specified browsers
    .useFiles(['desktop/tests/test.js'])        // use only specified files if sets
                                                // and files to use are not specified
    .build('/root', globOpts, ['.js', '.ts'])   // builds a collection of sets with paths expanded according
                                                // to the project root, glob options and file extensions
    .then((setCollection) => {
        setCollection.groupByFile();    // groups all browsers of test-sets by file:
                                        // {'desktop/tests/test.js': ['bro1']}
        setCollection.groupByBrowser(); // groups all files of test-sets by browser:
                                        // {'bro': ['desktop/tests/test.js']}
    })
    .done();

Options

Returns an object with some options.

const options = require('gemini-core').config.options;

Sets

const sets = options.sets; // returns a section for configparser with two options – files and browsers.
                           // Default value is an empty set - all: {files: []}

BrowserPool

Example:

const BrowserPool = require('gemini-core').BrowserPool;

// Some browser realization
class Browser {
    constructor(id) {
        this.id = 'bro'; // required field
        this.sessionId = null; // required field
    }

    launch() {
        return doLaunch()
            .then((sessionId) => this.sessionId = sessionId);
    }

    // required method
    reset() {
        return doSomeReset();
    }

    quit() {
        return doQuit();
    }
}

const BrowserManager = {
    create: (id) => new Browser(id),

    start: (browser) => browser.launch(),
    onStart: (browser) => emitter.emitAndWait('sessionStart', browser),

    onQuit: (browser) => emitter.emitAndWait('sessionEnd', browser),
    quit: (browser) => browser.quit()
};

const config = {
    forBrowser: (id) => {
        return {
            parallelLimit: 1, // maximum number of specific browser sessions executed in parallel
            sessionUseLimit: 2 // maxiumu number of session reuse (test per session, for example)
        };
    },

    getBrowserIds: () => config.getBrowserIds(),

    system: {
        parallelLimit: 10 // maximum number of browser sessions at all
    }
};

const pool = BrowserPool.create(BrowserManager, {
    logNamespace: 'gemini', // prefix for logger. log = require('debug')(`${logNamespace}:pool:...`)
    config
});

return pool.getBrowser('bro'/*, {highPriority: true}*/)
    .then((bro) => {
        ...
        return pool.freeBrowser(bro);
    });

events

AsyncEmitter

Node.js event emitter with promises support.

Node.js builtin EventEmitter class executes all handlers synchronously without waiting for completion of any async operations that may happen inside.

AsyncEmitter is the subclass of EventEmitter which adds ability to return a promise from event handler and wait until it resolved. Just use emitAndWait instead of emit:

const AsyncEmitter = require('gemini-core').events.AsyncEmitter;
const emitter = new AsyncEmitter();
emitter.on('event', function() {
    return Promise.delay(1000);
});

emitter.emitAndWait('event')
    .then(function() {
        console.log('All handlers finished'); // Would be called after 1 second
    });

emitAndWait returns promise.

utils

passthroughEvent(from, to, event)

Passes event from from to to. event can be an array of events.

promiseUtils

waitForResults(promises)

Waits for all promises in array to be resolved or rejected. If any promise is rejected - rejects with the first rejection error, otherwise resolves.

BrowserAgent

Example:

const BrowserAgent = require('gemini-core').BrowserAgent;
const BrowserPool = require('gemini-core').BrowserPool;
const pool = BrowserPool.create(/*BrowserManager, config*/);
const browserAgent = BrowserAgent.create('bro-id', pool);

return browserAgent.getBrowser(/*{highPriority: true}*/)
    .then((bro) => {
        ...
        return browserAgent.freeBrowser(bro/*, {force: true}*/);
    });

Errors

CancelledError

This error will be thrown on browser pool cancel:

const BrowserPool = require('gemini-core').BrowserPool;
const CancelledError = require('gemini-core').errors.CancelledError;
...
pool.getBrowser('bro')
    .then((bro) => ...)
    .catch((e) => {
        if (e instanceof CancelledError) {
            console.log('cancelled')
        }
    });

pool.cancel();

Image

API for working with images.

const {Image} = require('gemini-core');
const imgBuffer = new Buffer('someBufferString', 'base64');
const image = new Image(imgBuffer);

const imageSize = image.getSize();

Methods

crop

Crop image to the passed sizes depending on scale factor. Modifies current image. Returns Promise with image instance.

const image = new Image(imgBuffer);
const cropArea = {
    top: 10,
    left: 10,
    width: 100,
    height: 100
};

image.crop(cropArea, 2); // will crop double sized image i.e width=200, heigth=200 etc.
getSize

Returns object with current image size e.g. {width: 100, height: 100}

getRGBA

Returns RGBA color of the passed image pixel in row. Takes pixel number in row as first argument and row nomber as second. Returns object with color.

const image = new Image(imgBuffer);

const color = image.getRGBA(1, 2); // {r: 255, g: 0, b: 0, a:255}
save

Save image to the passed path. Asynchronous operation. Returns Promise with current image instance.

clear

Fill image area with black color depending on scale factor.

const image = new Image(imgBuffer);
const clearArea = {
    top: 10,
    left: 10,
    width: 100,
    height: 100
};

image.clear(clearArea, {scaleFactor: 1});
join

Append another image to current. Modifies current image.

const image1 = new Image(imgBuffer);
const image2 = new Image(imgBuffer);

image1.join(image2);

Static methods

fromBase64

Returns new Image instance from base64 hash.

RGBToString

Convert object-like RGB color to string.

const color = Image.RGBToString({r: 255, g: 0, b: 0}); // returns #ff0000
compare

Compare images with passed options. Asynchronous operation. Returns compare result sa Boolean value.

const opts = {
    canHaveCaret: true,
    pixelRatio: 1,
    tolerance: 2,
    antialiasingTolerance: 3
};

return Image.compare(path1, path2, opts)
    .then((isEqual) => {
        console.log(isEqual);
    });
buildDiff

Save new diff image with passed options on the file system.

const diffOpts = {
    reference: '/ref/path/image.png',
    current: '/curr/path/image.png',
    diff: '/diff/path/image.png',
    diffColor: '#f5f5f5',
    tolerance: 2
};

return Image.buildDiff(diffOpts); // will save image with diff to /diff/path/image.png

Temp

Class for creating temp direcroty for image save. Directory will be removed on process end.

init

Init temp directory.

path

Generate random path relative temp directory.

serialize

Serialize Temp instance.

attach

Attach passed directory to the current Temp instance.

clientBdridge

const {clientBridge} = require('gemini-core');

return clientBridge.build(browser, {calibration, coverage});

coverageLevel

const {coverage: {coverageLevel}} = require('gemini-core');

coverageLevel.merge(oldValue, newValue);

Current Tags

  • 5.1.1                                ...           latest (19 days ago)

54 Versions

  • 5.1.1                                ...           19 days ago
  • 5.1.0                                ...           a month ago
  • 5.0.1                                ...           3 months ago
  • 5.0.0                                ...           4 months ago
  • 4.0.0                                ...           6 months ago
  • 3.8.3                                ...           6 months ago
  • 3.8.2                                ...           10 months ago
  • 3.8.1                                ...           10 months ago
  • 3.8.0                                ...           a year ago
  • 3.7.1                                ...           a year ago
  • 3.7.0                                ...           a year ago
  • 3.6.1                                ...           a year ago
  • 3.6.0                                ...           a year ago
  • 3.5.0                                ...           a year ago
  • 3.4.0                                ...           a year ago
  • 3.3.0                                ...           a year ago
  • 3.2.0                                ...           a year ago
  • 3.1.2                                ...           a year ago
  • 3.1.1                                ...           a year ago
  • 3.1.0                                ...           a year ago
  • 3.0.3                                ...           a year ago
  • 3.0.2                                ...           a year ago
  • 3.0.1                                ...           a year ago
  • 3.0.0                                ...           a year ago
  • 2.11.2                                ...           2 years ago
  • 2.11.1                                ...           2 years ago
  • 2.11.0                                ...           2 years ago
  • 2.10.0                                ...           2 years ago
  • 2.9.1                                ...           2 years ago
  • 2.9.0                                ...           2 years ago
  • 2.8.1                                ...           2 years ago
  • 2.8.0                                ...           2 years ago
  • 2.7.1                                ...           2 years ago
  • 2.7.0                                ...           2 years ago
  • 2.6.2                                ...           2 years ago
  • 2.6.1                                ...           2 years ago
  • 2.6.0                                ...           2 years ago
  • 2.5.1                                ...           2 years ago
  • 2.5.0                                ...           2 years ago
  • 2.4.0                                ...           2 years ago
  • 2.3.2                                ...           2 years ago
  • 2.3.1                                ...           2 years ago
  • 2.3.0                                ...           2 years ago
  • 2.2.1                                ...           2 years ago
  • 2.2.0                                ...           2 years ago
  • 2.1.0                                ...           3 years ago
  • 2.0.0                                ...           3 years ago
  • 1.3.2                                ...           3 years ago
  • 1.3.1                                ...           3 years ago
  • 1.3.0                                ...           3 years ago
  • 1.2.0                                ...           3 years ago
  • 1.1.1                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Downloads
Today 0
This Week 1
This Month 99
Last Day 1
Last Week 6
Last Month 140
Dependencies (15)
Dev Dependencies (9)

Copyright 2014 - 2016 © taobao.org |