Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F21589538
get-app-port.test.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
get-app-port.test.ts
View Options
import
assert
from
"assert"
;
import
{
mkdtemp
,
mkdir
,
rm
,
writeFile
}
from
"node:fs/promises"
;
import
os
from
"node:os"
;
import
path
from
"node:path"
;
import
{
getAppPort
}
from
"./get-app-port.js"
;
async
function
ensureModuleType
(
dir
:
string
)
{
await
writeFile
(
path
.
join
(
dir
,
"package.json"
),
JSON
.
stringify
({
type
:
"module"
}),
"utf-8"
);
}
describe
(
"getAppPort"
,
()
=>
{
let
projectDir
:
string
;
beforeEach
(
async
()
=>
{
projectDir
=
await
mkdtemp
(
path
.
join
(
os
.
tmpdir
(),
"sealgen-app-config-test-"
)
);
await
ensureModuleType
(
projectDir
);
});
afterEach
(
async
()
=>
{
await
rm
(
projectDir
,
{
recursive
:
true
,
force
:
true
});
delete
process
.
env
.
SEALIOUS_PORT
;
});
async
function
writeConfigFile
(
contents
:
string
)
{
const
distBackDir
=
path
.
join
(
projectDir
,
"dist/back"
);
await
mkdir
(
distBackDir
,
{
recursive
:
true
});
await
writeFile
(
path
.
join
(
distBackDir
,
"config.js"
),
contents
,
"utf-8"
);
}
it
(
"returns the PORT exported by the compiled config file"
,
async
()
=>
{
await
writeConfigFile
(
`export const PORT = 4321;`
);
const
port
=
await
getAppPort
(
projectDir
);
assert
.
strictEqual
(
port
,
4321
);
});
it
(
"falls back to SEALIOUS_PORT when config PORT is invalid"
,
async
()
=>
{
await
writeConfigFile
(
`export const PORT = "not-a-number";`
);
process
.
env
.
SEALIOUS_PORT
=
"9876"
;
const
port
=
await
getAppPort
(
projectDir
);
assert
.
strictEqual
(
port
,
9876
);
});
it
(
"returns null when no config and no env port provided"
,
async
()
=>
{
const
port
=
await
getAppPort
(
projectDir
);
assert
.
strictEqual
(
port
,
null
);
});
});
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Sat, Nov 7, 18:05 (4 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1182073
Default Alt Text
get-app-port.test.ts (1 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline