From 1b4a48d9a1cb7ba9d2408e9a37533eb7013c2317 Mon Sep 17 00:00:00 2001 From: Damon Aw Date: Wed, 28 Jun 2017 23:09:30 -0400 Subject: [PATCH] Automate the use of DynamoDB --- .gitignore | 3 +++ circle.yml | 16 +++++----------- package.json | 4 +++- tests/index-test.js | 14 ++++++++++++++ 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 4bbaf5f..0beef0c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ node_modules subway.zip .env* +.env +downloads +.vscode diff --git a/circle.yml b/circle.yml index 63566e1..49a6578 100644 --- a/circle.yml +++ b/circle.yml @@ -1,14 +1,4 @@ machine: - pre: - - mkdir -p ~/downloads - - mkdir -p ~/dynamodb_local - - wget -N https://s3-us-west-2.amazonaws.com/dynamodb-local/dynamodb_local_latest.tar.gz -P ~/downloads - - post: - - tar -xvf /home/ubuntu/downloads/dynamodb_local_latest.tar.gz -C ~/dynamodb_local - - 'cd dynamodb_local;java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb': - background: true - node: version: $NODE_RUNTIME_VERSION environment: @@ -30,14 +20,18 @@ dependencies: else echo "The correct version of Yarn is already installed." fi + - yarn run dynamodb:download + - yarn run dynamodb:start: + background: true override: - yarn install + cache_directories: - ~/.yarn - ~/.cache/yarn - - ~/downloads + - ~/nyc-subway/downloads test: override: diff --git a/package.json b/package.json index 93d913d..4cc9093 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,9 @@ "main": "index.js", "author": "Damon Aw ", "scripts": { - "release": "rm -f subway.zip && yarn --production && zip -r subway.zip . -x *.git*", + "dynamodb:download": "mkdir -p downloads && mkdir -p dynamodb_local && wget -N https://s3-us-west-2.amazonaws.com/dynamodb-local/dynamodb_local_latest.tar.gz -P ./downloads && tar -xvf ./downloads/dynamodb_local_latest.tar.gz -C ./dynamodb_local", + "dynamodb:start": "java -Djava.library.path=./dynamodb_local/DynamoDBLocal_lib -jar ./dynamodb_local/DynamoDBLocal.jar -sharedDb -inMemory", + "release": "rm -f subway.zip && yarn --production && zip -r subway.zip . -x '*.git*' -x 'tests/*' -x 'downloads/*' -x 'dynamodb_local/*'", "test": "NODE_ENV=test ava" }, "ava": { diff --git a/tests/index-test.js b/tests/index-test.js index 99cf2ff..ee0883c 100644 --- a/tests/index-test.js +++ b/tests/index-test.js @@ -1,4 +1,5 @@ import fs from 'fs'; +import { spawn } from 'child_process'; import test from 'ava'; import LambdaTester from 'lambda-tester'; @@ -6,6 +7,19 @@ import fetchMock from 'fetch-mock'; import { handler, flashBriefingHandler } from '../index.js'; +var dynamo; + +test.cb.before(t => { + dynamo = spawn('yarn run dynamodb:start', { shell: true, timeout: 3000 }); + setTimeout(t.end, 3000); +}) + +test.cb.after.always(t => { + dynamo.on('exit', () => t.end()); + setTimeout(t.end, 3000); + dynamo.kill('SIGINT'); +}) + test.serial('flashBriefingHandler', async t => { t.plan(3);