From 7f77ba3ef46df02aa496c483ea99dfe535d71809 Mon Sep 17 00:00:00 2001 From: Sofia Leon Date: Thu, 5 Mar 2020 16:15:43 -0800 Subject: [PATCH 1/7] save to now --- appengine/building-an-app/update/package.json | 6 +- .../update/test/server.test.js | 77 ++++++------------- 2 files changed, 29 insertions(+), 54 deletions(-) diff --git a/appengine/building-an-app/update/package.json b/appengine/building-an-app/update/package.json index fb6e4196b1..d0eb77191a 100644 --- a/appengine/building-an-app/update/package.json +++ b/appengine/building-an-app/update/package.json @@ -20,11 +20,13 @@ "license": "Apache-2.0", "dependencies": { "body-parser": "^1.18.2", - "express": "^4.16.3" + "express": "^4.16.3", + "nock": "^12.0.2" }, "devDependencies": { "@google-cloud/nodejs-repo-tools": "^3.3.0", "mocha": "^7.0.0", - "sinon": "^9.0.0" + "sinon": "^9.0.0", + "supertest": "^4.0.2" } } diff --git a/appengine/building-an-app/update/test/server.test.js b/appengine/building-an-app/update/test/server.test.js index 5baf2b73e3..3af88515ec 100755 --- a/appengine/building-an-app/update/test/server.test.js +++ b/appengine/building-an-app/update/test/server.test.js @@ -13,67 +13,40 @@ 'use strict'; -const path = require('path'); const assert = require('assert'); -const utils = require('@google-cloud/nodejs-repo-tools'); -const sinon = require('sinon'); +const supertest = require('supertest'); +const express = require('express'); -const cwd = path.join(__dirname, '../'); -const requestObj = utils.getRequest({ - cwd: cwd, - cmd: 'server', -}); - -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(); -}; +const app = express(); -beforeEach(stubConsole); -afterEach(restoreConsole); it('should send greetings', async () => { - await requestObj - .get('/') - .expect(200) - .expect(response => { - assert.strictEqual(response.text, 'Hello from App Engine!'); - }); + supertest(app) + .get('/') + .expect(200) + .expect(response => { + assert.strictEqual(response.text, 'Hello from App Engine!'); + }) }); it('should display form', async () => { - await requestObj - .get('/submit') - .expect(200) - .expect(response => { - assert.strictEqual( - response.text.includes('textarea name="message" placeholder="Message"'), - true - ); - }); + supertest(app) + .get('/') + .expect(200) + .expect(response => { + assert.strictEqual(response.text.includes('textarea name="message" placeholder="Message"'), + true + ); + }) }); it('should record message', async () => { - await requestObj - .post('/submit', { - name: 'sample-user', - message: 'sample-message', - }) - .expect(200) - .expect(response => { - assert.strictEqual(response.text, 'Thanks for your message!'); - }); -}); + supertest(app) + .get('/') + .expect(200) + .expect(response => { + assert.strictEqual(response.text, 'Thanks for your message!') + }); + }) + \ No newline at end of file From 26f87f596822bdea1047ac09982ff0ff48074f0f Mon Sep 17 00:00:00 2001 From: Sofia Leon Date: Thu, 5 Mar 2020 21:21:06 -0800 Subject: [PATCH 2/7] save up until now --- functions/tips/test/index.test.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/functions/tips/test/index.test.js b/functions/tips/test/index.test.js index bef0d13260..45e8908d37 100644 --- a/functions/tips/test/index.test.js +++ b/functions/tips/test/index.test.js @@ -20,15 +20,7 @@ const assert = require(`assert`); const sample = require(`../`); 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); - } - }); + sinon.stub(console, `log`); }; //Restore console From b3b50f715675eeb3d201eed8192533de312b41d6 Mon Sep 17 00:00:00 2001 From: Sofia Leon Date: Fri, 6 Mar 2020 13:25:26 -0800 Subject: [PATCH 3/7] npm run lint --- appengine/analytics/package.json | 2 +- .../update/test/server.test.js | 46 +++++++++---------- appengine/cloudsql/test/createTables.test.js | 11 +---- .../test/createTables.test.js | 10 +--- appengine/pubsub/package.json | 4 +- appengine/pubsub/test/app.test.js | 5 +- appengine/sendgrid/package.json | 5 +- appengine/sendgrid/test/app.test.js | 5 +- appengine/storage/flexible/package.json | 4 +- .../storage/flexible/system-test/app.test.js | 5 +- appengine/storage/standard/package.json | 4 +- .../storage/standard/system-test/app.test.js | 5 +- .../system-test/endpoints.test.js | 6 +-- functions/firebase/test/index.test.js | 10 +--- functions/helloworld/test/index.test.js | 1 - .../test/sample.integration.storage.test.js | 4 +- .../test/sample.unit.pubsub.test.js | 12 +---- .../test/sample.unit.storage.test.js | 12 +---- functions/log/test/index.test.js | 10 +--- functions/node8/test/index.test.js | 10 +--- functions/ocr/app/test/index.test.js | 10 +--- functions/pubsub/test/index.test.js | 10 +--- functions/scheduleinstance/test/index.test.js | 10 +--- functions/sendgrid/test/index.test.js | 17 +------ functions/slack/test/index.test.js | 10 +--- .../system-test/cloudiot_http_example.test.js | 3 +- iot/manager/system-test/manager.test.js | 9 ++-- .../system-test/cloudiot_mqtt_example.test.js | 7 ++- package.json | 5 ++ storage-transfer/system-test/transfer.test.js | 11 +---- storage-transfer/test/transfer.test.js | 11 +---- 31 files changed, 78 insertions(+), 196 deletions(-) diff --git a/appengine/analytics/package.json b/appengine/analytics/package.json index 1bd86216ba..a483442165 100644 --- a/appengine/analytics/package.json +++ b/appengine/analytics/package.json @@ -14,7 +14,7 @@ }, "scripts": { "start": "node app.js", - "system-test": "repo-tools test app", + "system-test": "repo-tools test app", "test": "npm run system-test" }, "dependencies": { diff --git a/appengine/building-an-app/update/test/server.test.js b/appengine/building-an-app/update/test/server.test.js index 3af88515ec..a6165a8441 100755 --- a/appengine/building-an-app/update/test/server.test.js +++ b/appengine/building-an-app/update/test/server.test.js @@ -17,36 +17,34 @@ const assert = require('assert'); const supertest = require('supertest'); const express = require('express'); - const app = express(); - -it('should send greetings', async () => { +it('should send greetings', () => { supertest(app) - .get('/') - .expect(200) - .expect(response => { - assert.strictEqual(response.text, 'Hello from App Engine!'); - }) + .get('/') + .expect(200) + .expect(response => { + assert.strictEqual(response.text, 'Hello from App Engine!'); + }); }); -it('should display form', async () => { +it('should display form', () => { supertest(app) - .get('/') - .expect(200) - .expect(response => { - assert.strictEqual(response.text.includes('textarea name="message" placeholder="Message"'), - true - ); - }) + .get('/') + .expect(200) + .expect(response => { + assert.strictEqual( + response.text.includes('textarea name="message" placeholder="Message"'), + true + ); + }); }); -it('should record message', async () => { +it('should record message', () => { supertest(app) - .get('/') - .expect(200) - .expect(response => { - assert.strictEqual(response.text, 'Thanks for your message!') - }); - }) - \ No newline at end of file + .get('/') + .expect(200) + .expect(response => { + assert.strictEqual(response.text, 'Thanks for your message!'); + }); +}); diff --git a/appengine/cloudsql/test/createTables.test.js b/appengine/cloudsql/test/createTables.test.js index 43a88f5049..49b92c30b5 100644 --- a/appengine/cloudsql/test/createTables.test.js +++ b/appengine/cloudsql/test/createTables.test.js @@ -57,17 +57,8 @@ const getSample = () => { }; 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); - } - }); + sinon.stub(console, `log`); }; const restoreConsole = function() { diff --git a/appengine/cloudsql_postgresql/test/createTables.test.js b/appengine/cloudsql_postgresql/test/createTables.test.js index 296646cc76..095cd48679 100644 --- a/appengine/cloudsql_postgresql/test/createTables.test.js +++ b/appengine/cloudsql_postgresql/test/createTables.test.js @@ -58,15 +58,7 @@ 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.apply(console, arguments); - } - }); + sinon.stub(console, `log`); }; const restoreConsole = function() { diff --git a/appengine/pubsub/package.json b/appengine/pubsub/package.json index e024f7043a..f14ed02352 100644 --- a/appengine/pubsub/package.json +++ b/appengine/pubsub/package.json @@ -17,7 +17,9 @@ "body-parser": "^1.18.3", "express": "^4.16.3", "google-auth-library": "^5.0.0", - "pug": "^2.0.1" + "proxyquire": "^2.1.3", + "pug": "^2.0.1", + "supertest": "^4.0.2" }, "devDependencies": { "@google-cloud/nodejs-repo-tools": "^3.3.0", diff --git a/appengine/pubsub/test/app.test.js b/appengine/pubsub/test/app.test.js index 395e640b37..1e0dad13d6 100644 --- a/appengine/pubsub/test/app.test.js +++ b/appengine/pubsub/test/app.test.js @@ -24,13 +24,14 @@ const jwt = require('jsonwebtoken'); const {OAuth2Client} = require('google-auth-library'); const path = require('path'); const sinon = require('sinon'); -const utils = require('@google-cloud/nodejs-repo-tools'); +const supertest = require('supertest'); +const proxyquire = require('proxyquire').noPreserveCache(); const message = 'This is a test message sent at: '; const payload = message + Date.now(); const cwd = path.join(__dirname, '../'); -const requestObj = utils.getRequest({cwd: cwd}); +const requestObj = supertest(proxyquire(path.join(cwd))); const fixtures = path.join(__dirname, 'fixtures'); const privateKey = fs.readFileSync(path.join(fixtures, 'privatekey.pem')); diff --git a/appengine/sendgrid/package.json b/appengine/sendgrid/package.json index fce6769b68..a693d97b89 100644 --- a/appengine/sendgrid/package.json +++ b/appengine/sendgrid/package.json @@ -13,10 +13,11 @@ "test": "repo-tools test app && mocha test/*.test.js" }, "dependencies": { + "@sendgrid/client": "^6.3.0", "body-parser": "^1.19.0", "express": "^4.16.4", - "pug": "^2.0.3", - "@sendgrid/client": "^6.3.0" + "proxyquire": "^2.1.3", + "pug": "^2.0.3" }, "devDependencies": { "@google-cloud/nodejs-repo-tools": "^3.3.0", diff --git a/appengine/sendgrid/test/app.test.js b/appengine/sendgrid/test/app.test.js index 57873dde7d..d0e795f993 100644 --- a/appengine/sendgrid/test/app.test.js +++ b/appengine/sendgrid/test/app.test.js @@ -1,9 +1,10 @@ const assert = require('assert'); const path = require('path'); -const utils = require('@google-cloud/nodejs-repo-tools'); +const supertest = require('supertest'); +const proxyquire = require('proxyquire'); const cwd = path.join(__dirname, '../'); -const request = utils.getRequest({cwd: cwd}); +const request = supertest(proxyquire(path.join(cwd))); describe('gae_flex_sendgrid', () => { it('GET /: should show homepage template', async () => { diff --git a/appengine/storage/flexible/package.json b/appengine/storage/flexible/package.json index 397e45bb6c..8bcfb7f04a 100644 --- a/appengine/storage/flexible/package.json +++ b/appengine/storage/flexible/package.json @@ -13,7 +13,9 @@ "body-parser": "^1.18.3", "express": "^4.16.4", "multer": "^1.4.1", - "pug": "^2.0.3" + "proxyquire": "^2.1.3", + "pug": "^2.0.3", + "supertest": "^4.0.2" }, "devDependencies": { "@google-cloud/nodejs-repo-tools": "^3.3.0", diff --git a/appengine/storage/flexible/system-test/app.test.js b/appengine/storage/flexible/system-test/app.test.js index b9de0c5be0..3f8e72c963 100644 --- a/appengine/storage/flexible/system-test/app.test.js +++ b/appengine/storage/flexible/system-test/app.test.js @@ -17,13 +17,14 @@ const path = require('path'); const {Storage} = require('@google-cloud/storage'); const storage = new Storage(); const assert = require('assert'); -const tools = require('@google-cloud/nodejs-repo-tools'); +const supertest = require('supertest'); +const proxyquire = require('proxyquire').noPreserveCache(); const bucketName = process.env.GCLOUD_STORAGE_BUCKET; const bucket = storage.bucket(bucketName); const cwd = path.join(__dirname, '../'); -const requestObj = tools.getRequest({cwd: cwd}); +const requestObj = supertest(proxyquire(path.join(cwd))); before(async () => { assert( diff --git a/appengine/storage/standard/package.json b/appengine/storage/standard/package.json index 397e45bb6c..8bcfb7f04a 100644 --- a/appengine/storage/standard/package.json +++ b/appengine/storage/standard/package.json @@ -13,7 +13,9 @@ "body-parser": "^1.18.3", "express": "^4.16.4", "multer": "^1.4.1", - "pug": "^2.0.3" + "proxyquire": "^2.1.3", + "pug": "^2.0.3", + "supertest": "^4.0.2" }, "devDependencies": { "@google-cloud/nodejs-repo-tools": "^3.3.0", diff --git a/appengine/storage/standard/system-test/app.test.js b/appengine/storage/standard/system-test/app.test.js index b9de0c5be0..3f8e72c963 100644 --- a/appengine/storage/standard/system-test/app.test.js +++ b/appengine/storage/standard/system-test/app.test.js @@ -17,13 +17,14 @@ const path = require('path'); const {Storage} = require('@google-cloud/storage'); const storage = new Storage(); const assert = require('assert'); -const tools = require('@google-cloud/nodejs-repo-tools'); +const supertest = require('supertest'); +const proxyquire = require('proxyquire').noPreserveCache(); const bucketName = process.env.GCLOUD_STORAGE_BUCKET; const bucket = storage.bucket(bucketName); const cwd = path.join(__dirname, '../'); -const requestObj = tools.getRequest({cwd: cwd}); +const requestObj = supertest(proxyquire(path.join(cwd))); before(async () => { assert( diff --git a/endpoints/getting-started-grpc/system-test/endpoints.test.js b/endpoints/getting-started-grpc/system-test/endpoints.test.js index 31ddbaedd7..19a46571a0 100644 --- a/endpoints/getting-started-grpc/system-test/endpoints.test.js +++ b/endpoints/getting-started-grpc/system-test/endpoints.test.js @@ -19,7 +19,6 @@ const path = require('path'); const assert = require('assert'); const fs = require(`fs`); const jwt = require('jsonwebtoken'); -const tools = require('@google-cloud/nodejs-repo-tools'); const delay = require('delay'); const clientCmd = `node client.js`; @@ -133,9 +132,6 @@ it(`should request and handle a greeting locally using a JWT Auth Token`, async // Misc it('should require either an API key or a JWT Auth Token', async () => { - const {stderr} = await tools.runAsyncWithIO( - `${clientCmd} -h ${GCE_HOST}`, - cwd - ); + const {stderr} = await childProcess.exec(`${clientCmd} -h ${GCE_HOST}`, cwd); assert.ok(stderr.includes('One of API_KEY or JWT_AUTH_TOKEN must be set')); }); diff --git a/functions/firebase/test/index.test.js b/functions/firebase/test/index.test.js index e0d6e5973f..73803d56c8 100644 --- a/functions/firebase/test/index.test.js +++ b/functions/firebase/test/index.test.js @@ -36,15 +36,7 @@ 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.apply(console, arguments); - } - }); + sinon.stub(console, `log`); }; const restoreConsole = function() { diff --git a/functions/helloworld/test/index.test.js b/functions/helloworld/test/index.test.js index 3c8ded05c4..5294f2fba9 100644 --- a/functions/helloworld/test/index.test.js +++ b/functions/helloworld/test/index.test.js @@ -14,7 +14,6 @@ const path = require('path'); const assert = require('assert'); -const tools = require('@google-cloud/nodejs-repo-tools'); const requestRetry = require('requestretry'); const uuid = require('uuid'); const sinon = require('sinon'); diff --git a/functions/helloworld/test/sample.integration.storage.test.js b/functions/helloworld/test/sample.integration.storage.test.js index 32a65c96ab..32f388dcf5 100644 --- a/functions/helloworld/test/sample.integration.storage.test.js +++ b/functions/helloworld/test/sample.integration.storage.test.js @@ -27,7 +27,7 @@ describe('functions_helloworld_storage integration test', () => { // [START functions_storage_integration_test] it('helloGCS: should print uploaded message', async () => { const filename = uuid.v4(); // Use a unique filename to avoid conflicts - const PORT = 9000; // Each running framework instance needs a unique port + const PORT = 2001; // Each running framework instance needs a unique port const data = { data: { @@ -65,7 +65,7 @@ describe('functions_helloworld_storage integration test', () => { it('helloGCS: should print metadata updated message', async () => { const filename = uuid.v4(); // Use a unique filename to avoid conflicts - const PORT = 9001; // Each running framework instance needs a unique port + const PORT = 9005; // Each running framework instance needs a unique port const data = { data: { diff --git a/functions/helloworld/test/sample.unit.pubsub.test.js b/functions/helloworld/test/sample.unit.pubsub.test.js index 3b40918f0e..3bb1e272bc 100644 --- a/functions/helloworld/test/sample.unit.pubsub.test.js +++ b/functions/helloworld/test/sample.unit.pubsub.test.js @@ -16,23 +16,13 @@ describe('functions_helloworld_pubsub', () => { // [START functions_pubsub_unit_test] const assert = require('assert'); const uuid = require('uuid'); - const utils = require('@google-cloud/nodejs-repo-tools'); const sinon = require('sinon'); const {helloPubSub} = require('..'); 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); - } - }); + sinon.stub(console, `log`); }; const restoreConsole = function() { diff --git a/functions/helloworld/test/sample.unit.storage.test.js b/functions/helloworld/test/sample.unit.storage.test.js index 01cf6d3cea..9b1fb3ea0a 100644 --- a/functions/helloworld/test/sample.unit.storage.test.js +++ b/functions/helloworld/test/sample.unit.storage.test.js @@ -16,23 +16,13 @@ describe('functions_helloworld_storage', () => { // [START functions_storage_unit_test] const assert = require('assert'); const uuid = require('uuid'); - const utils = require('@google-cloud/nodejs-repo-tools'); const sinon = require('sinon'); const {helloGCS} = require('..'); 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); - } - }); + sinon.stub(console, `log`); }; const restoreConsole = function() { diff --git a/functions/log/test/index.test.js b/functions/log/test/index.test.js index 9741031d99..393d2a18d3 100644 --- a/functions/log/test/index.test.js +++ b/functions/log/test/index.test.js @@ -52,15 +52,7 @@ 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.apply(console, arguments); - } - }); + sinon.stub(console, `log`); }; const restoreConsole = function() { diff --git a/functions/node8/test/index.test.js b/functions/node8/test/index.test.js index 7de96beb04..71b12a447b 100644 --- a/functions/node8/test/index.test.js +++ b/functions/node8/test/index.test.js @@ -41,15 +41,7 @@ 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.apply(console, arguments); - } - }); + sinon.stub(console, `log`); }; const restoreConsole = function() { diff --git a/functions/ocr/app/test/index.test.js b/functions/ocr/app/test/index.test.js index 0e7c5a80c8..6ad9033edc 100644 --- a/functions/ocr/app/test/index.test.js +++ b/functions/ocr/app/test/index.test.js @@ -36,15 +36,7 @@ const errorMsg = (name, propertyName) => { 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); - } - }); + sinon.stub(console, `log`); }; const restoreConsole = function() { diff --git a/functions/pubsub/test/index.test.js b/functions/pubsub/test/index.test.js index cd280c00d5..5aba6a226c 100644 --- a/functions/pubsub/test/index.test.js +++ b/functions/pubsub/test/index.test.js @@ -31,15 +31,7 @@ const MESSAGE = 'Hello, world!'; describe('functions/pubsub', () => { 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); - } - }); + sinon.stub(console, `log`); }; //Restore console diff --git a/functions/scheduleinstance/test/index.test.js b/functions/scheduleinstance/test/index.test.js index d0a8ea81bd..2f7bef63e2 100644 --- a/functions/scheduleinstance/test/index.test.js +++ b/functions/scheduleinstance/test/index.test.js @@ -48,15 +48,7 @@ const getMocks = () => { }; 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); - } - }); + sinon.stub(console, `log`); }; //Restore console diff --git a/functions/sendgrid/test/index.test.js b/functions/sendgrid/test/index.test.js index 06e33f5aba..a8f7dfb2d3 100644 --- a/functions/sendgrid/test/index.test.js +++ b/functions/sendgrid/test/index.test.js @@ -144,21 +144,8 @@ const getMocks = () => { }; }; 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); - } - }); - } + sinon.stub(console, `error`); + sinon.stub(console, `log`); }; //Restore console diff --git a/functions/slack/test/index.test.js b/functions/slack/test/index.test.js index 92355617f6..2626f4be23 100644 --- a/functions/slack/test/index.test.js +++ b/functions/slack/test/index.test.js @@ -89,15 +89,7 @@ const getMocks = () => { 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); - } - }); + sinon.stub(console, `log`); }; //Restore console diff --git a/iot/http_example/system-test/cloudiot_http_example.test.js b/iot/http_example/system-test/cloudiot_http_example.test.js index 6ee4bd8321..f0690d9e60 100644 --- a/iot/http_example/system-test/cloudiot_http_example.test.js +++ b/iot/http_example/system-test/cloudiot_http_example.test.js @@ -17,7 +17,6 @@ const path = require('path'); const {PubSub} = require('@google-cloud/pubsub'); const assert = require('assert'); -const tools = require('@google-cloud/nodejs-repo-tools'); const uuid = require('uuid'); const childProcess = require('child_process'); @@ -29,7 +28,7 @@ const cmd = `node cloudiot_http_example.js --registryId="${registryName}" --devi const cwd = path.join(__dirname, '..'); const installDeps = 'npm install'; -assert.ok(tools.run(installDeps, `${cwd}/../manager`)); +assert.ok(childProcess.exec(installDeps, `${cwd}/../manager`)); before(async () => { assert( process.env.GCLOUD_PROJECT, diff --git a/iot/manager/system-test/manager.test.js b/iot/manager/system-test/manager.test.js index 9fb16c61cf..6c3c33ae7b 100644 --- a/iot/manager/system-test/manager.test.js +++ b/iot/manager/system-test/manager.test.js @@ -18,7 +18,6 @@ const iot = require('@google-cloud/iot'); const path = require('path'); const {PubSub} = require('@google-cloud/pubsub'); const assert = require('assert'); -const tools = require('@google-cloud/nodejs-repo-tools'); const uuid = require('uuid'); const childProcess = require('child_process'); @@ -39,7 +38,7 @@ const iotClient = new iot.v1.DeviceManagerClient(); const pubSubClient = new PubSub({projectId}); before(async () => { - tools.run(installDeps, `${cwd}/../mqtt_example`); + childProcess.exec(installDeps, `${cwd}/../mqtt_example`); assert( process.env.GCLOUD_PROJECT, `Must set GCLOUD_PROJECT environment variable!` @@ -75,8 +74,8 @@ after(async () => { console.log(`Topic ${topicName} deleted.`); // Cleans up the registry by removing all associations and deleting all devices. - tools.run(`${cmd} unbindAllDevices ${registryName}`, cwd); - tools.run(`${cmd} clearRegistry ${registryName}`, cwd); + childProcess.exec(`${cmd} unbindAllDevices ${registryName}`, cwd); + childProcess.exec(`${cmd} clearRegistry ${registryName}`, cwd); console.log('Deleted test registry.'); }); @@ -266,7 +265,7 @@ it('should send command message to device', () => { cwd ); - tools.runAsync( + childProcess.execSync( `node cloudiot_mqtt_example_nodejs.js mqttDeviceDemo --deviceId=${deviceId} --registryId=${registryName}\ --privateKeyFile=${rsaPrivateKey} --algorithm=RS256 --numMessages=20 --mqttBridgePort=8883`, path.join(__dirname, '../../mqtt_example') diff --git a/iot/mqtt_example/system-test/cloudiot_mqtt_example.test.js b/iot/mqtt_example/system-test/cloudiot_mqtt_example.test.js index 12704b9a0f..5a9cec2f75 100644 --- a/iot/mqtt_example/system-test/cloudiot_mqtt_example.test.js +++ b/iot/mqtt_example/system-test/cloudiot_mqtt_example.test.js @@ -19,7 +19,6 @@ const childProcess = require('child_process'); const iot = require('@google-cloud/iot'); const path = require('path'); const {PubSub} = require('@google-cloud/pubsub'); -const tools = require('@google-cloud/nodejs-repo-tools'); const util = require('util'); const uuid = require('uuid'); @@ -40,7 +39,7 @@ const installDeps = 'npm install'; const iotClient = new iot.v1.DeviceManagerClient(); const pubSubClient = new PubSub({projectId}); -assert.ok(tools.run(installDeps, `${cwd}/../manager`)); +assert.ok(childProcess.exec(installDeps, `${cwd}/../manager`)); before(async () => { assert( process.env.GCLOUD_PROJECT, @@ -77,8 +76,8 @@ after(async () => { console.log(`Topic ${topicName} deleted.`); // Cleans up the registry by removing all associations and deleting all devices. - tools.run(`${helper} unbindAllDevices ${registryName}`, cwd); - tools.run(`${helper} clearRegistry ${registryName}`, cwd); + childProcess.exec(`${helper} unbindAllDevices ${registryName}`, cwd); + childProcess.exec(`${helper} clearRegistry ${registryName}`, cwd); console.log('Deleted test registry.'); }); diff --git a/package.json b/package.json index e2e8316eab..52012e63e7 100644 --- a/package.json +++ b/package.json @@ -26,5 +26,10 @@ "eslint-plugin-promise": "^4.1.1", "prettier": "^1.18.2", "requestretry": "^4.0.0" + }, + "dependencies": { + "mocha": "^7.1.0", + "proxyquire": "^2.1.3", + "supertest": "^4.0.2" } } diff --git a/storage-transfer/system-test/transfer.test.js b/storage-transfer/system-test/transfer.test.js index ff1e4e0c86..423dc1dcd4 100644 --- a/storage-transfer/system-test/transfer.test.js +++ b/storage-transfer/system-test/transfer.test.js @@ -34,16 +34,7 @@ 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); - } - }); + sinon.stub(console, `log`); }; const restoreConsole = function restoreConsole() { diff --git a/storage-transfer/test/transfer.test.js b/storage-transfer/test/transfer.test.js index df44f0c7f0..911507a8a8 100644 --- a/storage-transfer/test/transfer.test.js +++ b/storage-transfer/test/transfer.test.js @@ -76,16 +76,7 @@ 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); - } - }); + sinon.stub(console, `log`); }; //Restore console From 6883924976362eb8b1e619920a2ddaa25140b5d1 Mon Sep 17 00:00:00 2001 From: Sofia Leon Date: Fri, 6 Mar 2020 13:40:45 -0800 Subject: [PATCH 4/7] fix: remove proxyquire --- appengine/pubsub/test/app.test.js | 3 +-- appengine/sendgrid/test/app.test.js | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/appengine/pubsub/test/app.test.js b/appengine/pubsub/test/app.test.js index 1e0dad13d6..cc1407fcb7 100644 --- a/appengine/pubsub/test/app.test.js +++ b/appengine/pubsub/test/app.test.js @@ -25,13 +25,12 @@ const {OAuth2Client} = require('google-auth-library'); const path = require('path'); const sinon = require('sinon'); const supertest = require('supertest'); -const proxyquire = require('proxyquire').noPreserveCache(); const message = 'This is a test message sent at: '; const payload = message + Date.now(); const cwd = path.join(__dirname, '../'); -const requestObj = supertest(proxyquire(path.join(cwd))); +const requestObj = ssupertest(path.join(cwd)); const fixtures = path.join(__dirname, 'fixtures'); const privateKey = fs.readFileSync(path.join(fixtures, 'privatekey.pem')); diff --git a/appengine/sendgrid/test/app.test.js b/appengine/sendgrid/test/app.test.js index d0e795f993..ebdfcb984f 100644 --- a/appengine/sendgrid/test/app.test.js +++ b/appengine/sendgrid/test/app.test.js @@ -1,10 +1,9 @@ const assert = require('assert'); const path = require('path'); const supertest = require('supertest'); -const proxyquire = require('proxyquire'); const cwd = path.join(__dirname, '../'); -const request = supertest(proxyquire(path.join(cwd))); +const request = supertest(path.join(cwd)); describe('gae_flex_sendgrid', () => { it('GET /: should show homepage template', async () => { From fcd57401763523ba609d44e4d9138696f1d496e0 Mon Sep 17 00:00:00 2001 From: Sofia Leon Date: Fri, 6 Mar 2020 13:41:33 -0800 Subject: [PATCH 5/7] fix: typo --- appengine/pubsub/test/app.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appengine/pubsub/test/app.test.js b/appengine/pubsub/test/app.test.js index cc1407fcb7..a5b9cbd6d6 100644 --- a/appengine/pubsub/test/app.test.js +++ b/appengine/pubsub/test/app.test.js @@ -30,7 +30,7 @@ const message = 'This is a test message sent at: '; const payload = message + Date.now(); const cwd = path.join(__dirname, '../'); -const requestObj = ssupertest(path.join(cwd)); +const requestObj = supertest(path.join(cwd)); const fixtures = path.join(__dirname, 'fixtures'); const privateKey = fs.readFileSync(path.join(fixtures, 'privatekey.pem')); From 985f711b8682f8d129da7401cdccceaceb1155bf Mon Sep 17 00:00:00 2001 From: Sofia Leon Date: Fri, 6 Mar 2020 14:05:54 -0800 Subject: [PATCH 6/7] test different functions --- appengine/pubsub/test/app.test.js | 6 ++++-- appengine/sendgrid/test/app.test.js | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/appengine/pubsub/test/app.test.js b/appengine/pubsub/test/app.test.js index a5b9cbd6d6..cbdbc133cc 100644 --- a/appengine/pubsub/test/app.test.js +++ b/appengine/pubsub/test/app.test.js @@ -24,13 +24,15 @@ const jwt = require('jsonwebtoken'); const {OAuth2Client} = require('google-auth-library'); const path = require('path'); const sinon = require('sinon'); -const supertest = require('supertest'); +const utils = require('@google-cloud/nodejs-repo-tools'); const message = 'This is a test message sent at: '; const payload = message + Date.now(); const cwd = path.join(__dirname, '../'); -const requestObj = supertest(path.join(cwd)); +//const requestObj = supertest(path.join(cwd)); + +const requestObj = utils.getRequest({cwd: cwd}); const fixtures = path.join(__dirname, 'fixtures'); const privateKey = fs.readFileSync(path.join(fixtures, 'privatekey.pem')); diff --git a/appengine/sendgrid/test/app.test.js b/appengine/sendgrid/test/app.test.js index ebdfcb984f..e0186e9aec 100644 --- a/appengine/sendgrid/test/app.test.js +++ b/appengine/sendgrid/test/app.test.js @@ -1,9 +1,11 @@ const assert = require('assert'); const path = require('path'); -const supertest = require('supertest'); +const utils = require('@google-cloud/nodejs-repo-tools'); const cwd = path.join(__dirname, '../'); -const request = supertest(path.join(cwd)); +const request = utils.getRequest({cwd: cwd}); + +//const requestObj = supertest(path.join(cwd)); describe('gae_flex_sendgrid', () => { it('GET /: should show homepage template', async () => { From e37960a9a3070def07723a1e0b339871655c95c7 Mon Sep 17 00:00:00 2001 From: Sofia Leon Date: Fri, 6 Mar 2020 14:08:12 -0800 Subject: [PATCH 7/7] test different refactors --- appengine/storage/flexible/system-test/app.test.js | 7 ++++--- appengine/storage/standard/system-test/app.test.js | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/appengine/storage/flexible/system-test/app.test.js b/appengine/storage/flexible/system-test/app.test.js index 3f8e72c963..71815fc398 100644 --- a/appengine/storage/flexible/system-test/app.test.js +++ b/appengine/storage/flexible/system-test/app.test.js @@ -17,14 +17,15 @@ const path = require('path'); const {Storage} = require('@google-cloud/storage'); const storage = new Storage(); const assert = require('assert'); -const supertest = require('supertest'); -const proxyquire = require('proxyquire').noPreserveCache(); +const tools = require('@google-cloud/nodejs-repo-tools'); const bucketName = process.env.GCLOUD_STORAGE_BUCKET; const bucket = storage.bucket(bucketName); const cwd = path.join(__dirname, '../'); -const requestObj = supertest(proxyquire(path.join(cwd))); +const requestObj = tools.getRequest({cwd: cwd}); +//const requestObj = supertest(path.join(cwd)); + before(async () => { assert( diff --git a/appengine/storage/standard/system-test/app.test.js b/appengine/storage/standard/system-test/app.test.js index 3f8e72c963..5d9947dc6c 100644 --- a/appengine/storage/standard/system-test/app.test.js +++ b/appengine/storage/standard/system-test/app.test.js @@ -17,14 +17,15 @@ const path = require('path'); const {Storage} = require('@google-cloud/storage'); const storage = new Storage(); const assert = require('assert'); -const supertest = require('supertest'); -const proxyquire = require('proxyquire').noPreserveCache(); +const tools = require('@google-cloud/nodejs-repo-tools'); const bucketName = process.env.GCLOUD_STORAGE_BUCKET; const bucket = storage.bucket(bucketName); const cwd = path.join(__dirname, '../'); -const requestObj = supertest(proxyquire(path.join(cwd))); +//const requestObj = supertest(path.join(cwd)); + +const requestObj = tools.getRequest({cwd: cwd}); before(async () => { assert(