1.0.4 • Published 7 years ago

node-es-local v1.0.4

Weekly downloads
5
License
MIT
Repository
github
Last release
7 years ago

node-es-local CircleCI

A simple low-dependency nodejs module that downloads, installs and starts elasticsearch v5.x locally for integration testing. Please note that this module currently only supports elasticsearch v5.x i.e. older versions are not supported.

The module attempts to download and unzip the package from the Official Elasticsearch artifacts source, if not already downloaded, and starts elasticsearch as a detached nodejs background process listening on the specified port.

To get started, npm install this module as a dev dependency:

npm install --save-dev node-es-local

This module has a single external dependency on the following module for unzipping:

  • adm-zip - a pure Javascript (no-dependency) implementation of zip for nodejs

Once installed, you can use the module in your mocha tests or within gulp tasks.

Usage

To download and start a local instance of elasticsearch:

const ElasticsearchLocal = require('node-es-local')

const elasticsearchVersion = '5.2.0'
const elasticsearchPort = 9500
const cacheDirectory = './.cache'
const targetDirectory = './.installs'

new ElasticsearchLocal(elasticsearchVersion, elasticsearchPort, {
  cacheDirectory: cacheDirectory,
  installationDirectory: targetDirectory
}).start()

start() returns a promise.

To stop a local instance of elasticsearch started by the previous script:

const ElasticsearchLocal = require('node-es-local')

const elasticsearchVersion = '5.2.0'
const elasticsearchPort = 9500
const cacheDirectory = './.cache'
const targetDirectory = './.installs'

new ElasticsearchLocal(elasticsearchVersion, elasticsearchPort, {
  cacheDirectory: cacheDirectory,
  installationDirectory: targetDirectory
}).stop()

stop() returns a promise.

Port 9200 is the default port if not specified and ./.cachedArtifacts and ./.installs are the default cache and default installation directories. Hence, if you are ok with the defaults, the following script is all you need:

const ElasticsearchLocal = require('node-es-local')
new ElasticsearchLocal('5.2.0').start()

Simples!

Using es-node-local in integration tests

The following example shows how you can use node-es-local with mocha to start a local instance of elasticsearch for integration tests:

const ElasticsearchLocal = require('node-es-local')

describe('Some feature eg search', () => {
  before('given an index with some entries', () => {
    return new ElasticsearchLocal('5.2.0').start()  // return the promise
      .then(() => {
        // Put some data in...
      })
  })

  after(() => {
    return new ElasticsearchLocal('5.2.0').stop() // return the promise
  })
1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago