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

Commit 50abf1d

Browse files
test: add smoke test for app sample (#663)
1 parent b079085 commit 50abf1d

File tree

3 files changed

+57
-28
lines changed

3 files changed

+57
-28
lines changed

samples/app.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,8 @@ app.get('/', (req, res) => {
2828
});
2929

3030
// Start the server
31-
if (module === require.main) {
32-
const PORT = process.env.PORT || 8080;
33-
app.listen(PORT, () => {
34-
console.log(`App listening on port ${PORT}`);
35-
console.log('Press Ctrl+C to quit.');
36-
});
37-
}
38-
39-
module.exports = app;
31+
const PORT = process.env.PORT || 8080;
32+
app.listen(PORT, () => {
33+
console.log(`App listening on port ${PORT}`);
34+
console.log('Press Ctrl+C to quit.');
35+
});

samples/package.json

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,24 @@
11
{
22
"name": "nodejs-docs-samples-debugger",
33
"description": "Sample for Google Stackdriver Trace on Google App Engine Flexible Environment.",
4-
"version": "0.0.1",
54
"private": true,
65
"license": "Apache-2.0",
7-
"author": "Google Inc.",
8-
"repository": {
9-
"type": "git",
10-
"url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
11-
},
6+
"author": "Google LLC",
7+
"repository": "googleapis/cloud-debug-nodejs",
128
"engines": {
139
"node": ">=8"
1410
},
1511
"scripts": {
1612
"deploy": "gcloud app deploy",
1713
"start": "node app.js",
18-
"system-test": "repo-tools test app",
19-
"test": "npm run system-test",
20-
"e2e-test": "repo-tools test deploy"
14+
"test": "mocha"
2115
},
2216
"dependencies": {
2317
"@google-cloud/debug-agent": "^3.1.0",
2418
"express": "4.16.4"
2519
},
2620
"devDependencies": {
27-
"@google-cloud/nodejs-repo-tools": "^3.0.0",
21+
"execa": "^1.0.0",
2822
"mocha": "^6.0.0"
29-
},
30-
"cloud-repo-tools": {
31-
"test": {
32-
"app": {
33-
"msg": "Hello, world!"
34-
}
35-
},
36-
"requiresKeyFile": true,
37-
"requiresProjectId": true
3823
}
3924
}

samples/test/test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Copyright 2019, Google, LLC.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
'use strict';
17+
18+
const execa = require('execa');
19+
20+
describe('debug samples', () => {
21+
22+
it('should run the quickstart', done => {
23+
// select a random port between 49152 and 65535
24+
const PORT = Math.floor((Math.random() * (65535-49152))) + 49152;
25+
const proc = execa('node', ['app.js'], {
26+
env: {
27+
PORT
28+
}
29+
});
30+
proc.stdout.on('data', message => {
31+
// Listen to stdout and look for messages. If we get a `Press CTRL+...`
32+
// assume the process started. Wait a second to make sure there
33+
// is no stderr output signifying something may have gone wrong.
34+
message = message.toString('utf8');
35+
if (/Press Ctrl/.test(message)) {
36+
setTimeout(() => {
37+
proc.kill();
38+
done();
39+
}, 1000);
40+
}
41+
})
42+
proc.stderr.on('data', message => {
43+
// if anything comes through stderr, assume a bug
44+
done(new Error(message.toString('utf8')));
45+
});
46+
});
47+
48+
});

0 commit comments

Comments
 (0)