diff --git a/appengine/memcached/app.js b/appengine/memcached/app.js index 3ba83e99a5..c8593ee30a 100644 --- a/appengine/memcached/app.js +++ b/appengine/memcached/app.js @@ -43,7 +43,9 @@ app.get('/', async (req, res, next) => { }); const PORT = process.env.PORT || 8080; -app.listen(PORT, () => { +const server = app.listen(PORT, () => { console.log(`App listening on port ${PORT}`); console.log('Press Ctrl+C to quit.'); }); + +module.exports = server; diff --git a/appengine/memcached/package.json b/appengine/memcached/package.json index 021dffe7a0..4fc85584d9 100644 --- a/appengine/memcached/package.json +++ b/appengine/memcached/package.json @@ -10,13 +10,15 @@ }, "scripts": { "start": "node app.js", - "test": "repo-tools test app" + "test": "mocha --exit test/*.test.js" }, "dependencies": { "express": "^4.16.4", "memjs": "^1.2.0" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "^3.3.0" + "chai": "^4.2.0", + "mocha": "^7.1.1", + "wait-port": "^0.2.7" } } diff --git a/appengine/memcached/test/app.test.js b/appengine/memcached/test/app.test.js new file mode 100644 index 0000000000..c2290430a1 --- /dev/null +++ b/appengine/memcached/test/app.test.js @@ -0,0 +1,13 @@ +const waitPort = require('wait-port'); +const {expect} = require('chai'); + +const PORT = process.env.PORT || 8080; + +describe('server listening', () => { + it('should be listening', async () => { + const server = require('../app.js'); + const isOpen = await waitPort({port: PORT}); + expect(isOpen).to.be.true; + server.close(); + }); +});