Skip to content

Commit 3f689e2

Browse files
nareshqlogicfhinkel
authored andcommitted
Refactor(background):ava to mocha (GoogleCloudPlatform#1153)
1 parent 0634546 commit 3f689e2

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

functions/background/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
"node": ">=8"
1313
},
1414
"scripts": {
15-
"test": "ava -T 20s --verbose test/*.test.js"
15+
"test": "mocha test/*.test.js --timeout=20000"
1616
},
1717
"dependencies": {
1818
"request": "2.88.0",
1919
"request-promise-native": "^1.0.5"
2020
},
2121
"devDependencies": {
2222
"@google-cloud/nodejs-repo-tools": "^3.0.0",
23-
"ava": "0.25.0",
23+
"mocha": "^5.2.0",
2424
"proxyquire": "2.1.0",
2525
"sinon": "7.2.5"
2626
},

functions/background/test/index.test.js

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515

1616
'use strict';
1717

18-
const proxyquire = require(`proxyquire`).noCallThru();
19-
const sinon = require(`sinon`);
20-
const test = require(`ava`);
21-
const tools = require(`@google-cloud/nodejs-repo-tools`);
18+
const proxyquire = require('proxyquire').noCallThru();
19+
const sinon = require('sinon');
20+
const assert = require('assert');
21+
const tools = require('@google-cloud/nodejs-repo-tools');
2222

2323
function getSample() {
24-
const requestPromiseNative = sinon.stub().returns(Promise.resolve(`test`));
24+
const requestPromiseNative = sinon.stub().returns(Promise.resolve('test'));
2525

2626
return {
27-
program: proxyquire(`../`, {
27+
program: proxyquire('../', {
2828
'request-promise-native': requestPromiseNative,
2929
}),
3030
mocks: {
@@ -33,65 +33,65 @@ function getSample() {
3333
};
3434
}
3535

36-
test.beforeEach(tools.stubConsole);
37-
test.afterEach.always(tools.restoreConsole);
36+
beforeEach(tools.stubConsole);
37+
afterEach(tools.restoreConsole);
3838

39-
test.serial(`should echo message`, t => {
39+
it('should echo message', () => {
4040
const event = {
4141
data: {
42-
myMessage: `hi`,
42+
myMessage: 'hi',
4343
},
4444
};
4545
const sample = getSample();
4646
const callback = sinon.stub();
4747

4848
sample.program.helloWorld(event, callback);
4949

50-
t.is(console.log.callCount, 1);
51-
t.deepEqual(console.log.firstCall.args, [event.data.myMessage]);
52-
t.is(callback.callCount, 1);
53-
t.deepEqual(callback.firstCall.args, []);
50+
assert.strictEqual(console.log.callCount, 1);
51+
assert.deepStrictEqual(console.log.firstCall.args, [event.data.myMessage]);
52+
assert.strictEqual(callback.callCount, 1);
53+
assert.deepStrictEqual(callback.firstCall.args, []);
5454
});
5555

56-
test.serial(`should say no message was provided`, t => {
57-
const error = new Error(`No message defined!`);
56+
it('should say no message was provided', () => {
57+
const error = new Error('No message defined!');
5858
const callback = sinon.stub();
5959
const sample = getSample();
6060
sample.program.helloWorld({data: {}}, callback);
6161

62-
t.is(callback.callCount, 1);
63-
t.deepEqual(callback.firstCall.args, [error]);
62+
assert.strictEqual(callback.callCount, 1);
63+
assert.deepStrictEqual(callback.firstCall.args, [error]);
6464
});
6565

66-
test.serial(`should make a promise request`, t => {
66+
it('should make a promise request', () => {
6767
const sample = getSample();
6868
const event = {
6969
data: {
70-
endpoint: `foo.com`,
70+
endpoint: 'foo.com',
7171
},
7272
};
7373

7474
return sample.program.helloPromise(event).then(result => {
75-
t.deepEqual(sample.mocks.requestPromiseNative.firstCall.args, [
76-
{uri: `foo.com`},
75+
assert.deepStrictEqual(sample.mocks.requestPromiseNative.firstCall.args, [
76+
{uri: 'foo.com'},
7777
]);
78-
t.is(result, `test`);
78+
assert.strictEqual(result, 'test');
7979
});
8080
});
8181

82-
test.serial(`should return synchronously`, t => {
83-
t.is(
82+
it('should return synchronously', () => {
83+
assert.strictEqual(
8484
getSample().program.helloSynchronous({
8585
data: {
8686
something: true,
8787
},
8888
}),
89-
`Something is true!`
89+
'Something is true!'
9090
);
9191
});
9292

93-
test.serial(`should throw an error`, t => {
94-
t.throws(
93+
it('should throw an error', () => {
94+
assert.throws(
9595
() => {
9696
getSample().program.helloSynchronous({
9797
data: {
@@ -100,6 +100,6 @@ test.serial(`should throw an error`, t => {
100100
});
101101
},
102102
Error,
103-
`Something was not true!`
103+
'Something was not true!'
104104
);
105105
});

0 commit comments

Comments
 (0)