Skip to content

Commit 607e680

Browse files
committed
build: improve docker setup
1 parent 8328434 commit 607e680

13 files changed

+106
-52
lines changed

.dockerignore

-1
This file was deleted.

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ env:
2222
script:
2323
- yarn validate
2424
after_success:
25-
- yarn --silent nyc report --reporter=text-lcov | sed "s|/app|$(pwd)|" | ./node_modules/.bin/coveralls
25+
- yarn report
2626
# Rebuild docs, only on master branch and not on pull requests
2727
- '[[ $TRAVIS_PULL_REQUEST = "false" && $TRAVIS_BRANCH = "master" ]] && yarn docs'
2828

docker/Dockerfile-test

-7
This file was deleted.

docker/docker-compose.test.yml

-25
This file was deleted.

package.json

+9-8
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@
2323
],
2424
"scripts": {
2525
"commit": "git-cz",
26-
"build": "yarn build:declaration && yarn build:rollup",
27-
"build:declaration": "tsc --project tsconfig.declaration.json --outDir dist/typings --declaration --emitDeclarationOnly",
28-
"build:rollup": "rollup -c",
29-
"lint": "tslint --project ./tsconfig.json",
30-
"test": "docker-compose -f docker/docker-compose.test.yml -p cypher-query-builder up --exit-code-from tests",
31-
"test:unit": "nyc --reporter=html --reporter=text-summary mocha src/*.spec.ts src/**/*.spec.ts",
32-
"validate": "yarn --silent lint && yarn --silent build && yarn --silent test",
33-
"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"
26+
"build": "scripts/build declaration && scripts/build rollup",
27+
"build:declaration": "scripts/build declaration",
28+
"build:rollup": "scripts/build rollup",
29+
"docs": "scripts/docs",
30+
"lint": "scripts/lint",
31+
"report": "scripts/report",
32+
"test": "scripts/test-integration",
33+
"test:unit": "scripts/test",
34+
"validate": "scripts/validate"
3435
},
3536
"config": {
3637
"commitizen": {

scripts/build

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
3+
kind="$1"
4+
case "$kind" in
5+
rollup)
6+
yarn rollup -c
7+
;;
8+
declaration)
9+
tsc --project tsconfig.declaration.json --outDir dist/typings --declaration --emitDeclarationOnly
10+
;;
11+
*)
12+
>&2 echo "Unknown build kind '$kind'. Expected rollup or declaration."
13+
exit 1
14+
;;
15+
esac

scripts/docs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
yarn typedoc \
4+
src/builder.ts \
5+
src/query.ts \
6+
src/connection.ts \
7+
src/clauses/index.ts \
8+
src/clauses/where-comparators.ts \
9+
src/clauses/where-operators.ts \
10+
--mode file \
11+
--theme minimal \
12+
--out ./docs \
13+
--excludeExternals \
14+
--excludeProtected \
15+
--excludePrivate \
16+
--ignoreCompilerErrors

scripts/lint

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
yarn tslint --project ./tsconfig.json

scripts/report

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
yarn --silent nyc report --reporter=text-lcov \
4+
| sed "s|/app|$(pwd)|" \
5+
| ./node_modules/.bin/coveralls

scripts/test

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
yarn --silent nyc \
4+
--reporter=html \
5+
--reporter=text-summary \
6+
mocha \
7+
src/**/*.spec.ts

scripts/test-integration

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
3+
start-neo4j() {
4+
docker run \
5+
-d \
6+
-p 7474:7474 \
7+
-p 7687:7687 \
8+
-e NEO4J_AUTH=neo4j/admin \
9+
"neo4j:${NEO4J_VERSION-latest}"
10+
}
11+
12+
run-tests() {
13+
yarn --silent nyc \
14+
--reporter=html \
15+
--reporter=text-summary \
16+
mocha \
17+
src/*.spec.ts \
18+
src/**/*.spec.ts \
19+
tests/*.test.ts \
20+
tests/**/*.test.ts "$@"
21+
}
22+
23+
# Start the neo4j docker container
24+
echo "Starting neo4j..."
25+
id=$(start-neo4j) || exit 1
26+
27+
# Run the tests
28+
echo "Running tests..."
29+
NEO4J_URL=bolt://localhost NEO4J_USER=neo4j NEO4J_PASS=admin run-tests "$@"
30+
code="$?"
31+
32+
# Stop the container
33+
echo "Stopping neo4j..."
34+
docker container stop "$id" > /dev/null
35+
36+
# Exit with the same code as the tests
37+
exit "$code"

scripts/validate

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
yarn --silent lint && yarn --silent build && yarn --silent test

tests/connection.test.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe('Connection', () => {
6262
const driverSpy = spy(neo4j, 'driver');
6363
const connection = new Connection(neo4jUrl, neo4jCredentials);
6464

65-
expect(driverSpy.calledOnce);
65+
expect(driverSpy.calledOnce).to.equal(true);
6666

6767
await connection.close();
6868
driverSpy.restore();
@@ -93,27 +93,27 @@ describe('Connection', () => {
9393
describe('#close', () => {
9494
it('should close the driver', async () => {
9595
await connection.close();
96-
expect(driverCloseSpy.calledOnce);
96+
expect(driverCloseSpy.calledOnce).to.equal(true);
9797
});
9898

9999
it('should only close the driver once', async () => {
100100
await connection.close();
101101
await connection.close();
102-
expect(driverCloseSpy.calledOnce);
102+
expect(driverCloseSpy.calledOnce).to.equal(true);
103103
});
104104
});
105105

106106
describe('#session', () => {
107107
it('should use the driver to create a session', () => {
108108
connection.session();
109-
expect(driverSessionStub.calledOnce);
109+
expect(driverSessionStub.calledOnce).to.equal(true);
110110
});
111111

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

116-
expect(driverSessionStub.notCalled);
116+
expect(driverSessionStub.notCalled).to.equal(true);
117117
expect(result).to.equal(null);
118118
});
119119
});
@@ -143,15 +143,15 @@ describe('Connection', () => {
143143

144144
const promise = connection.run(query);
145145
await expect(promise).to.be.fulfilled.then(() => {
146-
expect(sessionRunSpy.calledOnce);
146+
expect(sessionRunSpy.calledOnce).to.equal(true);
147147
expect(sessionRunSpy.calledWith('RETURN 1', params));
148148
});
149149
});
150150

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

157157
it('should close the session when run() throws', async () => {
@@ -180,7 +180,7 @@ describe('Connection', () => {
180180
try {
181181
await connection.run(new Query().raw('RETURN a'));
182182
} catch (e) {}
183-
expect(sessionCloseStub.calledOnce);
183+
expect(sessionCloseStub.calledOnce).to.equal(true);
184184
});
185185
});
186186
});
@@ -257,7 +257,7 @@ describe('Connection', () => {
257257
.toPromise()
258258
.then(() => {
259259
expect(count).to.equal(records.length);
260-
expect(sessionRunSpy.calledOnce);
260+
expect(sessionRunSpy.calledOnce).to.equal(true);
261261
expect(sessionRunSpy.calledWith(query.build(), params));
262262
});
263263
});
@@ -277,7 +277,7 @@ describe('Connection', () => {
277277
observable.subscribe({
278278
next: () => expect.fail(null, null, 'Observable should not emit any items'),
279279
error() {
280-
expect(sessionCloseSpy.calledOnce);
280+
expect(sessionCloseSpy.calledOnce).to.equal(true);
281281
done();
282282
},
283283
complete: () => expect.fail(null, null, 'Observable should not complete without an error'),

0 commit comments

Comments
 (0)