diff --git a/.env b/.env new file mode 100644 index 0000000..809bb3a --- /dev/null +++ b/.env @@ -0,0 +1,7 @@ +# Environment variables for docker-compose +PGHOST=db +PGPASSWORD=pg-cursor-test +POSTGRES_PASSWORD=pg-cursor-test +PGUSER=postgres +POSTGRES_VERSION=9.6 +NODE_VERSION=8 diff --git a/.travis.yml b/.travis.yml index 54d6654..a63d01f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,9 @@ language: node_js dist: trusty sudo: false node_js: - - "4.2" - "6" - "8" + - "10" env: - PGUSER=postgres services: diff --git a/README.md b/README.md index 1b01b3d..6fae016 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,21 @@ ___note___: this depends on _either_ `npm install pg` or `npm install pg.js`, bu ### :star: [Documentation](https://node-postgres.com/api/cursor) :star: +### Testing + +To run the test suite against all supported versions of PostgreSQL and +Node.js locally, you will need to install and run Docker, and then run + + ./test_all_versions.sh + +This will take a while, and consume a lot of bandwidth downloading Docker +images. + +Due to a [bug in npm][npmbug], the output is very verbose, but with a bit of +scrolling, you should hopefully see green checkmarks for every test run. + +[npmbug]: https://npm.community/t/npm-rebuild-silent-is-not-silent/3834 + ### license The MIT License (MIT) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..b9b4958 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,24 @@ +version: "3" + +services: + db: + image: "postgres:${POSTGRES_VERSION}" + restart: always + expose: + - 5432 + environment: + - POSTGRES_PASSWORD + test: + image: "node:${NODE_VERSION}" + links: + - db + environment: + - PGHOST + - PGPASSWORD + - PGUSER + working_dir: /app + volumes: + - .:/app + command: bash -c " + npm rebuild --silent && + npm test " diff --git a/test/test_all_versions.sh b/test/test_all_versions.sh new file mode 100755 index 0000000..43f0fb5 --- /dev/null +++ b/test/test_all_versions.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +node_versions='6 8 10' +pg_versions='9.6 10 11' + +trap cleanup 0 1 2 3 6 +set -e + +function cleanup { + docker-compose down +} + +for node_version in $node_versions +do + export NODE_VERSION=$node_version + for pg_version in $pg_versions + do + export POSTGRES_VERSION=$pg_version + echo "Running tests with Node v$node_version, PostgreSQL v$pg_version..." + docker-compose run --rm test + docker-compose down + done +done +echo "All done"