diff --git a/samples/package.json b/samples/package.json index f3890539..71b15b52 100644 --- a/samples/package.json +++ b/samples/package.json @@ -13,7 +13,8 @@ "node": ">=14.0.0" }, "scripts": { - "test": "mocha --timeout 200000" + "test": "mocha --timeout 200000", + "fix": "gts fix" }, "dependencies": { "@google-cloud/bigquery": "^7.3.0", @@ -25,6 +26,7 @@ "devDependencies": { "@google-cloud/datacatalog": "^4.0.0", "chai": "^4.2.0", + "gts": "^5.0.0", "mocha": "^8.0.0", "proxyquire": "^2.1.3", "sinon": "^17.0.0", diff --git a/samples/test/authViewTutorial.test.js b/samples/test/authViewTutorial.test.js index 15c432ab..ee0f4827 100644 --- a/samples/test/authViewTutorial.test.js +++ b/samples/test/authViewTutorial.test.js @@ -15,7 +15,7 @@ 'use strict'; const {assert} = require('chai'); -const {describe, it, before, after} = require('mocha'); +const {describe, it, before, beforeEach, after} = require('mocha'); const cp = require('child_process'); const uuid = require('uuid'); @@ -55,6 +55,10 @@ describe('Authorized View Tutorial', () => { projectId = tableData.metadata.tableReference.projectId; }); + beforeEach(async function () { + this.currentTest.retries(2); + }); + it('should create an authorized view', async () => { const output = execSync( `node authViewTutorial.js ${projectId} ${sourceDatasetId} ${sourceTableId} ${sharedDatasetId} ${sharedViewId}` diff --git a/samples/test/datasets.test.js b/samples/test/datasets.test.js index cc0e1b2c..6a0b5c82 100644 --- a/samples/test/datasets.test.js +++ b/samples/test/datasets.test.js @@ -16,7 +16,7 @@ const {BigQuery} = require('@google-cloud/bigquery'); const {assert} = require('chai'); -const {describe, it, after, before} = require('mocha'); +const {describe, it, after, before, beforeEach} = require('mocha'); const cp = require('child_process'); const uuid = require('uuid'); @@ -35,6 +35,10 @@ describe('Datasets', () => { await deleteDatasets(); }); + beforeEach(async function () { + this.currentTest.retries(2); + }); + after(async () => { await bigquery.dataset(datasetId).delete({force: true}).catch(console.warn); }); diff --git a/samples/test/jobs.test.js b/samples/test/jobs.test.js index 068117d9..1190bf06 100644 --- a/samples/test/jobs.test.js +++ b/samples/test/jobs.test.js @@ -16,7 +16,7 @@ const {BigQuery} = require('@google-cloud/bigquery'); const {assert} = require('chai'); -const {describe, it, before} = require('mocha'); +const {describe, it, before, beforeEach} = require('mocha'); const cp = require('child_process'); const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); @@ -34,6 +34,9 @@ describe('Jobs', () => { const queryOptions = { query: query, }; + beforeEach(async function () { + this.currentTest.retries(2); + }); const [job] = await bigquery.createQueryJob(queryOptions); jobId = job.metadata.jobReference.jobId; diff --git a/samples/test/models.test.js b/samples/test/models.test.js index 90904621..48764cdb 100644 --- a/samples/test/models.test.js +++ b/samples/test/models.test.js @@ -16,7 +16,7 @@ const {BigQuery} = require('@google-cloud/bigquery'); const {assert} = require('chai'); -const {describe, it, before, after} = require('mocha'); +const {describe, it, before, beforeEach, after} = require('mocha'); const cp = require('child_process'); const uuid = require('uuid'); @@ -64,6 +64,10 @@ describe('Models', function () { await job.getQueryResults(); }); + beforeEach(async function () { + this.currentTest.retries(2); + }); + after(async () => { await bigquery.dataset(datasetId).delete({force: true}).catch(console.warn); }); @@ -108,6 +112,10 @@ describe('Create/Delete Model', () => { await bigquery.createDataset(datasetId, datasetOptions); }); + beforeEach(async function () { + this.currentTest.retries(2); + }); + after(async () => { await bigquery.dataset(datasetId).delete({force: true}).catch(console.warn); }); diff --git a/samples/test/queries.test.js b/samples/test/queries.test.js index beaedeed..00c322a5 100644 --- a/samples/test/queries.test.js +++ b/samples/test/queries.test.js @@ -15,7 +15,7 @@ 'use strict'; const {assert} = require('chai'); -const {describe, it, before, after} = require('mocha'); +const {describe, it, before, beforeEach, after} = require('mocha'); const cp = require('child_process'); const uuid = require('uuid'); @@ -50,6 +50,10 @@ describe('Queries', () => { projectId = tableData.metadata.tableReference.projectId; }); + beforeEach(async function () { + this.currentTest.retries(2); + }); + after(async () => { await bigquery.dataset(datasetId).delete({force: true}).catch(console.warn); }); diff --git a/samples/test/quickstart.test.js b/samples/test/quickstart.test.js index 4428a822..d9cd0a22 100644 --- a/samples/test/quickstart.test.js +++ b/samples/test/quickstart.test.js @@ -15,7 +15,7 @@ 'use strict'; const {assert} = require('chai'); -const {describe, it, after} = require('mocha'); +const {describe, it, after, beforeEach} = require('mocha'); const uuid = require('uuid'); const cp = require('child_process'); const {BigQuery} = require('@google-cloud/bigquery'); @@ -29,7 +29,9 @@ describe('Quickstart', () => { /-/gi, '_' ); - + beforeEach(async function () { + this.currentTest.retries(2); + }); after(async () => { await bigquery.dataset(datasetName).delete({force: true}); }); diff --git a/samples/test/routines.test.js b/samples/test/routines.test.js index 266da7ac..bee3f01d 100644 --- a/samples/test/routines.test.js +++ b/samples/test/routines.test.js @@ -15,7 +15,7 @@ 'use strict'; const {assert} = require('chai'); -const {describe, it, before, after} = require('mocha'); +const {describe, it, before, beforeEach, after} = require('mocha'); const cp = require('child_process'); const uuid = require('uuid'); @@ -61,6 +61,10 @@ describe('Routines', () => { await routine.create(config); }); + beforeEach(async function () { + this.currentTest.retries(2); + }); + it('should create a routine', async () => { const output = execSync( `node createRoutine.js ${datasetId} ${newRoutineId}` @@ -111,6 +115,10 @@ describe('Routines', () => { await routine.create(config); }); + beforeEach(async function () { + this.currentTest.retries(2); + }); + after(async () => { await bigquery .dataset(datasetId) diff --git a/samples/test/tables.test.js b/samples/test/tables.test.js index e7f94c5f..a2ebae8b 100644 --- a/samples/test/tables.test.js +++ b/samples/test/tables.test.js @@ -96,7 +96,9 @@ describe('Tables', () => { }); // to avoid getting rate limited - beforeEach(done => setTimeout(done, 500)); + beforeEach(async function () { + this.currentTest.retries(2); + }); after(async () => { await bigquery @@ -619,6 +621,10 @@ describe('Tables', () => { }); describe('Views', () => { + beforeEach(async function () { + this.currentTest.retries(2); + }); + it('should create a view', async () => { const output = execSync(`node createView.js ${datasetId} ${viewId}`); assert.include(output, `View ${viewId} created.`); @@ -657,6 +663,10 @@ describe('Tables', () => { await bigquery.dataset(datasetId).createTable(tableId, tableOptions); }); + beforeEach(async function () { + this.currentTest.retries(2); + }); + after(async () => { await bigquery .dataset(datasetId)