From 3e2be998df812ddc12f68f091bda3441e54c5839 Mon Sep 17 00:00:00 2001 From: Denver Coneybeare Date: Thu, 20 Apr 2023 12:24:10 -0400 Subject: [PATCH 1/5] Firestore: database.test.ts: add tests for coercing experimentalForceLongPolling and experimentalAutoDetectLongPolling to boolean --- .../firestore/test/unit/api/database.test.ts | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/packages/firestore/test/unit/api/database.test.ts b/packages/firestore/test/unit/api/database.test.ts index 38f4c4eedd0..93e47b360f7 100644 --- a/packages/firestore/test/unit/api/database.test.ts +++ b/packages/firestore/test/unit/api/database.test.ts @@ -359,6 +359,42 @@ describe('Settings', () => { expect(db._getSettings().experimentalForceLongPolling).to.be.false; }); + it('long polling autoDetect=[something truthy] is corced to true', () => { + // Use a new instance of Firestore in order to configure settings. + const db = newTestFirestore(); + db._setSettings({ + experimentalAutoDetectLongPolling: 1 as any, + }); + expect(db._getSettings().experimentalAutoDetectLongPolling).to.be.true; + }); + + it('long polling autoDetect=[something falsy] is corced to false', () => { + // Use a new instance of Firestore in order to configure settings. + const db = newTestFirestore(); + db._setSettings({ + experimentalAutoDetectLongPolling: 0 as any, + }); + expect(db._getSettings().experimentalAutoDetectLongPolling).to.be.false; + }); + + it('long polling force=[something truthy] is corced to true', () => { + // Use a new instance of Firestore in order to configure settings. + const db = newTestFirestore(); + db._setSettings({ + experimentalForceLongPolling: "I am truthy" as any, + }); + expect(db._getSettings().experimentalForceLongPolling).to.be.true; + }); + + it('long polling force=[something falsy] is corced to false', () => { + // Use a new instance of Firestore in order to configure settings. + const db = newTestFirestore(); + db._setSettings({ + experimentalForceLongPolling: NaN as any, + }); + expect(db._getSettings().experimentalForceLongPolling).to.be.false; + }); + it('gets settings from useEmulator', () => { // Use a new instance of Firestore in order to configure settings. const db = newTestFirestore(); From d8fccbea6de14057309948cdbbd2a77769c919a2 Mon Sep 17 00:00:00 2001 From: Denver Coneybeare Date: Thu, 20 Apr 2023 12:28:56 -0400 Subject: [PATCH 2/5] yarn prettier --- packages/firestore/test/unit/api/database.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/firestore/test/unit/api/database.test.ts b/packages/firestore/test/unit/api/database.test.ts index 93e47b360f7..5f7ffbf419e 100644 --- a/packages/firestore/test/unit/api/database.test.ts +++ b/packages/firestore/test/unit/api/database.test.ts @@ -363,7 +363,7 @@ describe('Settings', () => { // Use a new instance of Firestore in order to configure settings. const db = newTestFirestore(); db._setSettings({ - experimentalAutoDetectLongPolling: 1 as any, + experimentalAutoDetectLongPolling: 1 as any }); expect(db._getSettings().experimentalAutoDetectLongPolling).to.be.true; }); @@ -372,7 +372,7 @@ describe('Settings', () => { // Use a new instance of Firestore in order to configure settings. const db = newTestFirestore(); db._setSettings({ - experimentalAutoDetectLongPolling: 0 as any, + experimentalAutoDetectLongPolling: 0 as any }); expect(db._getSettings().experimentalAutoDetectLongPolling).to.be.false; }); @@ -381,7 +381,7 @@ describe('Settings', () => { // Use a new instance of Firestore in order to configure settings. const db = newTestFirestore(); db._setSettings({ - experimentalForceLongPolling: "I am truthy" as any, + experimentalForceLongPolling: 'I am truthy' as any }); expect(db._getSettings().experimentalForceLongPolling).to.be.true; }); @@ -390,7 +390,7 @@ describe('Settings', () => { // Use a new instance of Firestore in order to configure settings. const db = newTestFirestore(); db._setSettings({ - experimentalForceLongPolling: NaN as any, + experimentalForceLongPolling: NaN as any }); expect(db._getSettings().experimentalForceLongPolling).to.be.false; }); From 74278583e313401753b6ed6ffc75243cc99ea432 Mon Sep 17 00:00:00 2001 From: Denver Coneybeare Date: Thu, 20 Apr 2023 12:35:03 -0400 Subject: [PATCH 3/5] tweak unit test descriptions --- packages/firestore/test/unit/api/database.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/firestore/test/unit/api/database.test.ts b/packages/firestore/test/unit/api/database.test.ts index 5f7ffbf419e..8d6a08977e4 100644 --- a/packages/firestore/test/unit/api/database.test.ts +++ b/packages/firestore/test/unit/api/database.test.ts @@ -359,7 +359,7 @@ describe('Settings', () => { expect(db._getSettings().experimentalForceLongPolling).to.be.false; }); - it('long polling autoDetect=[something truthy] is corced to true', () => { + it('long polling autoDetect=[something truthy] should be coerced to true', () => { // Use a new instance of Firestore in order to configure settings. const db = newTestFirestore(); db._setSettings({ @@ -368,7 +368,7 @@ describe('Settings', () => { expect(db._getSettings().experimentalAutoDetectLongPolling).to.be.true; }); - it('long polling autoDetect=[something falsy] is corced to false', () => { + it('long polling autoDetect=[something falsy] should be coerced to false', () => { // Use a new instance of Firestore in order to configure settings. const db = newTestFirestore(); db._setSettings({ @@ -377,7 +377,7 @@ describe('Settings', () => { expect(db._getSettings().experimentalAutoDetectLongPolling).to.be.false; }); - it('long polling force=[something truthy] is corced to true', () => { + it('long polling force=[something truthy] should be coerced to true', () => { // Use a new instance of Firestore in order to configure settings. const db = newTestFirestore(); db._setSettings({ @@ -386,7 +386,7 @@ describe('Settings', () => { expect(db._getSettings().experimentalForceLongPolling).to.be.true; }); - it('long polling force=[something falsy] is corced to false', () => { + it('long polling force=[something falsy] should be coerced to false', () => { // Use a new instance of Firestore in order to configure settings. const db = newTestFirestore(); db._setSettings({ From 81a61b465af7d63569dbc20e6e83e46d9d751450 Mon Sep 17 00:00:00 2001 From: Denver Coneybeare Date: Thu, 20 Apr 2023 12:59:32 -0400 Subject: [PATCH 4/5] add `// eslint-disable-next-line @typescript-eslint/no-explicit-any` lines to make lint happy --- packages/firestore/test/unit/api/database.test.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/firestore/test/unit/api/database.test.ts b/packages/firestore/test/unit/api/database.test.ts index 8d6a08977e4..7668c3d0679 100644 --- a/packages/firestore/test/unit/api/database.test.ts +++ b/packages/firestore/test/unit/api/database.test.ts @@ -363,6 +363,7 @@ describe('Settings', () => { // Use a new instance of Firestore in order to configure settings. const db = newTestFirestore(); db._setSettings({ + // eslint-disable-next-line @typescript-eslint/no-explicit-any experimentalAutoDetectLongPolling: 1 as any }); expect(db._getSettings().experimentalAutoDetectLongPolling).to.be.true; @@ -372,6 +373,7 @@ describe('Settings', () => { // Use a new instance of Firestore in order to configure settings. const db = newTestFirestore(); db._setSettings({ + // eslint-disable-next-line @typescript-eslint/no-explicit-any experimentalAutoDetectLongPolling: 0 as any }); expect(db._getSettings().experimentalAutoDetectLongPolling).to.be.false; @@ -381,6 +383,7 @@ describe('Settings', () => { // Use a new instance of Firestore in order to configure settings. const db = newTestFirestore(); db._setSettings({ + // eslint-disable-next-line @typescript-eslint/no-explicit-any experimentalForceLongPolling: 'I am truthy' as any }); expect(db._getSettings().experimentalForceLongPolling).to.be.true; @@ -390,6 +393,7 @@ describe('Settings', () => { // Use a new instance of Firestore in order to configure settings. const db = newTestFirestore(); db._setSettings({ + // eslint-disable-next-line @typescript-eslint/no-explicit-any experimentalForceLongPolling: NaN as any }); expect(db._getSettings().experimentalForceLongPolling).to.be.false; From f8994da2152cc7385a83e0b3386489307d6ac0ae Mon Sep 17 00:00:00 2001 From: Denver Coneybeare Date: Thu, 20 Apr 2023 15:39:18 -0400 Subject: [PATCH 5/5] add tests for null being treated as falsy --- .../firestore/test/unit/api/database.test.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/firestore/test/unit/api/database.test.ts b/packages/firestore/test/unit/api/database.test.ts index 7668c3d0679..ea79c398bfc 100644 --- a/packages/firestore/test/unit/api/database.test.ts +++ b/packages/firestore/test/unit/api/database.test.ts @@ -379,6 +379,16 @@ describe('Settings', () => { expect(db._getSettings().experimentalAutoDetectLongPolling).to.be.false; }); + it('long polling autoDetect=null should be coerced to false', () => { + // Use a new instance of Firestore in order to configure settings. + const db = newTestFirestore(); + db._setSettings({ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + experimentalAutoDetectLongPolling: null as any + }); + expect(db._getSettings().experimentalAutoDetectLongPolling).to.be.false; + }); + it('long polling force=[something truthy] should be coerced to true', () => { // Use a new instance of Firestore in order to configure settings. const db = newTestFirestore(); @@ -399,6 +409,16 @@ describe('Settings', () => { expect(db._getSettings().experimentalForceLongPolling).to.be.false; }); + it('long polling force=null should be coerced to false', () => { + // Use a new instance of Firestore in order to configure settings. + const db = newTestFirestore(); + db._setSettings({ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + experimentalForceLongPolling: null as any + }); + expect(db._getSettings().experimentalForceLongPolling).to.be.false; + }); + it('gets settings from useEmulator', () => { // Use a new instance of Firestore in order to configure settings. const db = newTestFirestore();