From 507c61ee12e38f2d10af9189bf6679195b989563 Mon Sep 17 00:00:00 2001 From: Dominic Kramer Date: Fri, 22 Dec 2017 15:39:29 -0800 Subject: [PATCH] Complete code migration (#18) --- error-reporting/.eslintrc.yml | 3 ++ error-reporting/package.json | 30 +++--------- error-reporting/quickstart.js | 30 ++++++++++++ error-reporting/snippets.js | 50 +++++++++++++++----- error-reporting/system-test/.eslintrc.yml | 5 ++ error-reporting/system-test/snippets.test.js | 4 +- 6 files changed, 85 insertions(+), 37 deletions(-) create mode 100644 error-reporting/.eslintrc.yml create mode 100644 error-reporting/quickstart.js create mode 100644 error-reporting/system-test/.eslintrc.yml diff --git a/error-reporting/.eslintrc.yml b/error-reporting/.eslintrc.yml new file mode 100644 index 0000000000..282535f55f --- /dev/null +++ b/error-reporting/.eslintrc.yml @@ -0,0 +1,3 @@ +--- +rules: + no-console: off diff --git a/error-reporting/package.json b/error-reporting/package.json index 0c5fb6d054..62e07f22fb 100644 --- a/error-reporting/package.json +++ b/error-reporting/package.json @@ -4,21 +4,18 @@ "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", @@ -26,23 +23,10 @@ "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" - } - ] } } diff --git a/error-reporting/quickstart.js b/error-reporting/quickstart.js new file mode 100644 index 0000000000..b938e3d580 --- /dev/null +++ b/error-reporting/quickstart.js @@ -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] +} diff --git a/error-reporting/snippets.js b/error-reporting/snippets.js index 3ee41a85f9..9f8bc7b300 100644 --- a/error-reporting/snippets.js +++ b/error-reporting/snippets.js @@ -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'); @@ -28,7 +28,7 @@ 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'); @@ -36,7 +36,7 @@ function setupExplicit () { // Instantiates a client const errors = ErrorReporting({ projectId: 'your-project-id', - keyFilename: '/path/to/key.json' + keyFilename: '/path/to/key.json', }); // Reports a simple error @@ -44,7 +44,7 @@ function setupExplicit () { // [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'); @@ -76,7 +76,7 @@ function manual () { // [END error_reporting_manual] } -function express () { +function express() { // [START error_reporting_express] const express = require('express'); @@ -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(); diff --git a/error-reporting/system-test/.eslintrc.yml b/error-reporting/system-test/.eslintrc.yml new file mode 100644 index 0000000000..c0289282a6 --- /dev/null +++ b/error-reporting/system-test/.eslintrc.yml @@ -0,0 +1,5 @@ +--- +rules: + node/no-unpublished-require: off + node/no-unsupported-features: off + no-empty: off diff --git a/error-reporting/system-test/snippets.test.js b/error-reporting/system-test/snippets.test.js index c830419619..b5b4088c6b 100644 --- a/error-reporting/system-test/snippets.test.js +++ b/error-reporting/system-test/snippets.test.js @@ -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);