Skip to content

Commit 5fbc5fb

Browse files
authored
Integration tests for v9 & v9 compat interop (#4911)
* auth compat interop test * add compat interop integration tests * use scoped packages for integration tests * fix package name * ignore firebase-compat-interop-test in changeset * better handling of input * Create fuzzy-teachers-guess.md
1 parent 32c3f79 commit 5fbc5fb

File tree

18 files changed

+439
-10
lines changed

18 files changed

+439
-10
lines changed

.changeset/config.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"firebase-namespace-integration-test",
1414
"firebase-firestore-integration-test",
1515
"firebase-messaging-integration-test",
16+
"firebase-compat-interop-test",
1617
"firebase-compat-typings-test",
1718
"@firebase/app-exp",
1819
"@firebase/analytics-compat",

.changeset/fuzzy-teachers-guess.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@firebase/component": patch
3+
---
4+
5+
handle `undefined` correctly from input.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @license
3+
* Copyright 2021 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { getModularInstance } from '@firebase/util';
19+
import { expect } from 'chai';
20+
import { getAnalytics } from '@firebase/analytics-exp';
21+
import firebase from '@firebase/app-compat';
22+
import '@firebase/analytics-compat';
23+
24+
import { TEST_PROJECT_CONFIG } from './util';
25+
26+
firebase.initializeApp(TEST_PROJECT_CONFIG);
27+
28+
const compatAnalytics = firebase.analytics();
29+
const modularAnalytics = getAnalytics();
30+
31+
describe('Analytics compat interop', () => {
32+
it('Analytics compat instance references modular Analytics instance', () => {
33+
expect(getModularInstance(compatAnalytics)).to.equal(modularAnalytics);
34+
});
35+
});
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* @license
3+
* Copyright 2021 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { getModularInstance } from '@firebase/util';
19+
import { expect } from 'chai';
20+
import { getApp, getApps } from '@firebase/app-exp';
21+
import firebase from '@firebase/app-compat';
22+
23+
import { TEST_PROJECT_CONFIG } from './util';
24+
//TODO: add Storage, Firestore and Database tests once v8 is removed. Currently it's too difficult to set them up in integration tests.
25+
describe('App compat interop', () => {
26+
afterEach(() => {
27+
const deletePromises = [];
28+
for (const app of firebase.apps) {
29+
deletePromises.push(app.delete());
30+
}
31+
32+
return Promise.all(deletePromises);
33+
});
34+
35+
it('App compat instance references modular App instance', () => {
36+
const compatApp = firebase.initializeApp(TEST_PROJECT_CONFIG);
37+
const modularApp = getApp();
38+
expect(getModularInstance(compatApp)).to.equal(modularApp);
39+
});
40+
41+
it('deleting compat app deletes modular app', async () => {
42+
const compatApp = firebase.initializeApp(TEST_PROJECT_CONFIG);
43+
expect(firebase.apps.length).to.equal(1);
44+
expect(getApps().length).to.equal(1);
45+
46+
await compatApp.delete();
47+
expect(firebase.apps.length).to.equal(0);
48+
expect(getApps().length).to.equal(0);
49+
});
50+
});
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* @license
3+
* Copyright 2021 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { getModularInstance } from '@firebase/util';
19+
import { expect } from 'chai';
20+
import { getAuth, signOut } from '@firebase/auth-exp';
21+
import firebase from '@firebase/app-compat';
22+
import '@firebase/auth-compat';
23+
24+
import { TEST_PROJECT_CONFIG } from './util';
25+
26+
firebase.initializeApp(TEST_PROJECT_CONFIG);
27+
28+
const compatAuth = firebase.auth();
29+
const modularAuth = getAuth();
30+
31+
describe('Auth compat interop', () => {
32+
it('Auth compat instance references modular Auth instance', () => {
33+
expect(getModularInstance(compatAuth)).to.equal(modularAuth);
34+
});
35+
36+
it('Auth compat and modular Auth share the same user state', async () => {
37+
expect(compatAuth.currentUser).to.equal(null);
38+
expect(modularAuth.currentUser).to.equal(null);
39+
const userCred = await compatAuth.signInAnonymously();
40+
expect(userCred.user?.uid).to.equal(modularAuth.currentUser?.uid);
41+
expect(await userCred.user?.getIdToken()).to.equal(
42+
await modularAuth.currentUser?.getIdToken()
43+
);
44+
45+
await signOut(modularAuth);
46+
expect(compatAuth.currentUser).to.equal(null);
47+
expect(modularAuth.currentUser).to.equal(null);
48+
});
49+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @license
3+
* Copyright 2021 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { getModularInstance } from '@firebase/util';
19+
import { expect } from 'chai';
20+
import { getFunctions } from '@firebase/functions-exp';
21+
import firebase from '@firebase/app-compat';
22+
import '@firebase/functions-compat';
23+
24+
import { TEST_PROJECT_CONFIG } from './util';
25+
26+
firebase.initializeApp(TEST_PROJECT_CONFIG);
27+
28+
const compatFunction = firebase.functions();
29+
const modularFunctions = getFunctions();
30+
31+
describe('Functions compat interop', () => {
32+
it('Functions compat instance references modular Functions instance', () => {
33+
expect(getModularInstance(compatFunction)).to.equal(modularFunctions);
34+
});
35+
});
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* @license
3+
* Copyright 2017 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
const karma = require('karma');
19+
const karmaBase = require('../../config/karma.base');
20+
21+
const files = ['*.test.*'];
22+
23+
module.exports = function (config) {
24+
const karmaConfig = Object.assign({}, karmaBase, {
25+
// files to load into karma
26+
files: files,
27+
preprocessors: { '**/*.ts': ['webpack', 'sourcemap'] },
28+
// frameworks to use
29+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
30+
frameworks: ['mocha']
31+
});
32+
33+
config.set(karmaConfig);
34+
};
35+
36+
module.exports.files = files;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @license
3+
* Copyright 2021 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { getModularInstance } from '@firebase/util';
19+
import { expect } from 'chai';
20+
import { getMessaging } from '@firebase/messaging-exp';
21+
import firebase from '@firebase/app-compat';
22+
import '@firebase/messaging-compat';
23+
24+
import { TEST_PROJECT_CONFIG } from './util';
25+
26+
firebase.initializeApp(TEST_PROJECT_CONFIG);
27+
28+
const compatMessaging = firebase.messaging();
29+
const modularMessaging = getMessaging();
30+
31+
describe('Messaging compat interop', () => {
32+
it('Messaging compat instance references modular Messaging instance', () => {
33+
expect(getModularInstance(compatMessaging)).to.equal(modularMessaging);
34+
});
35+
});
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "firebase-compat-interop-test",
3+
"private": true,
4+
"version": "0.1.0",
5+
"scripts": {
6+
"test": "karma start --single-run",
7+
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test",
8+
"test:debug": "karma start --browsers Chrome --auto-watch"
9+
},
10+
"dependencies": {
11+
"@firebase/app-exp": "0.0.900",
12+
"@firebase/app-compat": "0.0.900",
13+
"@firebase/analytics-exp": "0.0.900",
14+
"@firebase/analytics-compat": "0.0.900",
15+
"@firebase/auth-exp": "0.0.900",
16+
"@firebase/auth-compat": "0.0.900",
17+
"@firebase/functions-exp": "0.0.900",
18+
"@firebase/functions-compat": "0.0.900",
19+
"@firebase/messaging-exp": "0.0.900",
20+
"@firebase/messaging-compat": "0.0.900",
21+
"@firebase/performance-exp": "0.0.900",
22+
"@firebase/performance-compat": "0.0.900",
23+
"@firebase/remote-config-exp": "0.0.900",
24+
"@firebase/remote-config-compat": "0.0.900"
25+
},
26+
"devDependencies": {
27+
"typescript": "4.2.2"
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* @license
3+
* Copyright 2021 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { getModularInstance } from '@firebase/util';
19+
import { expect } from 'chai';
20+
import { getPerformance } from '@firebase/performance-exp';
21+
import firebase from '@firebase/app-compat';
22+
import '@firebase/performance-compat';
23+
24+
import { TEST_PROJECT_CONFIG } from './util';
25+
26+
firebase.initializeApp(TEST_PROJECT_CONFIG);
27+
28+
const compatPerf = firebase.performance();
29+
const modularPerf = getPerformance();
30+
31+
describe('Performance compat interop', () => {
32+
it('Performance compat instance references modular Performance instance', () => {
33+
expect(getModularInstance(compatPerf)).to.equal(modularPerf);
34+
});
35+
36+
it('Performance compat and modular Performance instance share the same configuration', () => {
37+
expect(compatPerf.dataCollectionEnabled).to.equal(true);
38+
expect(compatPerf.instrumentationEnabled).to.equal(true);
39+
expect(modularPerf.dataCollectionEnabled).to.equal(true);
40+
expect(modularPerf.instrumentationEnabled).to.equal(true);
41+
42+
// change settings on the compat instance
43+
compatPerf.dataCollectionEnabled = false;
44+
compatPerf.instrumentationEnabled = false;
45+
46+
expect(compatPerf.dataCollectionEnabled).to.equal(false);
47+
expect(compatPerf.instrumentationEnabled).to.equal(false);
48+
expect(modularPerf.dataCollectionEnabled).to.equal(false);
49+
expect(modularPerf.instrumentationEnabled).to.equal(false);
50+
51+
// change settings on the modular instance
52+
modularPerf.dataCollectionEnabled = true;
53+
modularPerf.instrumentationEnabled = true;
54+
55+
expect(compatPerf.dataCollectionEnabled).to.equal(true);
56+
expect(compatPerf.instrumentationEnabled).to.equal(true);
57+
expect(modularPerf.dataCollectionEnabled).to.equal(true);
58+
expect(modularPerf.instrumentationEnabled).to.equal(true);
59+
});
60+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @license
3+
* Copyright 2021 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { getModularInstance } from '@firebase/util';
19+
import { expect } from 'chai';
20+
import { getRemoteConfig } from '@firebase/remote-config-exp';
21+
import firebase from '@firebase/app-compat';
22+
import '@firebase/remote-config-compat';
23+
24+
import { TEST_PROJECT_CONFIG } from './util';
25+
26+
firebase.initializeApp(TEST_PROJECT_CONFIG);
27+
28+
const compatRC = firebase.remoteConfig();
29+
const modularRC = getRemoteConfig();
30+
31+
describe('RC compat interop', () => {
32+
it('RC compat instance references modular RC instance', () => {
33+
expect(getModularInstance(compatRC)).to.equal(modularRC);
34+
});
35+
});

0 commit comments

Comments
 (0)