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

Improve docker setup #132

Merged
merged 1 commit into from
Dec 23, 2019
Merged
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
1 change: 0 additions & 1 deletion .dockerignore

This file was deleted.

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ env:
script:
- yarn validate
after_success:
- yarn --silent nyc report --reporter=text-lcov | sed "s|/app|$(pwd)|" | ./node_modules/.bin/coveralls
- yarn report
# Rebuild docs, only on master branch and not on pull requests
- '[[ $TRAVIS_PULL_REQUEST = "false" && $TRAVIS_BRANCH = "master" ]] && yarn docs'

Expand Down
7 changes: 0 additions & 7 deletions docker/Dockerfile-test

This file was deleted.

25 changes: 0 additions & 25 deletions docker/docker-compose.test.yml

This file was deleted.

17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
],
"scripts": {
"commit": "git-cz",
"build": "yarn build:declaration && yarn build:rollup",
"build:declaration": "tsc --project tsconfig.declaration.json --outDir dist/typings --declaration --emitDeclarationOnly",
"build:rollup": "rollup -c",
"lint": "tslint --project ./tsconfig.json",
"test": "docker-compose -f docker/docker-compose.test.yml -p cypher-query-builder up --exit-code-from tests",
"test:unit": "nyc --reporter=html --reporter=text-summary mocha src/*.spec.ts src/**/*.spec.ts",
"validate": "yarn --silent lint && yarn --silent build && yarn --silent test",
"docs": "typedoc src/builder.ts src/query.ts src/connection.ts src/clauses/index.ts src/clauses/where-comparators.ts src/clauses/where-operators.ts --mode file --theme minimal --out ./docs --excludeExternals --excludeProtected --excludePrivate --ignoreCompilerErrors"
"build": "scripts/build declaration && scripts/build rollup",
"build:declaration": "scripts/build declaration",
"build:rollup": "scripts/build rollup",
"docs": "scripts/docs",
"lint": "scripts/lint",
"report": "scripts/report",
"test": "scripts/test-integration",
"test:unit": "scripts/test",
"validate": "scripts/validate"
},
"config": {
"commitizen": {
Expand Down
15 changes: 15 additions & 0 deletions scripts/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

kind="$1"
case "$kind" in
rollup)
yarn rollup -c
;;
declaration)
tsc --project tsconfig.declaration.json --outDir dist/typings --declaration --emitDeclarationOnly
;;
*)
>&2 echo "Unknown build kind '$kind'. Expected rollup or declaration."
exit 1
;;
esac
16 changes: 16 additions & 0 deletions scripts/docs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

yarn typedoc \
src/builder.ts \
src/query.ts \
src/connection.ts \
src/clauses/index.ts \
src/clauses/where-comparators.ts \
src/clauses/where-operators.ts \
--mode file \
--theme minimal \
--out ./docs \
--excludeExternals \
--excludeProtected \
--excludePrivate \
--ignoreCompilerErrors
3 changes: 3 additions & 0 deletions scripts/lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

yarn tslint --project ./tsconfig.json
5 changes: 5 additions & 0 deletions scripts/report
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

yarn --silent nyc report --reporter=text-lcov \
| sed "s|/app|$(pwd)|" \
| ./node_modules/.bin/coveralls
7 changes: 7 additions & 0 deletions scripts/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

yarn --silent nyc \
--reporter=html \
--reporter=text-summary \
mocha \
src/**/*.spec.ts
37 changes: 37 additions & 0 deletions scripts/test-integration
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash

start-neo4j() {
docker run \
-d \
-p 7474:7474 \
-p 7687:7687 \
-e NEO4J_AUTH=neo4j/admin \
"neo4j:${NEO4J_VERSION-latest}"
}

run-tests() {
yarn --silent nyc \
--reporter=html \
--reporter=text-summary \
mocha \
src/*.spec.ts \
src/**/*.spec.ts \
tests/*.test.ts \
tests/**/*.test.ts "$@"
}

# Start the neo4j docker container
echo "Starting neo4j..."
id=$(start-neo4j) || exit 1

# Run the tests
echo "Running tests..."
NEO4J_URL=bolt://localhost NEO4J_USER=neo4j NEO4J_PASS=admin run-tests "$@"
code="$?"

# Stop the container
echo "Stopping neo4j..."
docker container stop "$id" > /dev/null

# Exit with the same code as the tests
exit "$code"
3 changes: 3 additions & 0 deletions scripts/validate
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

yarn --silent lint && yarn --silent build && yarn --silent test
20 changes: 10 additions & 10 deletions tests/connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('Connection', () => {
const driverSpy = spy(neo4j, 'driver');
const connection = new Connection(neo4jUrl, neo4jCredentials);

expect(driverSpy.calledOnce);
expect(driverSpy.calledOnce).to.equal(true);

await connection.close();
driverSpy.restore();
Expand Down Expand Up @@ -94,27 +94,27 @@ describe('Connection', () => {
describe('#close', () => {
it('should close the driver', async () => {
await connection.close();
expect(driverCloseSpy.calledOnce);
expect(driverCloseSpy.calledOnce).to.equal(true);
});

it('should only close the driver once', async () => {
await connection.close();
await connection.close();
expect(driverCloseSpy.calledOnce);
expect(driverCloseSpy.calledOnce).to.equal(true);
});
});

describe('#session', () => {
it('should use the driver to create a session', () => {
connection.session();
expect(driverSessionStub.calledOnce);
expect(driverSessionStub.calledOnce).to.equal(true);
});

it('should return null if the connection has been closed', async () => {
await connection.close();
const result = connection.session();

expect(driverSessionStub.notCalled);
expect(driverSessionStub.notCalled).to.equal(true);
expect(result).to.equal(null);
});
});
Expand Down Expand Up @@ -144,15 +144,15 @@ describe('Connection', () => {

const promise = connection.run(query);
await expect(promise).to.be.fulfilled.then(() => {
expect(sessionRunSpy.calledOnce);
expect(sessionRunSpy.calledOnce).to.equal(true);
expect(sessionRunSpy.calledWith('RETURN 1', params));
});
});

it('should close the session after running a query', async () => {
const promise = connection.run((new Query()).raw('RETURN 1'));
await expect(promise).to.be.fulfilled
.then(() => expect(sessionCloseSpy.calledOnce));
.then(() => expect(sessionCloseSpy.calledOnce).to.equal(true));
});

it('should close the session when run() throws', async () => {
Expand Down Expand Up @@ -181,7 +181,7 @@ describe('Connection', () => {
try {
await connection.run(new Query().raw('RETURN a'));
} catch (e) {}
expect(sessionCloseStub.calledOnce);
expect(sessionCloseStub.calledOnce).to.equal(true);
});
});
});
Expand Down Expand Up @@ -258,7 +258,7 @@ describe('Connection', () => {
.toPromise()
.then(() => {
expect(count).to.equal(records.length);
expect(sessionRunSpy.calledOnce);
expect(sessionRunSpy.calledOnce).to.equal(true);
expect(sessionRunSpy.calledWith(query.build(), params));
});
});
Expand All @@ -278,7 +278,7 @@ describe('Connection', () => {
observable.subscribe({
next: () => expect.fail(null, null, 'Observable should not emit any items'),
error() {
expect(sessionCloseSpy.calledOnce);
expect(sessionCloseSpy.calledOnce).to.equal(true);
done();
},
complete: () => expect.fail(null, null, 'Observable should not complete without an error'),
Expand Down