@sprucelabs/jest-sheets-reporter 1.3.37 → 1.3.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,7 +17,7 @@ const SheetsReporterUtility_1 = require("../../SheetsReporterUtility");
17
17
  require('dotenv').config();
18
18
  class SheetsReporterTest extends AbstractSheetsReporterTest_1.default {
19
19
  static async beforeAll() {
20
- this.worksheetId = await this.sheetsAdapter.generateRandomWorksheet(this.sheetId);
20
+ this.worksheetId = await this.sheetsAdapter.createRandomWorksheet(this.sheetId);
21
21
  }
22
22
  static async beforeEach() {
23
23
  await super.beforeEach();
@@ -51,14 +51,14 @@ class SheetsReporterTest extends AbstractSheetsReporterTest_1.default {
51
51
  test_1.assert.isEqual(value, 1);
52
52
  }
53
53
  static async canUpdateAllTestsAfterCompletion() {
54
- await this.reporter.onTestResult({}, { testResults: this.testResults });
54
+ this.reporter.onTestResult({}, { testResults: this.testResults });
55
55
  const value = await this.sheetsAdapter.fetchCellValue(this.sheetId, this.worksheetId, 'B1');
56
56
  test_1.assert.isEqual(value, 1);
57
57
  const value2 = await this.sheetsAdapter.fetchCellValue(this.sheetId, this.worksheetId, 'B2');
58
58
  test_1.assert.isEqual(value2, 0);
59
59
  }
60
60
  static async canSetWorksheetIdInCell(cell) {
61
- const worksheetId = await this.sheetsAdapter.generateRandomWorksheet(this.sheetId);
61
+ const worksheetId = await this.sheetsAdapter.createRandomWorksheet(this.sheetId);
62
62
  this.testMap.canBootCliInDifferentWorksheet = `${worksheetId}:${cell}`;
63
63
  await this.reporter.reportTestAsPassed('canBootCliInDifferentWorksheet');
64
64
  const value = await this.sheetsAdapter.fetchCellValue(this.sheetId, worksheetId, cell);
@@ -105,7 +105,7 @@ __decorate([
105
105
  (0, test_1.test)()
106
106
  ], SheetsReporterTest, "canUpdateAllTestsAfterCompletion", null);
107
107
  __decorate([
108
- test_1.test.only('can update in another worksheet 1', 'B1'),
109
- test_1.test.only('can update in another worksheet 2', 'B2')
108
+ (0, test_1.test)('can update in another worksheet 1', 'B1'),
109
+ (0, test_1.test)('can update in another worksheet 2', 'B2')
110
110
  ], SheetsReporterTest, "canSetWorksheetIdInCell", null);
111
111
  exports.default = SheetsReporterTest;
@@ -7,4 +7,5 @@ export default class SheetsAdapterTest extends AbstractSheetsReporterTest {
7
7
  protected static beforeAll(): Promise<void>;
8
8
  protected static afterAll(): Promise<void>;
9
9
  protected static canUpdateCell(expected: string | number | boolean): Promise<void>;
10
+ protected static updatingCellManyTimesAtOnceDoesNotHitRateLimit(): Promise<void>;
10
11
  }
@@ -27,7 +27,7 @@ class SheetsAdapterTest extends AbstractSheetsReporterTest_1.default {
27
27
  });
28
28
  }
29
29
  static async beforeAll() {
30
- this.worksheetId = await this.sheetsAdapter.generateRandomWorksheet(this.sheetId);
30
+ this.worksheetId = await this.sheetsAdapter.createRandomWorksheet(this.sheetId);
31
31
  }
32
32
  static async afterAll() {
33
33
  await super.afterAll();
@@ -46,6 +46,16 @@ class SheetsAdapterTest extends AbstractSheetsReporterTest_1.default {
46
46
  const actualValue = await this.sheetsAdapter.fetchCellValue(sheetId, worksheetId, 'A1');
47
47
  test_1.assert.isEqual(actualValue, expected);
48
48
  }
49
+ static async updatingCellManyTimesAtOnceDoesNotHitRateLimit() {
50
+ await Promise.all(new Array(75).fill(0).map(async (_, idx) => {
51
+ await this.adapter.updateCell({
52
+ sheetId: this.sheetId,
53
+ worksheetId: this.worksheetId,
54
+ cell: 'A1',
55
+ value: idx,
56
+ });
57
+ }));
58
+ }
49
59
  }
50
60
  SheetsAdapterTest.sheetId = '1MFb9AkB8sm7rurYew8hgzrXTz3JDxOFhl4kN9sNQVxw';
51
61
  __decorate([
@@ -53,4 +63,7 @@ __decorate([
53
63
  (0, test_1.test)('can set a boolean value', true),
54
64
  (0, test_1.test)('can set string value', 'it worked!')
55
65
  ], SheetsAdapterTest, "canUpdateCell", null);
66
+ __decorate([
67
+ (0, test_1.test)()
68
+ ], SheetsAdapterTest, "updatingCellManyTimesAtOnceDoesNotHitRateLimit", null);
56
69
  exports.default = SheetsAdapterTest;
@@ -11,6 +11,7 @@ export default class SheetsReporterGoogleAdapter implements IGoogleSheetsAdapter
11
11
  cell: string;
12
12
  value: string | number | boolean;
13
13
  }): Promise<void>;
14
+ private retriedUpdateCell;
14
15
  protected fetchSheetAndCell(sheetId: string, worksheetId: number, cellLookup: string): Promise<{
15
16
  cell: import("google-spreadsheet").GoogleSpreadsheetCell;
16
17
  sheet: import("google-spreadsheet").GoogleSpreadsheetWorksheet;
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  const google_spreadsheet_1 = require("google-spreadsheet");
7
+ const retry_1 = __importDefault(require("retry"));
4
8
  class SheetsReporterGoogleAdapter {
5
9
  constructor(options) {
6
10
  this.spreadsheetInstancesById = {};
@@ -20,10 +24,31 @@ class SheetsReporterGoogleAdapter {
20
24
  this.privateKey = privateKey;
21
25
  }
22
26
  async updateCell(options) {
27
+ await new Promise((resolve, reject) => {
28
+ void this.retriedUpdateCell(options, resolve, reject);
29
+ });
30
+ }
31
+ async retriedUpdateCell(options, resolve, reject) {
23
32
  const { sheetId, worksheetId, value, cell: cellLookup } = options;
24
- const { cell, sheet } = await this.fetchSheetAndCell(sheetId, worksheetId, cellLookup);
25
- cell.value = value;
26
- await sheet.saveUpdatedCells();
33
+ const operation = retry_1.default.operation({
34
+ factor: 2,
35
+ retries: 10,
36
+ randomize: true,
37
+ });
38
+ operation.attempt(async () => {
39
+ try {
40
+ const { cell, sheet } = await this.fetchSheetAndCell(sheetId, worksheetId, cellLookup);
41
+ cell.value = value;
42
+ await sheet.saveUpdatedCells();
43
+ resolve();
44
+ }
45
+ catch (err) {
46
+ if (operation.retry(err)) {
47
+ return;
48
+ }
49
+ reject(operation.mainError());
50
+ }
51
+ });
27
52
  }
28
53
  async fetchSheetAndCell(sheetId, worksheetId, cellLookup) {
29
54
  const spreadsheet = await this.fetchSpreadsheet(sheetId);
@@ -9,6 +9,6 @@ export default class SheetsReporterMockAdapter extends SheetsReporterTestAdapter
9
9
  value: string | number | boolean;
10
10
  }): Promise<void>;
11
11
  fetchCellValue(sheetId: string, worksheetId: number, cell: string): Promise<string | number | boolean>;
12
- generateRandomWorksheet(): Promise<number>;
12
+ createRandomWorksheet(): Promise<number>;
13
13
  deleteWorksheet(): Promise<void>;
14
14
  }
@@ -16,7 +16,7 @@ class SheetsReporterMockAdapter extends TestAdapter_1.default {
16
16
  const key = `${sheetId}${worksheetId}${cell}`;
17
17
  return SheetsReporterMockAdapter.cellCache[key];
18
18
  }
19
- async generateRandomWorksheet() {
19
+ async createRandomWorksheet() {
20
20
  return -1;
21
21
  }
22
22
  async deleteWorksheet() { }
@@ -1,8 +1,8 @@
1
1
  import SheetsReporterGoogleAdapter from './GoogleAdapter';
2
2
  export default class SheetsReporterTestAdapter extends SheetsReporterGoogleAdapter {
3
- private randomCount;
3
+ private static randomCount;
4
4
  fetchCellValue(sheetId: string, worksheetId: number, cell: string): Promise<string | number | boolean>;
5
- generateRandomWorksheet(sheetId: string): Promise<number>;
5
+ createRandomWorksheet(sheetId: string): Promise<number>;
6
6
  deleteWorksheet(sheetId: string, worksheetId: number): Promise<void>;
7
7
  protected fetchSpreadsheet(sheetId: string): Promise<import("google-spreadsheet").GoogleSpreadsheet>;
8
8
  }
@@ -5,19 +5,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const GoogleAdapter_1 = __importDefault(require("./GoogleAdapter"));
7
7
  class SheetsReporterTestAdapter extends GoogleAdapter_1.default {
8
- constructor() {
9
- super(...arguments);
10
- this.randomCount = 0;
11
- }
12
8
  async fetchCellValue(sheetId, worksheetId, cell) {
13
9
  const results = await this.fetchSheetAndCell(sheetId, worksheetId, cell);
14
10
  return results.cell.value;
15
11
  }
16
- async generateRandomWorksheet(sheetId) {
17
- const name = `TEST.${Date.now()}-${this.randomCount}`;
12
+ async createRandomWorksheet(sheetId) {
13
+ const name = `TEST.${Date.now()}-${SheetsReporterTestAdapter.randomCount}`;
18
14
  const sheet = await this.fetchSpreadsheet(sheetId);
19
15
  const worksheet = await sheet.addWorksheet({ title: name });
20
- this.randomCount++;
16
+ SheetsReporterTestAdapter.randomCount++;
21
17
  return parseInt(worksheet.sheetId, 10);
22
18
  }
23
19
  async deleteWorksheet(sheetId, worksheetId) {
@@ -30,3 +26,4 @@ class SheetsReporterTestAdapter extends GoogleAdapter_1.default {
30
26
  }
31
27
  }
32
28
  exports.default = SheetsReporterTestAdapter;
29
+ SheetsReporterTestAdapter.randomCount = 0;
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "@sprucelabs/resolve-path-aliases"
14
14
  ]
15
15
  },
16
- "version": "1.3.37",
16
+ "version": "1.3.38",
17
17
  "main": "./build/SheetsReporter.js",
18
18
  "types": "./build/SheetsReporter.d.ts",
19
19
  "description": "Have your Jest tests update a Google Spreadsheet™®©. 📡",
@@ -57,7 +57,8 @@
57
57
  },
58
58
  "dependencies": {
59
59
  "dotenv": "^16.0.0",
60
- "google-spreadsheet": "^3.2.0"
60
+ "google-spreadsheet": "^3.2.0",
61
+ "retry": "^0.13.1"
61
62
  },
62
63
  "devDependencies": {
63
64
  "@sprucelabs/resolve-path-aliases": "^1.0.244",