Skip to content

Commit ad7cd89

Browse files
authored
chore:refactor memcached test (GoogleCloudPlatform#1698)
1 parent ad7a245 commit ad7cd89

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

appengine/memcached/app.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ app.get('/', async (req, res, next) => {
4343
});
4444

4545
const PORT = process.env.PORT || 8080;
46-
app.listen(PORT, () => {
46+
const server = app.listen(PORT, () => {
4747
console.log(`App listening on port ${PORT}`);
4848
console.log('Press Ctrl+C to quit.');
4949
});
50+
51+
module.exports = server;

appengine/memcached/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
},
1111
"scripts": {
1212
"start": "node app.js",
13-
"test": "repo-tools test app"
13+
"test": "mocha --exit test/*.test.js"
1414
},
1515
"dependencies": {
1616
"express": "^4.16.4",
1717
"memjs": "^1.2.0"
1818
},
1919
"devDependencies": {
20-
"@google-cloud/nodejs-repo-tools": "^3.3.0"
20+
"chai": "^4.2.0",
21+
"mocha": "^7.1.1",
22+
"wait-port": "^0.2.7"
2123
}
2224
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const waitPort = require('wait-port');
2+
const {expect} = require('chai');
3+
4+
const PORT = process.env.PORT || 8080;
5+
6+
describe('server listening', () => {
7+
it('should be listening', async () => {
8+
const server = require('../app.js');
9+
const isOpen = await waitPort({port: PORT});
10+
expect(isOpen).to.be.true;
11+
server.close();
12+
});
13+
});

0 commit comments

Comments
 (0)