From bb8dadc40bd7c105b2916112318bcb9c32155875 Mon Sep 17 00:00:00 2001 From: Alex <7764119+AVaksman@users.noreply.github.com> Date: Sat, 6 Apr 2019 17:39:11 -0400 Subject: [PATCH] refactor(functions/tips): ava to mocha (#1241) --- functions/tips/package.json | 5 ++++- functions/tips/test/index.test.js | 32 ++++++++++++++++++------------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/functions/tips/package.json b/functions/tips/package.json index 26560528df..6f883de045 100644 --- a/functions/tips/package.json +++ b/functions/tips/package.json @@ -11,13 +11,16 @@ "engines": { "node": ">=8" }, + "scripts": { + "test": "mocha test/*.test.js --timeout=60000 --exit" + }, "dependencies": { "@google-cloud/pubsub": "^0.22.2", "safe-buffer": "^5.1.2" }, "devDependencies": { "@google-cloud/nodejs-repo-tools": "^3.0.0", - "ava": "^0.25.0", + "mocha": "^6.0.0", "sinon": "^7.0.0" }, "cloud-repo-tools": { diff --git a/functions/tips/test/index.test.js b/functions/tips/test/index.test.js index 2c460a05d3..4fd5d1211c 100644 --- a/functions/tips/test/index.test.js +++ b/functions/tips/test/index.test.js @@ -16,17 +16,16 @@ 'use strict'; const sinon = require(`sinon`); -const test = require(`ava`); +const assert = require(`assert`); const tools = require(`@google-cloud/nodejs-repo-tools`); const sample = require(`../`); +beforeEach(tools.stubConsole); +afterEach(tools.restoreConsole); -test.beforeEach(tools.stubConsole); -test.afterEach.always(tools.restoreConsole); - -test(`should demonstrate retry behavior for a promise`, async t => { +it('should demonstrate retry behavior for a promise', done => { // Retry by throwing an error - t.throws(() => { + assert.throws(() => { sample.retryPromise({ data: { retry: true, @@ -35,10 +34,16 @@ test(`should demonstrate retry behavior for a promise`, async t => { }, 'Retrying...'); // Terminate by returning a rejected promise - await t.throws(sample.retryPromise({data: {}}), 'Not retrying...'); + sample.retryPromise({data: {}}).then( + () => {}, + error => { + assert.strictEqual(error.message, 'Not retrying...'); + done(); + } + ); }); -test(`should demonstrate retry behavior for a callback`, t => { +it('should demonstrate retry behavior for a callback', done => { const cb = sinon.stub(); const err = new Error('Error!'); @@ -51,14 +56,15 @@ test(`should demonstrate retry behavior for a callback`, t => { }, cb ); - t.deepEqual(cb.firstCall.args, [err]); + assert.deepStrictEqual(cb.firstCall.args, [err]); // Terminate by passing nothing to the callback sample.retryCallback({data: {}}, cb); - t.deepEqual(cb.secondCall.args, []); + assert.deepStrictEqual(cb.secondCall.args, []); + done(); }); -test(`should call a GCP API`, async t => { +it('should call a GCP API', async () => { const reqMock = { body: { topic: process.env.FUNCTIONS_TOPIC, @@ -76,6 +82,6 @@ test(`should call a GCP API`, async t => { // use a delay here and keep the sample idiomatic await new Promise(resolve => setTimeout(resolve, 1000)); - t.true(resMock.status.calledOnce); - t.true(resMock.status.calledWith(200)); + assert.ok(resMock.status.calledOnce); + assert.ok(resMock.status.calledWith(200)); });