-
Notifications
You must be signed in to change notification settings - Fork 460
Expand file tree
/
Copy pathapplication.test.ts
More file actions
65 lines (52 loc) · 2.39 KB
/
Copy pathapplication.test.ts
File metadata and controls
65 lines (52 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { describe, expect, it } from 'vitest';
import { createAppRuntimeEnv, resolveServerUrl } from '../application';
import { environmentConfig } from '../environment';
describe('resolveServerUrl', () => {
describe('with opts.serverUrl', () => {
it('appends port to a URL without an explicit port', () => {
expect(resolveServerUrl('http://localhost', undefined, 3000)).toBe('http://localhost:3000');
});
it('appends port to an https URL without an explicit port', () => {
expect(resolveServerUrl('https://example.com', undefined, 4000)).toBe('https://example.com:4000');
});
it('preserves an explicit port in the URL', () => {
expect(resolveServerUrl('http://localhost:8080', undefined, 3000)).toBe('http://localhost:8080');
});
it('handles a URL with a path (returns origin only)', () => {
expect(resolveServerUrl('http://localhost/some/path', undefined, 3000)).toBe('http://localhost:3000');
});
it('handles a bare hostname by appending port', () => {
expect(resolveServerUrl('myhost', undefined, 5000)).toBe('myhost:5000');
});
it('handles a bare IP address by appending port', () => {
expect(resolveServerUrl('127.0.0.1', undefined, 5000)).toBe('127.0.0.1:5000');
});
});
describe('with fallback serverUrl', () => {
it('uses fallback when opts.serverUrl is undefined', () => {
expect(resolveServerUrl(undefined, 'http://fallback:9000', 3000)).toBe('http://fallback:9000');
});
it('prefers opts.serverUrl over fallback', () => {
expect(resolveServerUrl('http://localhost', 'http://fallback:9000', 3000)).toBe('http://localhost:3000');
});
});
describe('with no serverUrl at all', () => {
it('defaults to http://localhost with the given port', () => {
expect(resolveServerUrl(undefined, undefined, 4567)).toBe('http://localhost:4567');
});
it('defaults when fallback is empty string', () => {
expect(resolveServerUrl(undefined, '', 4567)).toBe('http://localhost:4567');
});
});
});
describe('createAppRuntimeEnv', () => {
it('passes configured falsey values through to spawned app processes', () => {
const env = environmentConfig()
.setEnvVariable('private', 'CI', 'false')
.setEnvVariable('public', 'CLERK_KEYLESS_DISABLED', false);
expect(createAppRuntimeEnv(env)).toMatchObject({
CI: 'false',
CLERK_KEYLESS_DISABLED: 'false',
});
});
});