Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

google-datastore-emulator

ert78gb3kMIT7.1.0TypeScript support: included

NodeJs wrapper to google datastore emulator. It could start and stop emulator as node module

google, datastore, emulator, nodejs, wrapper

readme

Google Cloud Datastore Emulator

CI CodeQL

This package helps to start / stop Google Datatstore Emulator with javascript. From 1.1.0 also could usable with google/cloud-sdk docker image. The wrapper automatically pull the image is not exists on the host, but I suggest to pull the image in the 'before_test' section in the CI script Important: Be careful with the timeouts, need time to pull the image, start and stop the container.

Perfect to support unit testing where the persistent layer is the gcloud Datastore.

The wrapper sets DATASTORE_EMULATOR_HOST and DATASTORE_PROJECT_ID environment variables.

Prerequisites

To use the emulator locally you need to install Google Cloud SDK or with Docker you need to install Docker host

Installation

npm install google-datastore-emulator --save-dev

Usage

I think the package is the most suitable for unit testing.

const datastore = require('@google-cloud/datastore');
const Emulator = require('google-datastore-emulator');

describe('test suit', ()=>{
    process.env.GCLOUD_PROJECT = 'project-id'; // Set the datastore project Id globally

    let emulator;

    before(()=>{
        const options = {
            useDocker: true // if you need docker image
        };

        emulator = new Emulator(options);

        return emulator.start();
    });

    after(()=>{
        return emulator.stop();
    });

    it('test case', ()=>{
        // your test
    });
})

Options

parameter (type) default value description
project (string) test This variable is datastore project Id.
storeOnDisk (boolean) false The datastore either persists the entities on disk or not.
dataDir (string) empty The emulator creates a directory where the project files are stored. If it is empty the emulator default value will be used. You could set relative ./directory or absolute path /tmp/dir1/dir2/. If this directory does not exist, it will be created. Bug : With linux Docker host don't delete the folder
clean (boolean) true If dataDir value is set and 'clean' value is true then the package deletes the dataDir. The package does not delete the gcloud emulator default directory.
host (string) localhost If it is empty the'localhost' of google default value is used. It can take the form of a single address (hostname, IPv4, or IPv6)
port (number) empty If it is empty the emulator selects a random free port.
debug (boolean) false If it is true, it writes the console.logs of the emulator onto the main process console.
consistency (string) '1.0' The consistency level of the Datastore Emulator. More details
useDocker (boolean) false If it is true, it use docker image to run emulator instead of locally installed version.
dockerImage (string) 'google/cloud-sdk:latest' This image will be use by docker. The default: google/cloud-sdk:latest

Methods

name description
start Starts the emulator and returns a Promise.
stop Stops the emulator and returns a Promise.

License

MIT

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

7.1.0 (2023-08-30)

Features

7.0.0 (2023-06-10)

⚠ BREAKING CHANGES

  • Require Node.js 16

Bug Fixes

6.0.1 (2022-12-02)

Bug Fixes

6.0.0 (2022-06-22)

⚠ BREAKING CHANGES

  • drop node 12 support

Features

Bug Fixes

  • allow @google-cloud/datastore 7.0.0 (#114) (c8bd236)
  • handle other "port already in use" error message (#118) (19bd174)

5.2.0 (2021-12-30)

Features

Bug Fixes

  • throw proper exception when emulator can't start because port already in used (#106) (ad26bef)

5.1.0 (2021-12-19)

Features

Bug Fixes

  • bump dockerode from 3.3.0 to 3.3.1 (#94) (0eb499a)
  • remove code duplication of the consistency param calculation (#102) (9f8c963)
  • unsafe shell command construction (#101) (ed31fcf)

5.0.0 (2021-07-17)

⚠ BREAKING CHANGES

  • Drop Node 10 support

Features

4.0.0 (2020-09-05)

⚠ BREAKING CHANGES

  • supported node 10+ fs-extra dropped older then node 10 support

Bug Fixes

  • change peer dep version @google-cloud/datastore <7.0.0 (2259622)
  • upgrade dockerode => 3.2.1 (#53) (f02fda6)
  • upgrade fs-extra => 9.0.1 (#54) (4841814)

3.0.2 (2020-02-16)

Bug Fixes

  • upgrade tree-kill => 1.2.2 (cc1a9c5)

3.0.1 (2019-11-23)

Bug Fixes

3.0.0 (2019-11-14)

⚠ BREAKING CHANGES

  • The legacy protocol support was removed from Cloud SDK 267.0.0

Features

  • remove 'legacy' parameter (80d1c7e)

2.2.2 (2019-09-05)

Bug Fixes

  • --legacy parameter is deprecated by Google (8058273)

2.2.1 (2019-08-25)

Bug Fixes

  • allow @google-cloud/datastore v4 as peer dependency (0b8b438)
  • data directory creation (c4e3c77)
  • kill process of the locally installed sdk (bfba371)

2.2.0 (2019-04-18)

Bug Fixes

  • catch docker pull errors (906a2a6)

Features

2.1.1 (2019-04-16)

Bug Fixes

  • rename the projectId to project in the TS definitions (b98b77c)

2.1.0 (2018-11-11)

Bug Fixes

Features

2.0.1 (2018-11-09)

Bug Fixes

  • package: update fs-extra to version 4.0.0 (#19) (7a9be20)
  • 2 start after stop (#27) (146233f), closes #26
  • dockerImage option was not used everywhere (2302104)
  • Improve parent process.exit handling (#7) (e4d33fe)

Features