Skip to content

Commit b8531cd

Browse files
committed
test(app): localhost is ::1 on some hosts, 127.0.0.1 is required
without this, hosts with IPv6 resolve localhost to ::1 and the firebase emulator isn't listening there, so our helpers cannot connect
1 parent ed06cc3 commit b8531cd

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

packages/app/e2e/helpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ exports.getE2eEmulatorHost = function getE2eEmulatorHost() {
77
// localhost and 127.0.0.1 on Android to 10.0.2.2 (the Android emulator host interface)
88
// But this specific code is executing in the host context even during E2E test.
99
// So no re-write is necessary here.
10-
return 'localhost';
10+
return '127.0.0.1';
1111
};

packages/database/e2e/helpers.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
const testingUtils = require('@firebase/rules-unit-testing');
2+
const { getE2eTestProject, getE2eEmulatorHost } = require('../../app/e2e/helpers');
23

34
// TODO make more unique?
45
const ID = Date.now();
56

67
const PATH = `tests/${ID}`;
7-
const DB_NAME = 'react-native-firebase-testing';
8+
const DB_NAME = getE2eTestProject();
89
const DB_RULES = `{ "rules": {".read": false, ".write": false, "tests": {".read": true, ".write": true } } }`;
910

1011
const CONTENT = {
@@ -40,8 +41,8 @@ exports.seed = function seed(path) {
4041
firebase.database().ref(`${path}/query`).set(CONTENT.QUERY),
4142
// The database emulator does not load rules correctly. We force them pre-test.
4243
testingUtils.initializeTestEnvironment({
43-
projectId: 'react-native-firebase-testing',
44-
database: { databaseName: DB_NAME, rules: DB_RULES, host: 'localhost', port: 9000 },
44+
projectId: getE2eTestProject(),
45+
database: { databaseName: DB_NAME, rules: DB_RULES, host: getE2eEmulatorHost(), port: 9000 },
4546
}),
4647
]);
4748
};

packages/storage/e2e/helpers.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const testingUtils = require('@firebase/rules-unit-testing');
2+
const { getE2eTestProject, getE2eEmulatorHost } = require('../../app/e2e/helpers');
23

34
// TODO make more unique?
45
const ID = Date.now();
@@ -11,7 +12,7 @@ exports.seed = async function seed(path) {
1112
// Force the rules for the storage emulator to be what we expect
1213

1314
await testingUtils.initializeTestEnvironment({
14-
projectId: 'react-native-firebase-testing',
15+
projectId: getE2eTestProject(),
1516
storage: {
1617
rules: `rules_version = '2';
1718
service firebase.storage {
@@ -29,12 +30,12 @@ exports.seed = async function seed(path) {
2930
allow read, write: if true;
3031
}
3132
32-
match /react-native-firebase-testing/{document=**} {
33+
match /${getE2eTestProject()}/{document=**} {
3334
allow read, write: if true;
3435
}
3536
}
3637
}`,
37-
host: 'localhost',
38+
host: getE2eEmulatorHost(),
3839
port: 9199,
3940
},
4041
});

0 commit comments

Comments
 (0)