From 682fda8b0e1e66308a3b4e7fd0049dde9528805b Mon Sep 17 00:00:00 2001 From: sofisl <55454395+sofisl@users.noreply.github.com> Date: Thu, 16 Apr 2020 16:40:10 -0700 Subject: [PATCH] chore: refactor cloudsql_postgresql test from repo-tools (#1722) --- appengine/cloudsql_postgresql/package.json | 9 +++++---- .../test/serverListening.test.js | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 appengine/cloudsql_postgresql/test/serverListening.test.js diff --git a/appengine/cloudsql_postgresql/package.json b/appengine/cloudsql_postgresql/package.json index efe30faf08..4000771054 100644 --- a/appengine/cloudsql_postgresql/package.json +++ b/appengine/cloudsql_postgresql/package.json @@ -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", diff --git a/appengine/cloudsql_postgresql/test/serverListening.test.js b/appengine/cloudsql_postgresql/test/serverListening.test.js new file mode 100644 index 0000000000..00cff58412 --- /dev/null +++ b/appengine/cloudsql_postgresql/test/serverListening.test.js @@ -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'); + }); +});