Skip to content

Commit 5d8904f

Browse files
AVaksmanfhinkel
authored andcommitted
refactor(appengine-pubsub):ava to mocha (GoogleCloudPlatform#1225)
1 parent 2482f90 commit 5d8904f

2 files changed

Lines changed: 29 additions & 34 deletions

File tree

appengine/pubsub/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"scripts": {
1212
"start": "node app.js",
13-
"test": "repo-tools test app && ava -T 30s */*.test.js"
13+
"test": "repo-tools test app && mocha */*.test.js --timeout=30000 --exit"
1414
},
1515
"dependencies": {
1616
"@google-cloud/pubsub": "^0.22.0",
@@ -21,7 +21,7 @@
2121
},
2222
"devDependencies": {
2323
"@google-cloud/nodejs-repo-tools": "^3.0.0",
24-
"ava": "^0.25.0",
24+
"mocha": "^6.0.0",
2525
"uuid": "^3.3.2"
2626
},
2727
"cloud-repo-tools": {

appengine/pubsub/test/app.test.js

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,58 +18,53 @@
1818

1919
'use strict';
2020

21-
const test = require(`ava`);
22-
const path = require(`path`);
23-
const utils = require(`@google-cloud/nodejs-repo-tools`);
21+
const assert = require('assert');
22+
const path = require('path');
23+
const utils = require('@google-cloud/nodejs-repo-tools');
2424

25-
const message = `This is a test message sent at: `;
25+
const message = 'This is a test message sent at: ';
2626
const payload = message + Date.now();
2727

28-
const cwd = path.join(__dirname, `../`);
28+
const cwd = path.join(__dirname, '../');
2929
const requestObj = utils.getRequest({cwd: cwd});
3030

31-
test.serial.cb(`should send a message to Pub/Sub`, t => {
32-
requestObj
33-
.post(`/`)
31+
it('should send a message to Pub/Sub', async () => {
32+
await requestObj
33+
.post('/')
3434
.type('form')
3535
.send({payload: payload})
3636
.expect(200)
3737
.expect(response => {
38-
t.regex(response.text, /Message \d* sent/);
39-
})
40-
.end(t.end);
38+
assert(new RegExp(/Message \d* sent/).test(response.text));
39+
});
4140
});
4241

43-
test.serial.cb(`should receive incoming Pub/Sub messages`, t => {
44-
requestObj
45-
.post(`/pubsub/push`)
42+
it('should receive incoming Pub/Sub messages', async () => {
43+
await requestObj
44+
.post('/pubsub/push')
4645
.query({token: process.env.PUBSUB_VERIFICATION_TOKEN})
4746
.send({
4847
message: {
4948
data: payload,
5049
},
5150
})
52-
.expect(200)
53-
.end(t.end);
51+
.expect(200);
5452
});
5553

56-
test.serial.cb(
57-
`should check for verification token on incoming Pub/Sub messages`,
58-
t => {
59-
requestObj
60-
.post(`/pubsub/push`)
61-
.field(`payload`, payload)
62-
.expect(400)
63-
.end(t.end);
64-
}
65-
);
54+
it('should check for verification token on incoming Pub/Sub messages', async () => {
55+
await requestObj
56+
.post('/pubsub/push')
57+
.field('payload', payload)
58+
.expect(400);
59+
});
6660

67-
test.serial.cb(`should list sent Pub/Sub messages`, t => {
68-
requestObj
69-
.get(`/`)
61+
it('should list sent Pub/Sub messages', async () => {
62+
await requestObj
63+
.get('/')
7064
.expect(200)
7165
.expect(response => {
72-
t.regex(response.text, /Messages received by this instance/);
73-
})
74-
.end(t.end);
66+
assert(
67+
new RegExp(/Messages received by this instance/).test(response.text)
68+
);
69+
});
7570
});

0 commit comments

Comments
 (0)