Skip to content

Commit 282f400

Browse files
authoredJan 8, 2020
chore: fetch open collective supporters via gql api (#9377)
1 parent 8c20a8d commit 282f400

File tree

4 files changed

+63
-39
lines changed

4 files changed

+63
-39
lines changed
 

‎website/fetchSupporters.js

+36-36
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,46 @@
77
* LICENSE file in the root directory of this source tree.
88
*/
99

10-
const fs = require('fs');
11-
const request = require('request');
10+
const fs = require('fs').promises;
11+
const {request} = require('graphql-request');
1212
const path = require('path');
1313

14-
const REQUIRED_KEYS = ['fromAccount', 'tier', 'totalDonations'];
15-
16-
request(
17-
'https://rest.opencollective.com/v2/jest/orders/incoming/active?limit=1000',
18-
(err, response, body) => {
19-
if (err) console.error('Failed to fetch backers: ', err);
20-
21-
// Basic validation
22-
const result = JSON.parse(body);
23-
if (!result || !Array.isArray(result.nodes)) {
24-
throw new Error('backer info is not an array');
25-
}
26-
27-
const backers = result.nodes;
28-
29-
for (const item of backers) {
30-
for (const key of REQUIRED_KEYS) {
31-
if (!item || typeof item !== 'object')
32-
throw new Error(
33-
`backer info item (${JSON.stringify(item)} is not an object`
34-
);
35-
if (!(key in item))
36-
throw new Error(
37-
`backer info item (${JSON.stringify(item)} doesn't include ${key}`
38-
);
14+
const graphqlQuery = `
15+
{
16+
account(slug: "jest") {
17+
orders(status: ACTIVE, limit: 1000) {
18+
nodes {
19+
tier {
20+
slug
21+
}
22+
fromAccount {
23+
name
24+
slug
25+
website
26+
imageUrl
27+
}
28+
totalDonations {
29+
value
30+
}
31+
}
3932
}
4033
}
34+
}
35+
`;
36+
37+
request('https://api.opencollective.com/graphql/v2', graphqlQuery)
38+
.then(data => {
39+
const backers = data.account.orders.nodes;
4140

42-
fs.writeFile(
41+
return fs.writeFile(
4342
path.resolve(__dirname, 'backers.json'),
44-
JSON.stringify(backers),
45-
err => {
46-
if (err) {
47-
console.error('Failed to write backers file: ', err);
48-
} else console.log('Fetched 1 file: backers.json');
49-
}
43+
JSON.stringify(backers)
5044
);
51-
}
52-
);
45+
})
46+
.then(() => {
47+
console.log('Fetched 1 file: backers.json');
48+
})
49+
.catch(e => {
50+
console.error('Failed to write backers file: ', e);
51+
process.exitCode = 1;
52+
});

‎website/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"version": "0.0.0",
44
"private": true,
55
"scripts": {
6-
"postinstall": "node fetchSupporters.js",
76
"start": "docusaurus-start",
87
"build": "docusaurus-build",
98
"gh-pages": "docusaurus-publish",
@@ -20,6 +19,6 @@
2019
},
2120
"devDependencies": {
2221
"crowdin-cli": "^0.3.0",
23-
"request": "^2.88.0"
22+
"graphql-request": "^1.8.2"
2423
}
2524
}

‎website/versioned_docs/version-22.x/SnapshotTesting.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Yes, all snapshot files should be committed alongside the modules they are cover
102102

103103
### Does snapshot testing only work with React components?
104104

105-
[React](TutorialReacte.md) and [React Native](TutorialReactNative.md) components are a good use case for snapshot testing. However, snapshots can capture any serializable value and should be used anytime the goal is testing whether the output is correct. The Jest repository contains many examples of testing the output of Jest itself, the output of Jest's assertion library as well as log messages from various parts of the Jest codebase. See an example of [snapshotting CLI output](https://github.com/facebook/jest/blob/master/e2e/__tests__/console.test.ts) in the Jest repo.
105+
[React](TutorialReact.md) and [React Native](TutorialReactNative.md) components are a good use case for snapshot testing. However, snapshots can capture any serializable value and should be used anytime the goal is testing whether the output is correct. The Jest repository contains many examples of testing the output of Jest itself, the output of Jest's assertion library as well as log messages from various parts of the Jest codebase. See an example of [snapshotting CLI output](https://github.com/facebook/jest/blob/master/e2e/__tests__/console.test.ts) in the Jest repo.
106106

107107
### What's the difference between snapshot testing and visual regression testing?
108108

‎yarn.lock

+25
Original file line numberDiff line numberDiff line change
@@ -4472,6 +4472,14 @@ create-react-class@^15.6.3:
44724472
loose-envify "^1.3.1"
44734473
object-assign "^4.1.1"
44744474

4475+
cross-fetch@2.2.2:
4476+
version "2.2.2"
4477+
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-2.2.2.tgz#a47ff4f7fc712daba8f6a695a11c948440d45723"
4478+
integrity sha1-pH/09/xxLauo9qaVoRyUhEDUVyM=
4479+
dependencies:
4480+
node-fetch "2.1.2"
4481+
whatwg-fetch "2.0.4"
4482+
44754483
cross-spawn@6.0.5, cross-spawn@^6.0.0, cross-spawn@^6.0.5:
44764484
version "6.0.5"
44774485
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4"
@@ -7038,6 +7046,13 @@ graceful-fs@^4.1.10, graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.
70387046
resolved "https://registry.yarnpkg.com/graceful-readlink/-/graceful-readlink-1.0.1.tgz#4cafad76bc62f02fa039b2f94e9a3dd3a391a725"
70397047
integrity sha1-TK+tdrxi8C+gObL5Tpo906ORpyU=
70407048

7049+
graphql-request@^1.8.2:
7050+
version "1.8.2"
7051+
resolved "https://registry.yarnpkg.com/graphql-request/-/graphql-request-1.8.2.tgz#398d10ae15c585676741bde3fc01d5ca948f8fbe"
7052+
integrity sha512-dDX2M+VMsxXFCmUX0Vo0TopIZIX4ggzOtiCsThgtrKR4niiaagsGTDIHj3fsOMFETpa064vzovI+4YV4QnMbcg==
7053+
dependencies:
7054+
cross-fetch "2.2.2"
7055+
70417056
gray-matter@^2.1.0:
70427057
version "2.1.1"
70437058
resolved "https://registry.yarnpkg.com/gray-matter/-/gray-matter-2.1.1.tgz#3042d9adec2a1ded6a7707a9ed2380f8a17a430e"
@@ -9961,6 +9976,11 @@ node-fetch@1.6.3:
99619976
encoding "^0.1.11"
99629977
is-stream "^1.0.1"
99639978

9979+
node-fetch@2.1.2:
9980+
version "2.1.2"
9981+
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.1.2.tgz#ab884e8e7e57e38a944753cec706f788d1768bb5"
9982+
integrity sha1-q4hOjn5X44qUR1POxwb3iNF2i7U=
9983+
99649984
node-fetch@^1.0.1:
99659985
version "1.7.3"
99669986
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.3.tgz#980f6f72d85211a5347c6b2bc18c5b84c3eb47ef"
@@ -14420,6 +14440,11 @@ whatwg-encoding@^1.0.1, whatwg-encoding@^1.0.5:
1442014440
dependencies:
1442114441
iconv-lite "0.4.24"
1442214442

14443+
whatwg-fetch@2.0.4:
14444+
version "2.0.4"
14445+
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz#dde6a5df315f9d39991aa17621853d720b85566f"
14446+
integrity sha512-dcQ1GWpOD/eEQ97k66aiEVpNnapVj90/+R+SXTPYGHpYBBypfKJEQjLrvMZ7YXbKm21gXd4NcuxUTjiv1YtLng==
14447+
1442314448
whatwg-fetch@>=0.10.0:
1442414449
version "3.0.0"
1442514450
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-3.0.0.tgz#fc804e458cc460009b1a2b966bc8817d2578aefb"

0 commit comments

Comments
 (0)
Please sign in to comment.