diff --git a/appengine/building-an-app/update/package.json b/appengine/building-an-app/update/package.json index 5fe5940176..161d10f12b 100644 --- a/appengine/building-an-app/update/package.json +++ b/appengine/building-an-app/update/package.json @@ -24,6 +24,7 @@ }, "devDependencies": { "@google-cloud/nodejs-repo-tools": "^3.3.0", - "mocha": "^7.0.0" + "mocha": "^7.0.0", + "sinon": "^8.0.0" } } diff --git a/appengine/building-an-app/update/test/server.test.js b/appengine/building-an-app/update/test/server.test.js index 5729916a82..5baf2b73e3 100755 --- a/appengine/building-an-app/update/test/server.test.js +++ b/appengine/building-an-app/update/test/server.test.js @@ -16,6 +16,7 @@ const path = require('path'); const assert = require('assert'); const utils = require('@google-cloud/nodejs-repo-tools'); +const sinon = require('sinon'); const cwd = path.join(__dirname, '../'); const requestObj = utils.getRequest({ @@ -23,8 +24,26 @@ const requestObj = utils.getRequest({ cmd: 'server', }); -beforeEach(utils.stubConsole); -afterEach(utils.restoreConsole); +const stubConsole = function() { + sinon.stub(console, `error`); + sinon.stub(console, `log`).callsFake((a, b) => { + if ( + typeof a === `string` && + a.indexOf(`\u001b`) !== -1 && + typeof b === `string` + ) { + console.log.apply(console, arguments); + } + }); +}; + +const restoreConsole = function() { + console.log.restore(); + console.error.restore(); +}; + +beforeEach(stubConsole); +afterEach(restoreConsole); it('should send greetings', async () => { await requestObj diff --git a/appengine/cloudsql/test/createTables.test.js b/appengine/cloudsql/test/createTables.test.js index 9d69512fac..43a88f5049 100644 --- a/appengine/cloudsql/test/createTables.test.js +++ b/appengine/cloudsql/test/createTables.test.js @@ -18,7 +18,6 @@ const assert = require('assert'); const path = require('path'); const proxyquire = require('proxyquire').noPreserveCache(); const sinon = require('sinon'); -const tools = require('@google-cloud/nodejs-repo-tools'); const SAMPLE_PATH = path.join(__dirname, '../createTables.js'); @@ -57,8 +56,27 @@ const getSample = () => { }; }; -beforeEach(tools.stubConsole); -afterEach(tools.restoreConsole); +const stubConsole = function() { + /* eslint-disable no-console */ + sinon.stub(console, `error`); + sinon.stub(console, `log`).callsFake((a, b) => { + if ( + typeof a === `string` && + a.indexOf(`\u001b`) !== -1 && + typeof b === `string` + ) { + console.log.apply(console, arguments); + } + }); +}; + +const restoreConsole = function() { + console.log.restore(); + console.error.restore(); +}; + +beforeEach(stubConsole); +afterEach(restoreConsole); describe('gae_flex_mysql_create_tables', () => { it('should create a table', async () => { diff --git a/appengine/cloudsql/test/server.test.js b/appengine/cloudsql/test/server.test.js index c4fb6a48c7..a1e0205284 100644 --- a/appengine/cloudsql/test/server.test.js +++ b/appengine/cloudsql/test/server.test.js @@ -20,7 +20,6 @@ const proxyquire = require('proxyquire').noCallThru(); const request = require('supertest'); const sinon = require('sinon'); const assert = require('assert'); -const tools = require('@google-cloud/nodejs-repo-tools'); const SAMPLE_PATH = path.join(__dirname, '../server.js'); @@ -73,9 +72,6 @@ const getSample = () => { }; }; -beforeEach(tools.stubConsole); -afterEach(tools.restoreConsole); - describe('gae_flex_mysql_connect', () => { it('should set up sample in Postgres', () => { const sample = getSample(); diff --git a/appengine/cloudsql_postgresql/test/createTables.test.js b/appengine/cloudsql_postgresql/test/createTables.test.js index a7c87d0ede..296646cc76 100644 --- a/appengine/cloudsql_postgresql/test/createTables.test.js +++ b/appengine/cloudsql_postgresql/test/createTables.test.js @@ -18,7 +18,6 @@ const assert = require('assert'); const path = require('path'); const proxyquire = require('proxyquire').noPreserveCache(); const sinon = require('sinon'); -const tools = require('@google-cloud/nodejs-repo-tools'); const SAMPLE_PATH = path.join(__dirname, '../createTables.js'); @@ -57,8 +56,26 @@ const getSample = () => { }; }; -beforeEach(tools.stubConsole); -afterEach(tools.restoreConsole); +const stubConsole = function() { + sinon.stub(console, `error`); + sinon.stub(console, `log`).callsFake((a, b) => { + if ( + typeof a === `string` && + a.indexOf(`\u001b`) !== -1 && + typeof b === `string` + ) { + console.log.apply(console, arguments); + } + }); +}; + +const restoreConsole = function() { + console.log.restore(); + console.error.restore(); +}; + +beforeEach(stubConsole); +afterEach(restoreConsole); describe('gae_flex_postgres_create_tables', () => { it('should create a table', async () => { diff --git a/appengine/cloudsql_postgresql/test/server.test.js b/appengine/cloudsql_postgresql/test/server.test.js index 43cb56fc37..b34c8541d9 100644 --- a/appengine/cloudsql_postgresql/test/server.test.js +++ b/appengine/cloudsql_postgresql/test/server.test.js @@ -20,7 +20,6 @@ const proxyquire = require('proxyquire').noCallThru(); const request = require('supertest'); const sinon = require('sinon'); const assert = require('assert'); -const tools = require('@google-cloud/nodejs-repo-tools'); const SAMPLE_PATH = path.join(__dirname, '../server.js'); @@ -73,9 +72,6 @@ const getSample = () => { }; }; -beforeEach(tools.stubConsole); -afterEach(tools.restoreConsole); - it('gae_flex_postgres_connect should set up sample in Postgres', () => { const sample = getSample(); diff --git a/appengine/endpoints/test/app.test.js b/appengine/endpoints/test/app.test.js index 24349d434c..d88e2d7ead 100644 --- a/appengine/endpoints/test/app.test.js +++ b/appengine/endpoints/test/app.test.js @@ -20,7 +20,6 @@ const proxyquire = require('proxyquire').noCallThru(); const request = require('supertest'); const sinon = require('sinon'); const assert = require('assert'); -const tools = require('@google-cloud/nodejs-repo-tools'); const SAMPLE_PATH = path.join(__dirname, '../app.js'); @@ -39,8 +38,16 @@ const getSample = () => { }; }; -beforeEach(tools.stubConsole); -afterEach(tools.restoreConsole); +const stubConsole = function() { + sinon.stub(console, `error`); +}; + +const restoreConsole = function() { + console.error.restore(); +}; + +beforeEach(stubConsole); +afterEach(restoreConsole); it(`sets up the sample`, done => { const sample = getSample(); diff --git a/endpoints/getting-started/test/app.test.js b/endpoints/getting-started/test/app.test.js index 68651a47e0..e6bb81567e 100644 --- a/endpoints/getting-started/test/app.test.js +++ b/endpoints/getting-started/test/app.test.js @@ -20,7 +20,6 @@ const proxyquire = require('proxyquire').noPreserveCache(); const request = require('supertest'); const sinon = require('sinon'); const assert = require('assert'); -const tools = require('@google-cloud/nodejs-repo-tools'); const SAMPLE_PATH = path.join(__dirname, '../app.js'); @@ -40,8 +39,17 @@ const getSample = () => { }; }; -beforeEach(tools.stubConsole); -afterEach(tools.restoreConsole); +const stubConsole = function() { + sinon.stub(console, `error`); +}; + +//Restore console +const restoreConsole = function() { + console.error.restore(); +}; + +beforeEach(stubConsole); +afterEach(restoreConsole); it('should echo a message', async () => { await request(getSample().app) diff --git a/functions/firebase/test/index.test.js b/functions/firebase/test/index.test.js index c09956b569..e0d6e5973f 100644 --- a/functions/firebase/test/index.test.js +++ b/functions/firebase/test/index.test.js @@ -17,7 +17,6 @@ const proxyquire = require('proxyquire').noCallThru(); const sinon = require('sinon'); const assert = require('assert'); -const tools = require('@google-cloud/nodejs-repo-tools'); const getSample = () => { const firestoreMock = { @@ -35,8 +34,26 @@ const getSample = () => { }; }; -beforeEach(tools.stubConsole); -afterEach(tools.restoreConsole); +const stubConsole = function() { + sinon.stub(console, `error`); + sinon.stub(console, `log`).callsFake((a, b) => { + if ( + typeof a === `string` && + a.indexOf(`\u001b`) !== -1 && + typeof b === `string` + ) { + console.log.apply(console, arguments); + } + }); +}; + +const restoreConsole = function() { + console.log.restore(); + console.error.restore(); +}; + +beforeEach(stubConsole); +afterEach(restoreConsole); describe('functions_firebase_rtdb', () => { it('should listen to RTDB', () => { diff --git a/functions/helloworld/test/index.test.js b/functions/helloworld/test/index.test.js index 69a721769e..3c8ded05c4 100644 --- a/functions/helloworld/test/index.test.js +++ b/functions/helloworld/test/index.test.js @@ -201,12 +201,8 @@ describe('index.test.js', () => { describe('functions_helloworld_error', () => { describe('Error handling (unit tests)', () => { - // Silence dummy console calls in the samples - before(tools.stubConsole); - after(tools.restoreConsole); - it('helloError: should throw an error', () => { - assert.throws(program.helloError, 'I failed you'); + assert.throws(program.helloError, 'Error: I failed you'); }); it('helloError2: should throw a value', () => { diff --git a/functions/helloworld/test/sample.unit.pubsub.test.js b/functions/helloworld/test/sample.unit.pubsub.test.js index 6f85dff52f..3b40918f0e 100644 --- a/functions/helloworld/test/sample.unit.pubsub.test.js +++ b/functions/helloworld/test/sample.unit.pubsub.test.js @@ -17,11 +17,31 @@ describe('functions_helloworld_pubsub', () => { const assert = require('assert'); const uuid = require('uuid'); const utils = require('@google-cloud/nodejs-repo-tools'); + const sinon = require('sinon'); const {helloPubSub} = require('..'); - beforeEach(utils.stubConsole); - afterEach(utils.restoreConsole); + const stubConsole = function() { + sinon.stub(console, `error`); + sinon.stub(console, `log`).callsFake((a, b) => { + if ( + typeof a === `string` && + a.indexOf(`\u001b`) !== -1 && + typeof b === `string` + ) { + console.log('e'); + console.log.apply(console, arguments); + } + }); + }; + + const restoreConsole = function() { + console.log.restore(); + console.error.restore(); + }; + + beforeEach(stubConsole); + afterEach(restoreConsole); it('helloPubSub: should print a name', () => { // Create mock Pub/Sub event diff --git a/functions/helloworld/test/sample.unit.storage.test.js b/functions/helloworld/test/sample.unit.storage.test.js index db51eee2f0..01cf6d3cea 100644 --- a/functions/helloworld/test/sample.unit.storage.test.js +++ b/functions/helloworld/test/sample.unit.storage.test.js @@ -17,11 +17,31 @@ describe('functions_helloworld_storage', () => { const assert = require('assert'); const uuid = require('uuid'); const utils = require('@google-cloud/nodejs-repo-tools'); + const sinon = require('sinon'); const {helloGCS} = require('..'); - beforeEach(utils.stubConsole); - afterEach(utils.restoreConsole); + const stubConsole = function() { + sinon.stub(console, `error`); + sinon.stub(console, `log`).callsFake((a, b) => { + if ( + typeof a === `string` && + a.indexOf(`\u001b`) !== -1 && + typeof b === `string` + ) { + console.log('e'); + console.log.apply(console, arguments); + } + }); + }; + + const restoreConsole = function() { + console.log.restore(); + console.error.restore(); + }; + + beforeEach(stubConsole); + afterEach(restoreConsole); it('helloGCS: should print uploaded message', () => { // Initialize mocks diff --git a/functions/http/test/index.test.js b/functions/http/test/index.test.js index 3d783c629c..2b404064a5 100644 --- a/functions/http/test/index.test.js +++ b/functions/http/test/index.test.js @@ -18,7 +18,6 @@ const proxyquire = require('proxyquire').noCallThru(); const sinon = require('sinon'); const assert = require('assert'); const uuid = require('uuid'); -const tools = require('@google-cloud/nodejs-repo-tools'); const getSample = () => { const requestPromise = sinon @@ -66,8 +65,16 @@ const getMocks = () => { }; }; -beforeEach(tools.stubConsole); -afterEach(tools.restoreConsole); +const stubConsole = function() { + sinon.stub(console, `error`); +}; + +const restoreConsole = function() { + console.error.restore(); +}; + +beforeEach(stubConsole); +afterEach(restoreConsole); describe('functions_http_method', () => { it('http:helloHttp: should handle GET', () => { diff --git a/functions/imagemagick/test/index.test.js b/functions/imagemagick/test/index.test.js index 0676438117..1f66ae9f2e 100644 --- a/functions/imagemagick/test/index.test.js +++ b/functions/imagemagick/test/index.test.js @@ -15,10 +15,10 @@ 'use strict'; const assert = require('assert'); -const tools = require('@google-cloud/nodejs-repo-tools'); const execPromise = require('child-process-promise').exec; const path = require('path'); const {Storage} = require('@google-cloud/storage'); +const sinon = require('sinon'); const storage = new Storage(); @@ -83,8 +83,16 @@ describe('functions/imagemagick tests', () => { }; }); - beforeEach(tools.stubConsole); - afterEach(tools.restoreConsole); + const stubConsole = function() { + sinon.stub(console, `error`); + }; + + const restoreConsole = function() { + console.error.restore(); + }; + + beforeEach(stubConsole); + afterEach(restoreConsole); describe('functions_imagemagick_analyze', () => { it('blurOffensiveImages detects safe images using Cloud Vision', async () => { diff --git a/functions/log/test/index.test.js b/functions/log/test/index.test.js index 0f182fd57f..9741031d99 100644 --- a/functions/log/test/index.test.js +++ b/functions/log/test/index.test.js @@ -17,7 +17,6 @@ const proxyquire = require('proxyquire').noCallThru(); const sinon = require('sinon'); const assert = require('assert'); -const tools = require('@google-cloud/nodejs-repo-tools'); const getSample = () => { const results = [[{}], {}]; @@ -51,8 +50,26 @@ const getSample = () => { }; }; -beforeEach(tools.stubConsole); -afterEach(tools.restoreConsole); +const stubConsole = function() { + sinon.stub(console, `error`); + sinon.stub(console, `log`).callsFake((a, b) => { + if ( + typeof a === `string` && + a.indexOf(`\u001b`) !== -1 && + typeof b === `string` + ) { + console.log.apply(console, arguments); + } + }); +}; + +const restoreConsole = function() { + console.log.restore(); + console.error.restore(); +}; + +beforeEach(stubConsole); +afterEach(restoreConsole); describe('functions_log_helloworld', () => { it('should write to log', () => { diff --git a/functions/node8/test/index.test.js b/functions/node8/test/index.test.js index edf6f5085c..7de96beb04 100644 --- a/functions/node8/test/index.test.js +++ b/functions/node8/test/index.test.js @@ -17,7 +17,6 @@ const sinon = require('sinon'); const uuid = require('uuid'); const assert = require('assert'); -const utils = require('@google-cloud/nodejs-repo-tools'); const proxyquire = require('proxyquire').noCallThru(); const getSample = () => { @@ -40,8 +39,26 @@ const getSample = () => { }; }; -beforeEach(utils.stubConsole); -afterEach(utils.restoreConsole); +const stubConsole = function() { + sinon.stub(console, `error`); + sinon.stub(console, `log`).callsFake((a, b) => { + if ( + typeof a === `string` && + a.indexOf(`\u001b`) !== -1 && + typeof b === `string` + ) { + console.log.apply(console, arguments); + } + }); +}; + +const restoreConsole = function() { + console.log.restore(); + console.error.restore(); +}; + +beforeEach(stubConsole); +afterEach(restoreConsole); it('should respond to HTTP POST', () => { const sample = getSample(); diff --git a/functions/node8/test/sample.unit.pubsub.test.js b/functions/node8/test/sample.unit.pubsub.test.js index 064b3e0692..0f9a4792a4 100644 --- a/functions/node8/test/sample.unit.pubsub.test.js +++ b/functions/node8/test/sample.unit.pubsub.test.js @@ -15,13 +15,8 @@ // [START functions_pubsub_unit_test] const assert = require('assert'); const uuid = require('uuid'); -const utils = require('@google-cloud/nodejs-repo-tools'); - const {helloPubSub} = require('..'); -beforeEach(utils.stubConsole); -afterEach(utils.restoreConsole); - describe('functions_helloworld_pubsub_node8', () => { it('helloPubSub: should print a name', async () => { // Initialize mocks diff --git a/functions/node8/test/sample.unit.storage.test.js b/functions/node8/test/sample.unit.storage.test.js index d262b0ef9d..fe46d210ce 100644 --- a/functions/node8/test/sample.unit.storage.test.js +++ b/functions/node8/test/sample.unit.storage.test.js @@ -15,13 +15,8 @@ // [START functions_storage_unit_test] const assert = require('assert'); const uuid = require('uuid'); -const utils = require('@google-cloud/nodejs-repo-tools'); - const {helloGCS} = require('..'); -beforeEach(utils.stubConsole); -afterEach(utils.restoreConsole); - describe('functions_helloworld_storage_node8', () => { it('helloGCS: should print uploaded message', async () => { // Initialize mocks diff --git a/functions/ocr/app/package.json b/functions/ocr/app/package.json index a4cab9239c..17b7b2718f 100644 --- a/functions/ocr/app/package.json +++ b/functions/ocr/app/package.json @@ -23,7 +23,8 @@ }, "devDependencies": { "@google-cloud/nodejs-repo-tools": "^3.3.0", - "mocha": "^7.0.0" + "mocha": "^7.0.0", + "sinon": "^8.0.0" }, "cloud-repo-tools": { "requiresKeyFile": true, diff --git a/functions/ocr/app/test/index.test.js b/functions/ocr/app/test/index.test.js index 9dd65dd03b..0e7c5a80c8 100644 --- a/functions/ocr/app/test/index.test.js +++ b/functions/ocr/app/test/index.test.js @@ -15,12 +15,11 @@ 'use strict'; const assert = require('assert'); +const sinon = require('sinon'); const {Storage} = require('@google-cloud/storage'); const storage = new Storage(); -const tools = require('@google-cloud/nodejs-repo-tools'); - const bucketName = process.env.FUNCTIONS_BUCKET; const filename = 'wakeupcat.jpg'; const text = 'Wake up human!'; @@ -35,8 +34,26 @@ const errorMsg = (name, propertyName) => { return `${name} not provided. Make sure you have a "${propertyName}" property in your request`; }; -before(tools.stubConsole); -after(tools.restoreConsole); +const stubConsole = function() { + sinon.stub(console, `error`); + sinon.stub(console, `log`).callsFake((a, b) => { + if ( + typeof a === `string` && + a.indexOf(`\u001b`) !== -1 && + typeof b === `string` + ) { + console.log.apply(console, arguments); + } + }); +}; + +const restoreConsole = function() { + console.log.restore(); + console.error.restore(); +}; + +beforeEach(stubConsole); +afterEach(restoreConsole); describe('processImage', () => { describe('functions_ocr_process', () => { diff --git a/functions/pubsub/package.json b/functions/pubsub/package.json index 4f3481ef75..59bde37d4c 100644 --- a/functions/pubsub/package.json +++ b/functions/pubsub/package.json @@ -15,7 +15,8 @@ "test": "mocha test/*.test.js --timeout=20000" }, "dependencies": { - "@google-cloud/pubsub": "^1.0.0" + "@google-cloud/pubsub": "^1.0.0", + "sinon": "^8.0.0" }, "devDependencies": { "@google-cloud/functions-framework": "^1.3.2", diff --git a/functions/pubsub/test/index.test.js b/functions/pubsub/test/index.test.js index e6a24e0795..cd280c00d5 100644 --- a/functions/pubsub/test/index.test.js +++ b/functions/pubsub/test/index.test.js @@ -15,8 +15,8 @@ 'use strict'; const assert = require('assert'); -const tools = require('@google-cloud/nodejs-repo-tools'); const path = require('path'); +const sinon = require('sinon'); const execPromise = require('child-process-promise').exec; const requestRetry = require('requestretry'); @@ -29,8 +29,26 @@ const TOPIC = process.env.FUNCTIONS_TOPIC; const MESSAGE = 'Hello, world!'; describe('functions/pubsub', () => { - beforeEach(tools.stubConsole); - afterEach(tools.restoreConsole); + const stubConsole = function() { + sinon.stub(console, `error`); + sinon.stub(console, `log`).callsFake((a, b) => { + if ( + typeof a === `string` && + a.indexOf(`\u001b`) !== -1 && + typeof b === `string` + ) { + console.log.apply(console, arguments); + } + }); + }; + + //Restore console + const restoreConsole = function() { + console.log.restore(); + console.error.restore(); + }; + beforeEach(stubConsole); + afterEach(restoreConsole); let ffProc; diff --git a/functions/scheduleinstance/test/index.test.js b/functions/scheduleinstance/test/index.test.js index 5f77eaa44a..d0a8ea81bd 100644 --- a/functions/scheduleinstance/test/index.test.js +++ b/functions/scheduleinstance/test/index.test.js @@ -17,7 +17,6 @@ const proxyquire = require('proxyquire').noCallThru(); const sinon = require('sinon'); const assert = require('assert'); -const tools = require('@google-cloud/nodejs-repo-tools'); const getSample = () => { const requestPromise = sinon @@ -47,9 +46,26 @@ const getMocks = () => { callback: callback, }; }; +const stubConsole = function() { + sinon.stub(console, `error`); + sinon.stub(console, `log`).callsFake((a, b) => { + if ( + typeof a === `string` && + a.indexOf(`\u001b`) !== -1 && + typeof b === `string` + ) { + console.log.apply(console, arguments); + } + }); +}; -beforeEach(tools.stubConsole); -afterEach(tools.restoreConsole); +//Restore console +const restoreConsole = function() { + console.log.restore(); + console.error.restore(); +}; +beforeEach(stubConsole); +afterEach(restoreConsole); /** Tests for startInstancePubSub */ describe('functions_start_instance_pubsub', () => { diff --git a/functions/sendgrid/test/index.test.js b/functions/sendgrid/test/index.test.js index 373138ebd6..06e33f5aba 100644 --- a/functions/sendgrid/test/index.test.js +++ b/functions/sendgrid/test/index.test.js @@ -17,7 +17,6 @@ const proxyquire = require('proxyquire').noCallThru(); const sinon = require('sinon'); const assert = require('assert'); -const tools = require('@google-cloud/nodejs-repo-tools'); const method = 'POST'; const key = 'sengrid_key'; @@ -144,9 +143,32 @@ const getMocks = () => { res: res, }; }; +const stubConsole = function() { + if ( + typeof console.log.restore !== `function` && + typeof console.error.restore !== `function` + ) { + sinon.stub(console, `error`); + sinon.stub(console, `log`).callsFake((a, b) => { + if ( + typeof a === `string` && + a.indexOf(`\u001b`) !== -1 && + typeof b === `string` + ) { + console.log.apply(console, arguments); + } + }); + } +}; + +//Restore console +const restoreConsole = function() { + console.log.restore(); + console.error.restore(); +}; -beforeEach(tools.stubConsole); -afterEach(tools.restoreConsole); +beforeEach(stubConsole); +afterEach(restoreConsole); describe('functions_sendgrid_email functions_get_payload functions_sendgrid_get_client', () => { it('Send fails if not a POST request', async () => { diff --git a/functions/slack/test/index.test.js b/functions/slack/test/index.test.js index 1ac55c94f5..92355617f6 100644 --- a/functions/slack/test/index.test.js +++ b/functions/slack/test/index.test.js @@ -17,7 +17,6 @@ const proxyquire = require('proxyquire').noCallThru(); const sinon = require('sinon'); const assert = require('assert'); -const tools = require('@google-cloud/nodejs-repo-tools'); const method = 'POST'; const query = 'giraffe'; @@ -88,8 +87,26 @@ const getMocks = () => { }; }; -beforeEach(tools.stubConsole); -afterEach(tools.restoreConsole); +const stubConsole = function() { + sinon.stub(console, `error`); + sinon.stub(console, `log`).callsFake((a, b) => { + if ( + typeof a === `string` && + a.indexOf(`\u001b`) !== -1 && + typeof b === `string` + ) { + console.log.apply(console, arguments); + } + }); +}; + +//Restore console +const restoreConsole = function() { + console.log.restore(); + console.error.restore(); +}; +beforeEach(stubConsole); +afterEach(restoreConsole); describe('functions_slack_search', () => { it('Send fails if not a POST request', async () => { diff --git a/functions/tips/test/index.test.js b/functions/tips/test/index.test.js index 10a19c99d9..bef0d13260 100644 --- a/functions/tips/test/index.test.js +++ b/functions/tips/test/index.test.js @@ -16,11 +16,28 @@ const sinon = require(`sinon`); const assert = require(`assert`); -const tools = require(`@google-cloud/nodejs-repo-tools`); const sample = require(`../`); -beforeEach(tools.stubConsole); -afterEach(tools.restoreConsole); +const stubConsole = function() { + sinon.stub(console, `error`); + sinon.stub(console, `log`).callsFake((a, b) => { + if ( + typeof a === `string` && + a.indexOf(`\u001b`) !== -1 && + typeof b === `string` + ) { + console.log.apply(console, arguments); + } + }); +}; + +//Restore console +const restoreConsole = function() { + console.log.restore(); + console.error.restore(); +}; +beforeEach(stubConsole); +afterEach(restoreConsole); describe('functions_tips_retry', () => { it('should demonstrate retry behavior for a promise', async () => { diff --git a/storage-transfer/system-test/transfer.test.js b/storage-transfer/system-test/transfer.test.js index c2c4816424..ff1e4e0c86 100644 --- a/storage-transfer/system-test/transfer.test.js +++ b/storage-transfer/system-test/transfer.test.js @@ -18,8 +18,8 @@ const {Storage} = require('@google-cloud/storage'); const storage = new Storage(); const assert = require('assert'); -const tools = require('@google-cloud/nodejs-repo-tools'); const uuid = require('uuid'); +const sinon = require('sinon'); const program = require('../transfer'); @@ -32,6 +32,25 @@ const time = '15:30'; const description = 'this is a test'; const status = 'DISABLED'; +const stubConsole = function stubConsole() { + sinon.stub(console, `error`); + sinon.stub(console, `log`).callsFake((a, b) => { + if ( + typeof a === `string` && + a.indexOf(`\u001b`) !== -1 && + typeof b === `string` + ) { + console.log('e'); + console.log.apply(console, arguments); + } + }); +}; + +const restoreConsole = function restoreConsole() { + console.log.restore(); + console.error.restore(); +}; + before(async () => { assert( process.env.GCLOUD_PROJECT, @@ -42,7 +61,7 @@ before(async () => { `Must set GOOGLE_APPLICATION_CREDENTIALS environment variable!` ); - tools.stubConsole(); + stubConsole(); const bucketOptions = { entity: 'allUsers', @@ -55,7 +74,7 @@ before(async () => { }); after(() => { - tools.restoreConsole(); + restoreConsole(); const bucketOne = storage.bucket(firstBucketName); const bucketTwo = storage.bucket(secondBucketName); try { diff --git a/storage-transfer/test/transfer.test.js b/storage-transfer/test/transfer.test.js index 125e20dc3a..df44f0c7f0 100644 --- a/storage-transfer/test/transfer.test.js +++ b/storage-transfer/test/transfer.test.js @@ -17,7 +17,6 @@ const proxyquire = require('proxyquire').noCallThru(); const sinon = require('sinon'); const assert = require('assert'); -const tools = require('@google-cloud/nodejs-repo-tools'); const srcBucketName = 'foo'; const destBucketName = 'bar'; @@ -75,9 +74,27 @@ const getSample = () => { }, }; }; +const stubConsole = function() { + sinon.stub(console, `error`); + sinon.stub(console, `log`).callsFake((a, b) => { + if ( + typeof a === `string` && + a.indexOf(`\u001b`) !== -1 && + typeof b === `string` + ) { + console.log('e'); + console.log.apply(console, arguments); + } + }); +}; -beforeEach(tools.stubConsole); -afterEach(tools.restoreConsole); +//Restore console +const restoreConsole = function() { + console.log.restore(); + console.error.restore(); +}; +beforeEach(stubConsole); +afterEach(restoreConsole); it('should create a transfer job', () => { const description = 'description';