Skip to content

Commit

Permalink
chore: fetch open collective supporters via gql api (#9377)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Jan 8, 2020
1 parent 8c20a8d commit 282f400
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 39 deletions.
72 changes: 36 additions & 36 deletions website/fetchSupporters.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,46 @@
* LICENSE file in the root directory of this source tree.
*/

const fs = require('fs');
const request = require('request');
const fs = require('fs').promises;
const {request} = require('graphql-request');
const path = require('path');

const REQUIRED_KEYS = ['fromAccount', 'tier', 'totalDonations'];

request(
'https://rest.opencollective.com/v2/jest/orders/incoming/active?limit=1000',
(err, response, body) => {
if (err) console.error('Failed to fetch backers: ', err);

// Basic validation
const result = JSON.parse(body);
if (!result || !Array.isArray(result.nodes)) {
throw new Error('backer info is not an array');
}

const backers = result.nodes;

for (const item of backers) {
for (const key of REQUIRED_KEYS) {
if (!item || typeof item !== 'object')
throw new Error(
`backer info item (${JSON.stringify(item)} is not an object`
);
if (!(key in item))
throw new Error(
`backer info item (${JSON.stringify(item)} doesn't include ${key}`
);
const graphqlQuery = `
{
account(slug: "jest") {
orders(status: ACTIVE, limit: 1000) {
nodes {
tier {
slug
}
fromAccount {
name
slug
website
imageUrl
}
totalDonations {
value
}
}
}
}
}
`;

request('https://api.opencollective.com/graphql/v2', graphqlQuery)
.then(data => {
const backers = data.account.orders.nodes;

fs.writeFile(
return fs.writeFile(
path.resolve(__dirname, 'backers.json'),
JSON.stringify(backers),
err => {
if (err) {
console.error('Failed to write backers file: ', err);
} else console.log('Fetched 1 file: backers.json');
}
JSON.stringify(backers)
);
}
);
})
.then(() => {
console.log('Fetched 1 file: backers.json');
})
.catch(e => {
console.error('Failed to write backers file: ', e);
process.exitCode = 1;
});
3 changes: 1 addition & 2 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"version": "0.0.0",
"private": true,
"scripts": {
"postinstall": "node fetchSupporters.js",
"start": "docusaurus-start",
"build": "docusaurus-build",
"gh-pages": "docusaurus-publish",
Expand All @@ -20,6 +19,6 @@
},
"devDependencies": {
"crowdin-cli": "^0.3.0",
"request": "^2.88.0"
"graphql-request": "^1.8.2"
}
}
2 changes: 1 addition & 1 deletion website/versioned_docs/version-22.x/SnapshotTesting.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Yes, all snapshot files should be committed alongside the modules they are cover

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

[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.
[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.

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

Expand Down
25 changes: 25 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4472,6 +4472,14 @@ create-react-class@^15.6.3:
loose-envify "^1.3.1"
object-assign "^4.1.1"

cross-fetch@2.2.2:
version "2.2.2"
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-2.2.2.tgz#a47ff4f7fc712daba8f6a695a11c948440d45723"
integrity sha1-pH/09/xxLauo9qaVoRyUhEDUVyM=
dependencies:
node-fetch "2.1.2"
whatwg-fetch "2.0.4"

cross-spawn@6.0.5, cross-spawn@^6.0.0, cross-spawn@^6.0.5:
version "6.0.5"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4"
Expand Down Expand Up @@ -7038,6 +7046,13 @@ graceful-fs@^4.1.10, graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.
resolved "https://registry.yarnpkg.com/graceful-readlink/-/graceful-readlink-1.0.1.tgz#4cafad76bc62f02fa039b2f94e9a3dd3a391a725"
integrity sha1-TK+tdrxi8C+gObL5Tpo906ORpyU=

graphql-request@^1.8.2:
version "1.8.2"
resolved "https://registry.yarnpkg.com/graphql-request/-/graphql-request-1.8.2.tgz#398d10ae15c585676741bde3fc01d5ca948f8fbe"
integrity sha512-dDX2M+VMsxXFCmUX0Vo0TopIZIX4ggzOtiCsThgtrKR4niiaagsGTDIHj3fsOMFETpa064vzovI+4YV4QnMbcg==
dependencies:
cross-fetch "2.2.2"

gray-matter@^2.1.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/gray-matter/-/gray-matter-2.1.1.tgz#3042d9adec2a1ded6a7707a9ed2380f8a17a430e"
Expand Down Expand Up @@ -9961,6 +9976,11 @@ node-fetch@1.6.3:
encoding "^0.1.11"
is-stream "^1.0.1"

node-fetch@2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.1.2.tgz#ab884e8e7e57e38a944753cec706f788d1768bb5"
integrity sha1-q4hOjn5X44qUR1POxwb3iNF2i7U=

node-fetch@^1.0.1:
version "1.7.3"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.3.tgz#980f6f72d85211a5347c6b2bc18c5b84c3eb47ef"
Expand Down Expand Up @@ -14420,6 +14440,11 @@ whatwg-encoding@^1.0.1, whatwg-encoding@^1.0.5:
dependencies:
iconv-lite "0.4.24"

whatwg-fetch@2.0.4:
version "2.0.4"
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz#dde6a5df315f9d39991aa17621853d720b85566f"
integrity sha512-dcQ1GWpOD/eEQ97k66aiEVpNnapVj90/+R+SXTPYGHpYBBypfKJEQjLrvMZ7YXbKm21gXd4NcuxUTjiv1YtLng==

whatwg-fetch@>=0.10.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-3.0.0.tgz#fc804e458cc460009b1a2b966bc8817d2578aefb"
Expand Down

0 comments on commit 282f400

Please sign in to comment.