0.6.0 • Published 4 years ago

gcp-emulator v0.6.0

Weekly downloads
14
License
ISC
Repository
github
Last release
4 years ago

GCP Emulator

Test Release Dependabot Status

Roughly emulate Google Cloud Platform services for development.

Emulators

  • Cloud Functions cloud-functions
  • Cloud Storage cloud-storage
  • Cloud Tasks cloud-tasks

Getting Started

Install the package.

yarn add -D gcp-emulator

Use as a CLI.

gcp-emulator emulate --emulators cloud-functions --cloud-functions-filepath ./function.js

Use as a Library.

import { EmulatorCloudFunctions } from "gcp-emulators";

const emulatorCloudFunctions = new EmulatorCloudFunctions({
  filepath: "./function.js",
  server: {
    port: 9010,
    hostname: "localhost",
    ssl: ...,
  },
});

Logging

The logger supports the following types of logs *, info, warn, error.

You can configure which types of logs are output by setting the LOGGER environment variable or setting the UtilityLogger.level property.

Proxy

You can configure a proxy server for all http based emulators to use.

You can also configure the proxy to use ngrok.

CLI Usage

Options

ArgumentDescriptionValue
--configjavascript or json config.gcprc.js

emulate command

gcp-emulator emulate [options]

Options

ArgumentDescriptionValue
--emulatorsemulators to usecloud-functions,cloud-storage,cloud-tasks
--proxyproxy emulatorstrue
--proxy-portproxy server port9000
--proxy-ngrokproxy with ngroktrue
--proxy-ngrok-authtokenproxy ngrok authtokenxxx
--proxy-ngrok-subdomainproxy ngrok subdomaingcp-emulator
--ssl-key-filepathglobal server ssl key path./key.pem
--ssl-cert-filepathglobal server ssl cert path./cert.pem
--cloud-functions-portcloud-functions emulator server port9010
--cloud-functions-filepathcloud-functions emulator source path./function.js
--cloud-functions-ssl-key-filepathcloud-functions emulator server ssl key path./key.pem
--cloud-functions-ssl-cert-filepathcloud-functions emulator server ssl cert path./cert.pem
--cloud-storage-portcloud-storage emulator server port9020
--cloud-storage-filepathcloud-storage emulator source path./public
--cloud-storage-ssl-key-filepathcloud-storage emulator server ssl key path./key.pem
--cloud-storage-ssl-cert-filepathcloud-storage emulator server ssl cert path./cert.pem

CLI Config

The file provided to the --config argument should return the following Javascript object structure when required in Node.

{
  [commandName]: {
    [camelCaseArgument]: value;
  }
}

Caveats & Limitations

The Cloud Functions emulator clears the require.cache before executing the function, this improves the development experience but may cause issues of it's own in certain situations.

The Cloud Storage emulator is more-or-less a simple static server.

The Cloud Tasks emulator uses sinon to stub the @google-cloud/tasks package so it is required for the emulator to operate.

Depending on your usage a built-in 404 page will be sent to requests that cannot be resolved to an emulator, or where an emulator cannot resolve the request, this does not align with any particular Google Cloud Platform service but seems more useful than not having it.

0.6.0

4 years ago

0.5.1

4 years ago

0.5.0

4 years ago

0.4.0

4 years ago

0.3.0

4 years ago

0.3.1

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago