Skip to content

Commit

Permalink
chore: refactor cloudsql_postgresql test from repo-tools (#1722)
Browse files Browse the repository at this point in the history
  • Loading branch information
sofisl authored Apr 16, 2020
1 parent 2c26a14 commit 682fda8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
9 changes: 5 additions & 4 deletions appengine/cloudsql_postgresql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,22 @@
"node": ">=8.0.0"
},
"scripts": {
"unit-test": "mocha test/*.test.js --timeout=30000",
"unit-test": "mocha test/createTables.test.js --timeout=30000 && mocha test/server.test.js",
"start-proxy": "! pgrep cloud_sql_proxy > /dev/null && cloud_sql_proxy -instances=$INSTANCE_CONNECTION_NAME=tcp:$SQL_PORT &",
"system-test": "repo-tools test app -- server.js",
"system-test": "mocha test/serverListening.test.js --exit",
"system-test-proxy": "npm run start-proxy; npm run system-test",
"all-test": "npm run unit-test && npm run system-test",
"test": "npm -- run all-test"
},
"dependencies": {
"chai": "^4.2.0",
"express": "^4.16.4",
"knex": "^0.20.0",
"pg": "^8.0.0",
"prompt": "^1.0.0"
"prompt": "^1.0.0",
"wait-port": "^0.2.7"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "^3.3.0",
"mocha": "^7.0.0",
"proxyquire": "^2.1.0",
"sinon": "^9.0.0",
Expand Down
15 changes: 15 additions & 0 deletions appengine/cloudsql_postgresql/test/serverListening.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const waitPort = require('wait-port');
const {expect} = require('chai');
const PORT = process.env.PORT || 8080;
const childProcess = require('child_process');
const path = require('path');
const appPath = path.join(__dirname, '../server.js');

describe('server listening', () => {
it('should be listening', async () => {
const child = childProcess.exec(`node ${appPath}`);
const isOpen = await waitPort({port: PORT});
expect(isOpen).to.be.true;
process.kill(child.pid, 'SIGTERM');
});
});

0 comments on commit 682fda8

Please sign in to comment.