Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(appengine-pubsub):ava to mocha #1225

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions appengine/pubsub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"scripts": {
"start": "node app.js",
"test": "repo-tools test app && ava -T 30s */*.test.js"
"test": "repo-tools test app && mocha */*.test.js --timeout=30000 --exit"
},
"dependencies": {
"@google-cloud/pubsub": "^0.22.0",
Expand All @@ -21,7 +21,7 @@
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "^3.0.0",
"ava": "^0.25.0",
"mocha": "^6.0.0",
"uuid": "^3.3.2"
},
"cloud-repo-tools": {
Expand Down
59 changes: 27 additions & 32 deletions appengine/pubsub/test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,58 +18,53 @@

'use strict';

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

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

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

test.serial.cb(`should send a message to Pub/Sub`, t => {
requestObj
.post(`/`)
it('should send a message to Pub/Sub', async () => {
await requestObj
.post('/')
.type('form')
.send({payload: payload})
.expect(200)
.expect(response => {
t.regex(response.text, /Message \d* sent/);
})
.end(t.end);
assert(new RegExp(/Message \d* sent/).test(response.text));
});
});

test.serial.cb(`should receive incoming Pub/Sub messages`, t => {
requestObj
.post(`/pubsub/push`)
it('should receive incoming Pub/Sub messages', async () => {
await requestObj
.post('/pubsub/push')
.query({token: process.env.PUBSUB_VERIFICATION_TOKEN})
.send({
message: {
data: payload,
},
})
.expect(200)
.end(t.end);
.expect(200);
});

test.serial.cb(
`should check for verification token on incoming Pub/Sub messages`,
t => {
requestObj
.post(`/pubsub/push`)
.field(`payload`, payload)
.expect(400)
.end(t.end);
}
);
it('should check for verification token on incoming Pub/Sub messages', async () => {
await requestObj
.post('/pubsub/push')
.field('payload', payload)
.expect(400);
});

test.serial.cb(`should list sent Pub/Sub messages`, t => {
requestObj
.get(`/`)
it('should list sent Pub/Sub messages', async () => {
await requestObj
.get('/')
.expect(200)
.expect(response => {
t.regex(response.text, /Messages received by this instance/);
})
.end(t.end);
assert(
new RegExp(/Messages received by this instance/).test(response.text)
);
});
});