Skip to content

Commit

Permalink
Complete code migration (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicKramer authored and Ace Nassri committed Nov 11, 2022
1 parent a376783 commit 507c61e
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 37 deletions.
3 changes: 3 additions & 0 deletions error-reporting/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
rules:
no-console: off
30 changes: 7 additions & 23 deletions error-reporting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,29 @@
"private": true,
"license": "Apache-2.0",
"author": "Google Inc.",
"repository": {
"type": "git",
"url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
},
"repository": "googleapis/nodejs-error-reporting",
"engines": {
"node": ">=4.3.2"
},
"scripts": {
"lint": "samples lint",
"pretest": "npm run lint",
"ava": "ava -T 20s --verbose test/*.test.js system-test/*.test.js",
"cover": "nyc --reporter=lcov --cache ava -T 20s --verbose test/*.test.js system-test/*.test.js && nyc report",
"error-test": "samples test app --msg \"Something broke!\" --url \"http://localhost:33332/error\" --port 33332 -- snippets.js express",
"exception-test": "samples test app --code 500 --msg SyntaxError --url \"http://localhost:33333/exception\" --port 33333 -- snippets.js express",
"system-test": "ava -T 1m --verbose system-test/*.test.js",
"all-test": "npm run system-test && npm run error-test && npm run exception-test",
"test": "samples test run --cmd npm -- run all-test"
"test": "repo-tools test run --cmd npm -- run cover"
},
"dependencies": {
"@google-cloud/error-reporting": "0.2.1",
"express": "4.15.4",
"yargs": "8.0.2"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "1.4.17",
"ava": "0.21.0",
"@google-cloud/nodejs-repo-tools": "2.1.0",
"ava": "0.23.0",
"nyc": "11.2.1",
"proxyquire": "1.8.0",
"sinon": "3.2.0"
},
"cloud-repo-tools": {
"requiresKeyFile": true,
"requiresProjectId": true,
"product": "error_reporting",
"samples": [
{
"id": "snippets",
"name": "Examples",
"file": "snippets.js",
"docs_link": "https://cloud.google.com/error-reporting/docs",
"usage": "node snippets.js --help"
}
]
}
}
30 changes: 30 additions & 0 deletions error-reporting/quickstart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright 2017, Google, Inc.
* 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';

// eslint-disable-next-line no-unused-vars
function quickstart() {
// [START error_reporting_quickstart]
// Imports the Google Cloud client library
const ErrorReporting = require('@google-cloud/error-reporting');

// Instantiates a client
const errors = ErrorReporting();

// Reports a simple error
errors.report('Something broke!');
// [END error_reporting_quickstart]
}
50 changes: 38 additions & 12 deletions error-reporting/snippets.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

'use strict';

function setupImplicit () {
function setupImplicit() {
// [START error_reporting_setup_implicit]
// Imports the Google Cloud client library
const ErrorReporting = require('@google-cloud/error-reporting');
Expand All @@ -28,23 +28,23 @@ function setupImplicit () {
// [END error_reporting_setup_implicit]
}

function setupExplicit () {
function setupExplicit() {
// [START error_reporting_setup_explicit]
// Imports the Google Cloud client library
const ErrorReporting = require('@google-cloud/error-reporting');

// Instantiates a client
const errors = ErrorReporting({
projectId: 'your-project-id',
keyFilename: '/path/to/key.json'
keyFilename: '/path/to/key.json',
});

// Reports a simple error
errors.report('Something broke!');
// [END error_reporting_setup_explicit]
}

function manual () {
function manual() {
// [START error_reporting_manual]
// Imports the Google Cloud client library
const ErrorReporting = require('@google-cloud/error-reporting');
Expand Down Expand Up @@ -76,7 +76,7 @@ function manual () {
// [END error_reporting_manual]
}

function express () {
function express() {
// [START error_reporting_express]
const express = require('express');

Expand Down Expand Up @@ -112,17 +112,43 @@ function express () {
// The command-line program
const cli = require(`yargs`)
.demand(1)
.command('setup-implicit', 'Reports a simple error using implicit credentials.', {}, setupImplicit)
.command('setup-explicit', 'Reports a simple error using explicit credentials.', {}, setupExplicit)
.command(
'setup-implicit',
'Reports a simple error using implicit credentials.',
{},
setupImplicit
)
.command(
'setup-explicit',
'Reports a simple error using explicit credentials.',
{},
setupExplicit
)
.command('manual', 'Manually reports errors.', {}, manual)
.command('express', 'Starts and Express service with integrated error reporting.', {}, express)
.example('node $0 setup-implicit', 'Reports a simple error using implicit credentials.')
.example('node $0 setup-explicit', 'Reports a simple error using explicit credentials.')
.command(
'express',
'Starts and Express service with integrated error reporting.',
{},
express
)
.example(
'node $0 setup-implicit',
'Reports a simple error using implicit credentials.'
)
.example(
'node $0 setup-explicit',
'Reports a simple error using explicit credentials.'
)
.example('node $0 manual', 'Manually report some errors.')
.example('node $0 express', 'Starts and Express service with integrated error reporting.')
.example(
'node $0 express',
'Starts and Express service with integrated error reporting.'
)
.wrap(120)
.recommendCommands()
.epilogue(`For more information, see https://cloud.google.com/error-reporting/docs`)
.epilogue(
`For more information, see https://cloud.google.com/error-reporting/docs`
)
.help()
.strict();

Expand Down
5 changes: 5 additions & 0 deletions error-reporting/system-test/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
rules:
node/no-unpublished-require: off
node/no-unsupported-features: off
no-empty: off
4 changes: 2 additions & 2 deletions error-reporting/system-test/snippets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ const cmd = `node snippets.js`;

test.before(tools.checkCredentials);

test.serial(`should setup using implicit credentials`, async (t) => {
test.serial(`should setup using implicit credentials`, async t => {
t.plan(0);
// There's no output, the command should just succeed
await tools.runAsync(`${cmd} setup-implicit`, cwd);
});

test.serial(`should report errors manually`, async (t) => {
test.serial(`should report errors manually`, async t => {
const output = await tools.runAsync(`${cmd} manual`, cwd);
t.is(output.includes('Done reporting error event!'), true);
t.is(output.includes('Done reporting Error object!'), true);
Expand Down

0 comments on commit 507c61e

Please sign in to comment.