Skip to content

Commit 4858930

Browse files
authored
chore: refactor nodejs-repo-tools and stubbing (GoogleCloudPlatform#1626)
* chore: refactor node-repo-tools
1 parent 0456b2e commit 4858930

File tree

33 files changed

+201
-274
lines changed

33 files changed

+201
-274
lines changed

appengine/building-an-app/update/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
"devDependencies": {
2626
"@google-cloud/nodejs-repo-tools": "^3.3.0",
2727
"mocha": "^7.0.0",
28-
"sinon": "^9.0.0"
28+
"sinon": "^9.0.0",
29+
"supertest": "^4.0.2",
30+
"proxyquire": "^2.1.3"
2931
}
3032
}

appengine/building-an-app/update/test/server.test.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,17 @@
1515

1616
const path = require('path');
1717
const assert = require('assert');
18-
const utils = require('@google-cloud/nodejs-repo-tools');
1918
const sinon = require('sinon');
19+
const supertest = require('supertest');
20+
const proxyquire = require('proxyquire').noPreserveCache();
2021

2122
const cwd = path.join(__dirname, '../');
22-
const requestObj = utils.getRequest({
23-
cwd: cwd,
24-
cmd: 'server',
25-
});
23+
24+
const requestObj = supertest(proxyquire(path.join(cwd, 'server'), {process}));
2625

2726
const stubConsole = function() {
2827
sinon.stub(console, `error`);
29-
sinon.stub(console, `log`).callsFake((a, b) => {
30-
if (
31-
typeof a === `string` &&
32-
a.indexOf(`\u001b`) !== -1 &&
33-
typeof b === `string`
34-
) {
35-
console.log.apply(console, arguments);
36-
}
37-
});
28+
sinon.stub(console, `log`);
3829
};
3930

4031
const restoreConsole = function() {

appengine/cloudsql/test/createTables.test.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,7 @@ const getSample = () => {
5959
const stubConsole = function() {
6060
/* eslint-disable no-console */
6161
sinon.stub(console, `error`);
62-
sinon.stub(console, `log`).callsFake((a, b) => {
63-
if (
64-
typeof a === `string` &&
65-
a.indexOf(`\u001b`) !== -1 &&
66-
typeof b === `string`
67-
) {
68-
console.log.apply(console, arguments);
69-
}
70-
});
62+
sinon.stub(console, `log`);
7163
};
7264

7365
const restoreConsole = function() {

appengine/cloudsql_postgresql/test/createTables.test.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,7 @@ const getSample = () => {
5858

5959
const stubConsole = function() {
6060
sinon.stub(console, `error`);
61-
sinon.stub(console, `log`).callsFake((a, b) => {
62-
if (
63-
typeof a === `string` &&
64-
a.indexOf(`\u001b`) !== -1 &&
65-
typeof b === `string`
66-
) {
67-
console.log.apply(console, arguments);
68-
}
69-
});
61+
sinon.stub(console, `log`);
7062
};
7163

7264
const restoreConsole = function() {

appengine/pubsub/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
"jsonwebtoken": "^8.5.1",
2525
"mocha": "^7.0.0",
2626
"sinon": "^9.0.0",
27-
"uuid": "^7.0.0"
27+
"uuid": "^7.0.0",
28+
"supertest": "^4.0.2",
29+
"proxyquire": "^2.1.3"
2830
},
2931
"cloud-repo-tools": {
3032
"requiresProjectId": true,

appengine/pubsub/test/app.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ const jwt = require('jsonwebtoken');
2424
const {OAuth2Client} = require('google-auth-library');
2525
const path = require('path');
2626
const sinon = require('sinon');
27-
const utils = require('@google-cloud/nodejs-repo-tools');
27+
const supertest = require('supertest');
28+
const proxyquire = require('proxyquire').noPreserveCache();
2829

2930
const message = 'This is a test message sent at: ';
3031
const payload = message + Date.now();
3132

3233
const cwd = path.join(__dirname, '../');
33-
const requestObj = utils.getRequest({cwd: cwd});
34+
const requestObj = supertest(proxyquire(path.join(cwd, 'app'), {process}));
3435

3536
const fixtures = path.join(__dirname, 'fixtures');
3637
const privateKey = fs.readFileSync(path.join(fixtures, 'privatekey.pem'));

appengine/sendgrid/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"devDependencies": {
2222
"@google-cloud/nodejs-repo-tools": "^3.3.0",
2323
"mocha": "^7.0.0",
24-
"supertest": "^4.0.2"
24+
"supertest": "^4.0.2",
25+
"proxyquire": "^2.1.3"
2526
}
2627
}

appengine/sendgrid/test/app.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
const assert = require('assert');
22
const path = require('path');
3-
const utils = require('@google-cloud/nodejs-repo-tools');
3+
const supertest = require('supertest');
4+
const proxyquire = require('proxyquire').noPreserveCache();
45

56
const cwd = path.join(__dirname, '../');
6-
const request = utils.getRequest({cwd: cwd});
7+
const request = supertest(proxyquire(path.join(cwd, 'app'), {process}));
78

89
describe('gae_flex_sendgrid', () => {
910
it('GET /: should show homepage template', async () => {

appengine/storage/flexible/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
},
1818
"devDependencies": {
1919
"@google-cloud/nodejs-repo-tools": "^3.3.0",
20-
"mocha": "^7.0.0"
20+
"mocha": "^7.0.0",
21+
"supertest": "^4.0.2",
22+
"proxyquire": "^2.1.3"
2123
},
2224
"cloud-repo-tools": {
2325
"requiresProjectId": true,

appengine/storage/flexible/system-test/app.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ const path = require('path');
1717
const {Storage} = require('@google-cloud/storage');
1818
const storage = new Storage();
1919
const assert = require('assert');
20-
const tools = require('@google-cloud/nodejs-repo-tools');
20+
const supertest = require('supertest');
21+
const proxyquire = require('proxyquire').noPreserveCache();
2122

2223
const bucketName = process.env.GCLOUD_STORAGE_BUCKET;
2324
const bucket = storage.bucket(bucketName);
2425

2526
const cwd = path.join(__dirname, '../');
26-
const requestObj = tools.getRequest({cwd: cwd});
27+
const requestObj = supertest(proxyquire(path.join(cwd, 'app'), {process}));
2728

2829
before(async () => {
2930
assert(

0 commit comments

Comments
 (0)