Skip to content

Integration tests for v9 & v9 compat interop #4911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"firebase-namespace-integration-test",
"firebase-firestore-integration-test",
"firebase-messaging-integration-test",
"firebase-compat-interop-test",
"firebase-compat-typings-test",
"@firebase/app-exp",
"@firebase/analytics-compat",
Expand Down
5 changes: 5 additions & 0 deletions .changeset/fuzzy-teachers-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@firebase/component": patch
---

handle `undefined` correctly from input.
35 changes: 35 additions & 0 deletions integration/compat-interop/analytics.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @license
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { getModularInstance } from '@firebase/util';
import { expect } from 'chai';
import { getAnalytics } from '@firebase/analytics-exp';
import firebase from '@firebase/app-compat';
import '@firebase/analytics-compat';

import { TEST_PROJECT_CONFIG } from './util';

firebase.initializeApp(TEST_PROJECT_CONFIG);

const compatAnalytics = firebase.analytics();
const modularAnalytics = getAnalytics();

describe('Analytics compat interop', () => {
it('Analytics compat instance references modular Analytics instance', () => {
expect(getModularInstance(compatAnalytics)).to.equal(modularAnalytics);
});
});
50 changes: 50 additions & 0 deletions integration/compat-interop/app.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* @license
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { getModularInstance } from '@firebase/util';
import { expect } from 'chai';
import { getApp, getApps } from '@firebase/app-exp';
import firebase from '@firebase/app-compat';

import { TEST_PROJECT_CONFIG } from './util';
//TODO: add Storage, Firestore and Database tests once v8 is removed. Currently it's too difficult to set them up in integration tests.
describe('App compat interop', () => {
afterEach(() => {
const deletePromises = [];
for (const app of firebase.apps) {
deletePromises.push(app.delete());
}

return Promise.all(deletePromises);
});

it('App compat instance references modular App instance', () => {
const compatApp = firebase.initializeApp(TEST_PROJECT_CONFIG);
const modularApp = getApp();
expect(getModularInstance(compatApp)).to.equal(modularApp);
});

it('deleting compat app deletes modular app', async () => {
const compatApp = firebase.initializeApp(TEST_PROJECT_CONFIG);
expect(firebase.apps.length).to.equal(1);
expect(getApps().length).to.equal(1);

await compatApp.delete();
expect(firebase.apps.length).to.equal(0);
expect(getApps().length).to.equal(0);
});
});
49 changes: 49 additions & 0 deletions integration/compat-interop/auth.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* @license
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { getModularInstance } from '@firebase/util';
import { expect } from 'chai';
import { getAuth, signOut } from '@firebase/auth-exp';
import firebase from '@firebase/app-compat';
import '@firebase/auth-compat';

import { TEST_PROJECT_CONFIG } from './util';

firebase.initializeApp(TEST_PROJECT_CONFIG);

const compatAuth = firebase.auth();
const modularAuth = getAuth();

describe('Auth compat interop', () => {
it('Auth compat instance references modular Auth instance', () => {
expect(getModularInstance(compatAuth)).to.equal(modularAuth);
});

it('Auth compat and modular Auth share the same user state', async () => {
expect(compatAuth.currentUser).to.equal(null);
expect(modularAuth.currentUser).to.equal(null);
const userCred = await compatAuth.signInAnonymously();
expect(userCred.user?.uid).to.equal(modularAuth.currentUser?.uid);
expect(await userCred.user?.getIdToken()).to.equal(
await modularAuth.currentUser?.getIdToken()
);

await signOut(modularAuth);
expect(compatAuth.currentUser).to.equal(null);
expect(modularAuth.currentUser).to.equal(null);
});
});
35 changes: 35 additions & 0 deletions integration/compat-interop/functions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @license
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { getModularInstance } from '@firebase/util';
import { expect } from 'chai';
import { getFunctions } from '@firebase/functions-exp';
import firebase from '@firebase/app-compat';
import '@firebase/functions-compat';

import { TEST_PROJECT_CONFIG } from './util';

firebase.initializeApp(TEST_PROJECT_CONFIG);

const compatFunction = firebase.functions();
const modularFunctions = getFunctions();

describe('Functions compat interop', () => {
it('Functions compat instance references modular Functions instance', () => {
expect(getModularInstance(compatFunction)).to.equal(modularFunctions);
});
});
36 changes: 36 additions & 0 deletions integration/compat-interop/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* @license
* Copyright 2017 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const karma = require('karma');
const karmaBase = require('../../config/karma.base');

const files = ['*.test.*'];

