From 14eee06799fa47828f4bb9c4a932a60a109427bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dandelion=20Man=C3=A9?= Date: Tue, 28 May 2019 18:59:50 +0300 Subject: [PATCH] Add a universal snapshot updater (#1159) As SourceCred has evolved, we've grown more and more snapshot tests that are not included in Jest. The GitHub plugin has two ad-hoc snapshot tests, the Git plugin has one, and the sharness test suites have one. This makes it difficult to keep track of where to update snapshots when core changes are made. To fix this, I've added a script, `scripts/update_snapshots.sh`, which updates snapshot tests across the project. Test plan: I removed existing snapshots across the codebase, ran the snapshot tester, and they correctly regenerated. --- scripts/update_snapshots.sh | 19 +++++++++++++++++++ sharness/test_load_example_github.t | 4 ++++ src/plugins/github/example/README.md | 11 +++-------- 3 files changed, 26 insertions(+), 8 deletions(-) create mode 100755 scripts/update_snapshots.sh diff --git a/scripts/update_snapshots.sh b/scripts/update_snapshots.sh new file mode 100755 index 0000000..b78ee67 --- /dev/null +++ b/scripts/update_snapshots.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +# Automatically update all SourceCred snapshot data. +set -eu + +toplevel="$(git -C "$(dirname "$0")" rev-parse --show-toplevel)" +cd "${toplevel}" + +yarn backend +echo "Updating for sharness/test_load_example_github.t" +(cd sharness; UPDATE_SNAPSHOT=1 ./test_load_example_github.t -l) +echo "Updating git/loadRepositoryTest.sh" +./src/plugins/git/loadRepositoryTest.sh -u +echo "Updating github/fetchGithubOrgTest.sh" +./src/plugins/github/fetchGithubOrgTest.sh -u --no-build +echo "Updating github/fetchGithubRepoTest.sh" +./src/plugins/github/fetchGithubRepoTest.sh -u --no-build +echo "Updating Jest snapshots" +yarn unit -u diff --git a/sharness/test_load_example_github.t b/sharness/test_load_example_github.t index 0fd5d9f..87be9f2 100755 --- a/sharness/test_load_example_github.t +++ b/sharness/test_load_example_github.t @@ -7,6 +7,10 @@ # shellcheck disable=SC2034,SC2016,SC1004 : +# If this test is failing, it probably means you need to update snapshots. +# You can do so by setting your SOURCECRED_GITHUB_TOKEN (see README) and then +# running scripts/update_snapshots.sh. + test_description='test snapshot integrity for sourcecred load' export GIT_CONFIG_NOSYSTEM=1 diff --git a/src/plugins/github/example/README.md b/src/plugins/github/example/README.md index ddfd73e..a32cf7c 100644 --- a/src/plugins/github/example/README.md +++ b/src/plugins/github/example/README.md @@ -5,16 +5,11 @@ data is generated by running our GitHub API fetch against the SourceCred example repo at https://github.com/sourcecred/example-github/. The demo data should be regenerated any time either the example repository or -the GitHub api query changes. To regenerate the demo data, run the following -command: +the GitHub api query changes. To regenerate the demo data, you can run the general-purpose +snapshot updater: ```shell -$ SOURCECRED_GITHUB_TOKEN="your_token_here" src/plugins/github/fetchGithubRepoTest.sh -u -``` - -You can also just verify that the data is up-to-date by running: -```shell -$ SOURCECRED_GITHUB_TOKEN="your_token_here" src/plugins/github/fetchGithubRepoTest.sh +$ SOURCECRED_GITHUB_TOKEN="your_token_here" scripts/update_snapshots.sh ``` There is a known issue where GitHub's end cursor output depends on your current