Skip to content

Commit db3b0d5

Browse files
committed
Don't throw an error in case where only one of host or port are defines
1 parent aa51e66 commit db3b0d5

File tree

2 files changed

+9
-34
lines changed

2 files changed

+9
-34
lines changed

packages/rules-unit-testing/src/impl/discovery.ts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,25 +88,16 @@ export function getEmulatorHostAndPort(
8888
discovered?: DiscoveredEmulators
8989
) {
9090
if (conf && 'host' in conf && 'port' in conf) {
91-
const { host, port } = conf;
92-
if (host || port) {
93-
if (!host || !port) {
94-
throw new Error(
95-
`Invalid configuration ${emulator}.host=${host} and ${emulator}.port=${port}. ` +
96-
'If either parameter is supplied, both must be defined.'
97-
);
98-
}
99-
if (discovered && !discovered[emulator]) {
100-
console.warn(
101-
`Warning: config for the ${emulator} emulator is specified, but the Emulator hub ` +
102-
'reports it as not running. This may lead to errors such as connection refused.'
103-
);
104-
}
105-
return {
106-
host: fixHostname(conf.host, discovered?.hub?.host),
107-
port: conf.port
108-
};
91+
if (discovered && !discovered[emulator]) {
92+
console.warn(
93+
`Warning: config for the ${emulator} emulator is specified, but the Emulator hub ` +
94+
'reports it as not running. This may lead to errors such as connection refused.'
95+
);
10996
}
97+
return {
98+
host: fixHostname(conf.host, discovered?.hub?.host),
99+
port: conf.port
100+
};
110101
}
111102
const envVar = EMULATOR_HOST_ENV_VARS[emulator];
112103
const fallback = discovered?.[emulator] || emulatorFromEnvVar(envVar);

packages/rules-unit-testing/test/impl/discovery.test.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -123,22 +123,6 @@ describe('getEmulatorHostAndPort()', () => {
123123
expect(result?.host).to.equal('::1');
124124
});
125125

126-
it('throws if only host is present', async () => {
127-
expect(() =>
128-
getEmulatorHostAndPort('hub', {
129-
host: '[::1]'
130-
} as HostAndPort)
131-
).to.throw(/hub.port=undefined/);
132-
});
133-
134-
it('throws if only port is present', async () => {
135-
expect(() =>
136-
getEmulatorHostAndPort('database', {
137-
port: 1234
138-
} as HostAndPort)
139-
).to.throw(/Invalid configuration database.host=undefined/);
140-
});
141-
142126
it('connect to 127.0.0.1 if host is wildcard 0.0.0.0', async () => {
143127
const result = getEmulatorHostAndPort('hub', {
144128
host: '0.0.0.0',

0 commit comments

Comments
 (0)