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: convert samples test from ava to mocha #190

Merged
merged 9 commits into from
Nov 16, 2018
3 changes: 1 addition & 2 deletions samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"node": ">=8"
},
"scripts": {
"system-test": "ava -T 1m --verbose system-test/*.test.js",
"test": "npm run system-test"
"test": "mocha system-test/*.js --timeout 600000"
},
"dependencies": {
"@google-cloud/logging-bunyan": "^0.9.4",
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
17 changes: 7 additions & 10 deletions samples/system-test/express.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,19 @@
'use strict';

const path = require(`path`);
const test = require(`ava`);
const assert = require(`assert`);
const tools = require(`@google-cloud/nodejs-repo-tools`);
const execa = require(`execa`);
const delay = require(`delay`);
const {Logging} = require('@google-cloud/logging');
const logging = new Logging();
const got = require('got');

before(tools.checkCredentials);
const lb = require('@google-cloud/logging-bunyan');
const {APP_LOG_SUFFIX} = lb.express;

test.before(tools.checkCredentials);

test.serial(`should write using bunyan`, async t => {
t.plan(4);

it(`should write using bunyan`, async () => {
// Start the express server.
execa(process.execPath, ['express.js'], {
cwd: path.join(__dirname, `..`),
Expand All @@ -50,9 +47,9 @@ test.serial(`should write using bunyan`, async t => {
// Make sure the log was written to Stackdriver Logging.
const log = logging.log(`samples_express_${APP_LOG_SUFFIX}`);
const entries = (await log.getEntries({pageSize: 1}))[0];
t.is(entries.length, 1);
assert.strictEqual(entries.length, 1);
const entry = entries[0];
t.is('this is an info log message', entry.data.message);
t.truthy(entry.metadata.trace, 'should have a trace property');
t.truthy(entry.metadata.trace.match(/projects\/.*\/traces\/.*/));
assert.strictEqual('this is an info log message', entry.data.message);
assert.ok(entry.metadata.trace, 'should have a trace property');
assert.ok(entry.metadata.trace.match(/projects\/.*\/traces\/.*/));
});
8 changes: 4 additions & 4 deletions samples/system-test/quickstart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
'use strict';

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

test.before(tools.checkCredentials);
before(tools.checkCredentials);

test.serial(`should write using bunyan`, async t => {
it(`should write using bunyan`, async () => {
const output = await tools.runAsync(
`node quickstart.js`,
path.join(__dirname, `..`)
);
t.is(output.includes('99%'), true);
assert.strictEqual(output.includes('99%'), true);
});