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: modernize the sample tests #237

Merged
merged 1 commit into from
Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 8 additions & 6 deletions samples/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"name": "nodejs-docs-samples-logging-bunyan",
"files": ["*.js"],
"files": [
"*.js"
],
"private": true,
"license": "Apache-2.0",
"author": "Google Inc.",
Expand All @@ -9,20 +11,20 @@
"node": ">=8"
},
"scripts": {
"test": "mocha system-test/*.js --timeout 600000"
"test": "mocha system-test --timeout 600000"
},
"dependencies": {
"@google-cloud/logging-bunyan": "^0.9.5",
"express": "^4.16.3",
"bunyan": "^1.8.12",
"express": "^4.16.3",
"yargs": "^12.0.0"
},
"devDependencies": {
"@google-cloud/logging": "^4.0.0",
"@google-cloud/nodejs-repo-tools": "^3.0.0",
"ava": "^0.25.0",
"chai": "^4.2.0",
"delay": "^4.0.0",
"execa": "^1.0.0",
"got": "^9.0.0"
"got": "^9.4.0",
"mocha": "^5.2.0"
}
}
62 changes: 31 additions & 31 deletions samples/system-test/express.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,43 @@

'use strict';

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

before(tools.checkCredentials);

This comment was marked as spam.

This comment was marked as spam.

after(() => got('http://localhost:8080/shutdown'));

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

it(`should write using bunyan`, async () => {
// Start the express server.
execa(process.execPath, ['express.js'], {
cwd: path.join(__dirname, `..`),
cleanup: true, // kill child process when parent exits.
}).stdout.pipe(process.stdout);

// Wait 10 seconds for initialization and for server to start listening.
await delay(10 * 1000);

// Make an HTTP request to exercise a request logging path.
await got('http://localhost:8080/');

// Wait 10 seconds for logs to be written to stackdriver service.
await delay(10 * 1000);

// 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];
assert.strictEqual(entries.length, 1);
const entry = entries[0];
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\/.*/));
describe('express samples', () => {
it('should write using bunyan', async () => {
// Start the express server.
execa(process.execPath, ['express.js'], {
cwd: path.join(__dirname, '..'),
cleanup: true, // kill child process when parent exits.
}).stdout.pipe(process.stdout);

// Wait 10 seconds for initialization and for server to start listening.
await delay(10 * 1000);

// Make an HTTP request to exercise a request logging path.
await got('http://localhost:8080/');

// Wait 10 seconds for logs to be written to stackdriver service.
await delay(10 * 1000);

// 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];
assert.strictEqual(entries.length, 1);
const entry = entries[0];
assert.strictEqual('this is an info log message', entry.data.message);
assert.ok(entry.metadata.trace, 'should have a trace property');
assert.match(entry.metadata.trace, /projects\/.*\/traces\/.*/);
});
});
19 changes: 9 additions & 10 deletions samples/system-test/quickstart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@

'use strict';

const path = require(`path`);
const assert = require(`assert`);
const tools = require(`@google-cloud/nodejs-repo-tools`);
const path = require('path');
const {assert} = require('chai');
const execa = require('execa');

before(tools.checkCredentials);
const cwd = path.join(__dirname, '..');

it(`should write using bunyan`, async () => {
const output = await tools.runAsync(
`node quickstart.js`,
path.join(__dirname, `..`)
);
assert.strictEqual(output.includes('99%'), true);
describe('quickstart samples', () => {
it('should write using bunyan', async () => {
const {stdout} = await execa.shell('node quickstart.js', {cwd});
assert.match(stdout, /99%/);
});
});