Skip to content

Commit

Permalink
refactor(spanner):ava to mocha (#1165)
Browse files Browse the repository at this point in the history
  • Loading branch information
nareshqlogic authored and fhinkel committed Mar 2, 2019
1 parent dae1088 commit 5b1f408
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions functions/spanner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
"node": ">=8"
},
"scripts": {
"test": "ava -T 20s --verbose test/*.test.js"
"test": "mocha test/*.test.js --timeout=20000"
},
"dependencies": {
"@google-cloud/spanner": "3.0.0"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "^3.0.0",
"ava": "0.25.0",
"mocha": "^5.2.0",
"proxyquire": "2.1.0",
"sinon": "7.2.5"
},
Expand Down
27 changes: 14 additions & 13 deletions functions/spanner/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

'use strict';

const proxyquire = require(`proxyquire`).noCallThru();
const sinon = require(`sinon`);
const test = require(`ava`);
const proxyquire = require('proxyquire').noCallThru();
const sinon = require('sinon');
const assert = require('assert');

const entities = [
{
Expand Down Expand Up @@ -53,7 +53,7 @@ function getSample() {
const SpannerMock = sinon.stub().returns(spannerMock);

return {
program: proxyquire(`../`, {
program: proxyquire('../', {
'@google-cloud/spanner': {Spanner: SpannerMock},
}),
mocks: {
Expand All @@ -71,19 +71,20 @@ function getSample() {
};
}

test(`get: Gets albums`, async t => {
it('get: Gets albums', async () => {
const sample = getSample();
const mocks = sample.mocks;

await sample.program.get(mocks.req, mocks.res);
t.true(mocks.spanner.instance.called);
t.true(mocks.instance.database.called);
t.true(mocks.database.run.calledWith(query));
t.true(mocks.results[0].toJSON.called);
t.true(
assert.strictEqual(mocks.spanner.instance.called, true);
assert.strictEqual(mocks.instance.database.called, true);
assert.strictEqual(mocks.database.run.calledWith(query), true);
assert.strictEqual(mocks.results[0].toJSON.called, true);
assert.strictEqual(
mocks.res.write.calledWith(
`SingerId: 1, AlbumId: 2, AlbumTitle: Total Junk\n`
)
'SingerId: 1, AlbumId: 2, AlbumTitle: Total Junk\n'
),
true
);
t.true(mocks.res.end.called);
assert.strictEqual(mocks.res.end.called, true);
});

0 comments on commit 5b1f408

Please sign in to comment.