Skip to content

Commit 3c6a058

Browse files
committed
Added data caching to Test runner for README badge.
1 parent a99b63b commit 3c6a058

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

Tests.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,19 @@ function RunTests_(): Shield {
421421
};
422422
}
423423

424+
function cacheResults_(): string {
425+
/* Script owner should set up a trigger for this function to cache the test results.
426+
* The badge fetching these Test Results (on README) is set to cache the image after 1 hour.
427+
* GitHub creates anonymized URLs which timeout after 3 seconds,
428+
* which is longer than the time it takes to execute all the tests.
429+
*/
430+
const results = JSON.stringify(RunTests_());
431+
CacheService.getUserCache()!.put('Test Results', results);
432+
return results;
433+
}
434+
424435
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
425436
function doGet(_e: GoogleAppsScript.Events.AppsScriptHttpRequestEvent): GoogleAppsScript.Content.TextOutput {
426-
const response = JSON.stringify(RunTests_());
427-
return ContentService.createTextOutput(response);
437+
const results = CacheService.getUserCache()!.get('Test Results') || cacheResults_();
438+
return ContentService.createTextOutput(results);
428439
}

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "firestore_google-apps-script",
3-
"version": "1.0.28",
3+
"version": "1.0.29",
44
"description": "A Google Apps Script library for accessing Google Cloud Firestore",
55
"homepage": "https://github.com/grahamearley/FirestoreGoogleAppsScript",
66
"bugs": "https://github.com/grahamearley/FirestoreGoogleAppsScript/issues",

0 commit comments

Comments
 (0)