Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

test: add smoke test for app sample #663

Merged
merged 2 commits into from
Apr 4, 2019
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: 5 additions & 9 deletions samples/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,8 @@ app.get('/', (req, res) => {
});

// Start the server
if (module === require.main) {
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log(`App listening on port ${PORT}`);
console.log('Press Ctrl+C to quit.');
});
}

module.exports = app;
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log(`App listening on port ${PORT}`);
console.log('Press Ctrl+C to quit.');
});
23 changes: 4 additions & 19 deletions samples/package.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,24 @@
{
"name": "nodejs-docs-samples-debugger",
"description": "Sample for Google Stackdriver Trace on Google App Engine Flexible Environment.",
"version": "0.0.1",
"private": true,
"license": "Apache-2.0",
"author": "Google Inc.",
"repository": {
"type": "git",
"url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
},
"author": "Google LLC",
"repository": "googleapis/cloud-debug-nodejs",
"engines": {
"node": ">=8"
},
"scripts": {
"deploy": "gcloud app deploy",
"start": "node app.js",
"system-test": "repo-tools test app",
"test": "npm run system-test",
"e2e-test": "repo-tools test deploy"
"test": "mocha"
},
"dependencies": {
"@google-cloud/debug-agent": "^3.1.0",
"express": "4.16.4"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "^3.0.0",
"execa": "^1.0.0",
"mocha": "^6.0.0"
},
"cloud-repo-tools": {
"test": {
"app": {
"msg": "Hello, world!"
}
},
"requiresKeyFile": true,
"requiresProjectId": true
}
}
48 changes: 48 additions & 0 deletions samples/test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Copyright 2019, Google, LLC.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

const execa = require('execa');

describe('debug samples', () => {

it('should run the quickstart', done => {
// select a random port between 49152 and 65535
const PORT = Math.floor((Math.random() * (65535-49152))) + 49152;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a difference in style, I'd usually just pick a port and use it consistently for integration tests (I'd rather know that I'm not shutting down cleanly via failure to bind).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In retrospect, that's probably going to be fine too. Initially I was worried about the same tests running in parallel, but it doesn't matter since they're almost always in docker containers that should abstract it from us.

const proc = execa('node', ['app.js'], {
env: {
PORT
}
});
proc.stdout.on('data', message => {
// Listen to stdout and look for messages. If we get a `Press CTRL+...`
// assume the process started. Wait a second to make sure there
// is no stderr output signifying something may have gone wrong.
message = message.toString('utf8');
if (/Press Ctrl/.test(message)) {
setTimeout(() => {
proc.kill();
done();
}, 1000);
}
})
proc.stderr.on('data', message => {
// if anything comes through stderr, assume a bug
done(new Error(message.toString('utf8')));
});
});

});