module.exports = function (config) {
const karmaConfig = Object.assign({}, karmaBase, {
// files to load into karma
files: files,
preprocessors: { '**/*.ts': ['webpack', 'sourcemap'] },
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha']
});

config.set(karmaConfig);
};

module.exports.files = files;
35 changes: 35 additions & 0 deletions integration/compat-interop/messaging.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @license
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { getModularInstance } from '@firebase/util';
import { expect } from 'chai';
import { getMessaging } from '@firebase/messaging-exp';
import firebase from '@firebase/app-compat';
import '@firebase/messaging-compat';

import { TEST_PROJECT_CONFIG } from './util';

firebase.initializeApp(TEST_PROJECT_CONFIG);

const compatMessaging = firebase.messaging();
const modularMessaging = getMessaging();

describe('Messaging compat interop', () => {
it('Messaging compat instance references modular Messaging instance', () => {
expect(getModularInstance(compatMessaging)).to.equal(modularMessaging);
});
});
29 changes: 29 additions & 0 deletions integration/compat-interop/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "firebase-compat-interop-test",
"private": true,
"version": "0.1.0",
"scripts": {
"test": "karma start --single-run",
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test",
"test:debug": "karma start --browsers Chrome --auto-watch"
},
"dependencies": {
"@firebase/app-exp": "0.0.900",
"@firebase/app-compat": "0.0.900",
"@firebase/analytics-exp": "0.0.900",
"@firebase/analytics-compat": "0.0.900",
"@firebase/auth-exp": "0.0.900",
"@firebase/auth-compat": "0.0.900",
"@firebase/functions-exp": "0.0.900",
"@firebase/functions-compat": "0.0.900",
"@firebase/messaging-exp": "0.0.900",
"@firebase/messaging-compat": "0.0.900",
"@firebase/performance-exp": "0.0.900",
"@firebase/performance-compat": "0.0.900",
"@firebase/remote-config-exp": "0.0.900",
"@firebase/remote-config-compat": "0.0.900"
},
"devDependencies": {
"typescript": "4.2.2"
}
}
60 changes: 60 additions & 0 deletions integration/compat-interop/performance.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* @license
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { getModularInstance } from '@firebase/util';
import { expect } from 'chai';
import { getPerformance } from '@firebase/performance-exp';
import firebase from '@firebase/app-compat';
import '@firebase/performance-compat';

import { TEST_PROJECT_CONFIG } from './util';

firebase.initializeApp(TEST_PROJECT_CONFIG);

const compatPerf = firebase.performance();
const modularPerf = getPerformance();

describe('Performance compat interop', () => {
it('Performance compat instance references modular Performance instance', () => {
expect(getModularInstance(compatPerf)).to.equal(modularPerf);
});

it('Performance compat and modular Performance instance share the same configuration', () => {
expect(compatPerf.dataCollectionEnabled).to.equal(true);
expect(compatPerf.instrumentationEnabled).to.equal(true);
expect(modularPerf.dataCollectionEnabled).to.equal(true);
expect(modularPerf.instrumentationEnabled).to.equal(true);

// change settings on the compat instance
compatPerf.dataCollectionEnabled = false;
compatPerf.instrumentationEnabled = false;

expect(compatPerf.dataCollectionEnabled).to.equal(false);
expect(compatPerf.instrumentationEnabled).to.equal(false);
expect(modularPerf.dataCollectionEnabled).to.equal(false);
expect(modularPerf.instrumentationEnabled).to.equal(false);

// change settings on the modular instance
modularPerf.dataCollectionEnabled = true;
modularPerf.instrumentationEnabled = true;

expect(compatPerf.dataCollectionEnabled).to.equal(true);
expect(compatPerf.instrumentationEnabled).to.equal(true);
expect(modularPerf.dataCollectionEnabled).to.equal(true);
expect(modularPerf.instrumentationEnabled).to.equal(true);
});
});
35 changes: 35 additions & 0 deletions integration/compat-interop/remote-config.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @license
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { getModularInstance } from '@firebase/util';
import { expect } from 'chai';
import { getRemoteConfig } from '@firebase/remote-config-exp';
import firebase from '@firebase/app-compat';
import '@firebase/remote-config-compat';

import { TEST_PROJECT_CONFIG } from './util';

firebase.initializeApp(TEST_PROJECT_CONFIG);

const compatRC = firebase.remoteConfig();
const modularRC = getRemoteConfig();

describe('RC compat interop', () => {
it('RC compat instance references modular RC instance', () => {
expect(getModularInstance(compatRC)).to.equal(modularRC);
});
});
Loading