Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(bug): Update README + add async install #85

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,26 @@ Usage example

```
var dynamodbLocal = require("dynamodb-localhost");
dynamodbLocal.install(); /* This is one time operation. Safe to execute multiple times which installs DynamoDB once. All the other methods depends on this. */
dynamodbLocal.start({port: 8000});
/* Installation is one time operation. Safe to execute multiple times which installs DynamoDB once. All the other methods depends on this. */
dynamodbLocal.install(function() {
dynamodbLocal.start({port: 8000});
});
```

or

```
var dynamodbLocal = require("dynamodb-localhost");
await dynamodbLocal.install();

dynamodbLocal.start();
```

Supported methods

```
install(callback) To install DynamoDB Local for usage (This is one time operation unless execute remove). 'callback' function is called after installation completes (or if already installed, immediately)
install(callback) To install DynamoDB Local for usage (This is one time operation unless remove is executed). 'callback' function is called after installation completes (or if already installed, immediately)
installAsync() To install DynamoDB Local asynchronously. Otherwise identical to install.
start(options) To start an instance of DynamoDB Local. More information about options shown in the coming section
stop(port) To stop particular instance of DynamoDb Local running on an specified port
remove(callback) To remove DynamoDB Local instance. 'callback' function is called after removal complete.
Expand Down Expand Up @@ -73,4 +85,4 @@ You can also contribute by writing. Feel free to let us know if you want to publ

## Credits

Bunch of thanks to doapp-ryanp who started [dynamodb-local](https://github.com/doapp-ryanp/dynamodb-local) project
Bunch of thanks to doapp-ryanp who started [dynamodb-local](https://github.com/doapp-ryanp/dynamodb-local) project
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ var dynamodb = {
callback();
});
},
installAsync: async function(path) {
return new Promise((resolve) => {
dynamodb.install(resolve, path);
});
},
start: function(options) {
var instance = starter.start(options, config);
dbInstances[instance.port] = {
Expand Down
20 changes: 18 additions & 2 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
const fs = require("fs");
const utils = require("../dynamodb/utils");
const { expect } = require("chai");
const { install, remove } = require("../index");
const { install, remove, installAsync } = require("../index");
const config = require("../dynamodb/config.json");

describe("install", function() {
const installPath = `./dynamodb/${config.setup.install_path}`;
const jarPath = `${installPath}/${config.setup.jar}`;

beforeEach(() => {
if (fs.existsSync(jarPath)) {
fs.unlinkSync(jarPath);
}
});

it("downloads the jar successfully", function(done) {
this.timeout(10000); // 10 second timeout
this.timeout(60000); // 60 second timeout

install(function() {
if (fs.existsSync(jarPath)) {
Expand All @@ -18,6 +24,16 @@ describe("install", function() {
});
});

it("can download the jar async", async function() {
this.timeout(60000); // 60s timeout

await installAsync();

if (!fs.existsSync(jarPath)) {
throw new Error('Jar was not downloaded.');
}
});

it("removes the setup files", function(done) {
this.timeout(10000);

Expand Down