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(samples): convert ava tests to mocha #400

Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0d4a0b8
Task #3053:Ava to mocha testcases conversion
Oct 24, 2018
7e83c41
Change var to const
Oct 25, 2018
fe27a82
Removed space
Oct 25, 2018
1137040
minor change
Oct 25, 2018
9a8b27e
Removed space
Oct 25, 2018
3fd088d
remove whitespace
Oct 25, 2018
27e5ef5
remove whitespace
Oct 25, 2018
8b2d751
Whitespace change
Oct 25, 2018
0e759d2
Updated test script in package json
Oct 25, 2018
84689c0
Refactor unit test cases
Oct 26, 2018
a521f18
Merge branch 'master' into sample-ava-to-mocha-testcases-conversion
JustinBeckwith Oct 26, 2018
da68376
Merge branch 'master' into sample-ava-to-mocha-testcases-conversion
JustinBeckwith Oct 28, 2018
71ffed5
Refactor the mocha testcases
Oct 29, 2018
05254e4
Merge branch 'sample-ava-to-mocha-testcases-conversion' of https://gi…
Oct 29, 2018
d032df1
refactor unit test cases
Oct 29, 2018
192bf95
Refactor unit test cases
Oct 29, 2018
1ffb424
Added new line
nareshqlogic Oct 30, 2018
b1b31c4
Merge branch 'master' into sample-ava-to-mocha-testcases-conversion
nareshqlogic Oct 31, 2018
bfd13f9
Refactor the code
nareshqlogic Oct 31, 2018
5a623a3
Refactor the code
nareshqlogic Nov 1, 2018
341b270
Merge branch 'master' into sample-ava-to-mocha-testcases-conversion
nareshqlogic Nov 2, 2018
8487a82
Merge branch 'master' into sample-ava-to-mocha-testcases-conversion
JustinBeckwith Nov 2, 2018
d6c3126
Merge branch 'master' into sample-ava-to-mocha-testcases-conversion
JustinBeckwith Nov 12, 2018
4984fbe
Removed try/catch
nareshqlogic Nov 12, 2018
192f18e
Merge branch 'master' into sample-ava-to-mocha-testcases-conversion
nareshqlogic Nov 13, 2018
5f21f30
Try/catch added while deleting instance and database in before hook
nareshqlogic Nov 13, 2018
5c5d137
Merge branch 'master' into sample-ava-to-mocha-testcases-conversion
nareshqlogic Nov 14, 2018
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: 1 addition & 3 deletions samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
"node": ">=8"
},
"scripts": {
"ava": "ava -T 5m --verbose test/*.test.js ./system-test/*.test.js",
"cover": "nyc --reporter=lcov --cache ava -T 5m --verbose test/*.test.js ./system-test/*.test.js && nyc report",
"test": "npm run cover"
"test": "mocha system-test/*.js --timeout 600000"
},
"dependencies": {
"@google-cloud/spanner": "^2.1.0",
Expand Down
2 changes: 2 additions & 0 deletions samples/system-test/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
env:
mocha: true
rules:
node/no-unpublished-require: off
node/no-unsupported-features: off
Expand Down
67 changes: 34 additions & 33 deletions samples/system-test/quickstart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,43 @@

const proxyquire = require(`proxyquire`).noPreserveCache();
const sinon = require(`sinon`);
const test = require(`ava`);
const assert = require(`assert`);
const tools = require(`@google-cloud/nodejs-repo-tools`);

test.before(tools.stubConsole);
test.after.always(tools.restoreConsole);
describe('QuickStart', () => {
before(() => tools.stubConsole);
nareshqlogic marked this conversation as resolved.
Show resolved Hide resolved
after(() => tools.restoreConsole);

test.cb(`should query a table`, t => {
const databaseMock = {
run: _query => {
t.deepEqual(_query, {
sql: `SELECT 1`,
});
setTimeout(() => {
try {
t.deepEqual(console.log.getCall(0).args, [`test`]);
t.end();
} catch (err) {
t.end(err);
}
}, 200);
return Promise.resolve([['test']]);
},
};
const instanceMock = {
database: sinon.stub().returns(databaseMock),
};
const spannerMock = {
instance: sinon.stub().returns(instanceMock),
};
it(`should query a table`, async () => {
const databaseMock = {
run: async _query => {
assert.deepStrictEqual(_query, {
sql: `SELECT 1`,
});

proxyquire(`../quickstart`, {
'@google-cloud/spanner': {
Spanner: sinon.stub().returns(spannerMock),
},
});
await new Promise(r => setTimeout(r, 200));
assert.deepStrictEqual(console.log.getCall(0).args, [`test`]);
return [['test']];
},
};
const instanceMock = {
database: sinon.stub().returns(databaseMock),
};
const spannerMock = {
instance: sinon.stub().returns(instanceMock),
};

proxyquire(`../quickstart`, {
'@google-cloud/spanner': {
Spanner: sinon.stub().returns(spannerMock),
},
});

t.deepEqual(spannerMock.instance.getCall(0).args, [`my-instance`]);
t.deepEqual(instanceMock.database.getCall(0).args, [`my-database`]);
assert.deepStrictEqual(spannerMock.instance.getCall(0).args, [
`my-instance`,
]);
assert.deepStrictEqual(instanceMock.database.getCall(0).args, [
`my-database`,
]);
});
});
Loading