Skip to content

Commit d685169

Browse files
authored
chore: refactor typescript test (GoogleCloudPlatform#1699)
1 parent 86ad6f9 commit d685169

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

appengine/typescript/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ app.get("/", (req, res) => {
2020
res.send("🎉 Hello TypeScript! 🎉");
2121
});
2222

23-
app.listen(PORT, () => {
23+
const server = app.listen(PORT, () => {
2424
console.log(`App listening on port ${PORT}`);
2525
});
26+
27+
module.exports = server;

appengine/typescript/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"scripts": {
1212
"prepare": "npm run gcp-build",
1313
"pretest": "npm run gcp-build",
14-
"test": "repo-tools test app -- index.js",
14+
"test": "mocha test/*.test.js --exit",
1515
"posttest": "npm run lint",
1616
"lint": "tslint -p .",
1717
"start": "node ./index.js",
@@ -23,8 +23,10 @@
2323
"typescript": "^3.0.1"
2424
},
2525
"devDependencies": {
26-
"@google-cloud/nodejs-repo-tools": "^3.3.0",
26+
"mocha": "^7.0.0",
27+
"wait-port": "^0.2.7",
2728
"@types/express": "^4.16.0",
29+
"chai": "^4.2.0",
2830
"tslint": "^6.0.0"
2931
}
3032
}
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('../index.js');
9+
const isOpen = await waitPort({port: PORT});
10+
expect(isOpen).to.be.true;
11+
server.close();
12+
});
13+
});

0 commit comments

Comments
 (0)