Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F1263281
add-route.test.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
add-route.test.ts
View Options
import
{
promises
as
fs
}
from
"fs"
;
import
{
exec
,
spawn
}
from
"child_process"
;
import
axios
from
"axios"
;
import
waitPort
from
"wait-port"
;
import
getPort
from
"get-port"
;
import
_locreq
from
"locreq"
;
import
{
module_dirname
}
from
"./utils/module-dirname.js"
;
const
locreq
=
_locreq
(
module_dirname
(
import
.
meta
.
url
));
const
execAsync
=
(
cmd
:
string
)
=>
{
return
new
Promise
<
void
>
((
resolve
,
reject
)
=>
{
const
process
=
exec
(
cmd
);
console
.
log
(
"EXECUTING"
,
cmd
);
process
?
.
stdout
?
.
on
(
"data"
,
(
data
)
=>
{
console
.
log
(
`stdout:
${
data
}
`
);
});
process
?
.
stderr
?
.
on
(
"data"
,
(
data
)
=>
{
console
.
log
(
`stdout:
${
data
}
`
);
});
process
.
on
(
"exit"
,
(
code
)
=>
{
if
(
code
==
0
)
{
resolve
();
}
else
{
reject
();
}
});
});
};
const
callSealgenBin
=
()
=>
`node
${
locreq
.
resolve
(
"dist/cli.js"
)
}
`
;
describe
(
"add route test"
,
()
=>
{
let
node_pid
=
0
;
const
timestamp
=
Date
.
now
();
const
app_path
=
`/tmp/sealious-minimal-
${
timestamp
}
`
;
const
container_name
=
`sealgen-test-mongo-
${
timestamp
}
`
;
afterEach
(
async
function
()
{
try
{
if
(
node_pid
!=
0
)
await
execAsync
(
`kill -9
${
node_pid
}
`
);
}
catch
(
error
)
{
throw
new
Error
(
"node process exited unexpectedly, please inspect the output"
);
}
await
Promise
.
all
([
fs
.
rm
(
app_path
,
{
recursive
:
true
,
force
:
true
}),
execAsync
(
`docker rm -f
${
container_name
}
`
),
]);
});
it
(
"creates minimal sealious app"
,
async
function
()
{
console
.
log
(
"\tcloning sealious-minimal..."
);
await
execAsync
(
`git clone https://hub.sealcode.org/source/sealious-minimal.git
${
app_path
}
&& cd
${
app_path
}
&& git checkout 5b33aac`
);
console
.
log
(
"\tinstalling dependencies and sealgen..."
);
await
execAsync
(
`cd
${
app_path
}
&& npm ci && rm -rf node_modules/@sealcode/sealgen && ln -s $OLDPWD node_modules/@sealcode/sealgen`
);
console
.
log
(
"\trunning add-route and building app..."
);
await
execAsync
(
`cd
${
app_path
}
&&
${
callSealgenBin
()
}
add-route --url=/sample --action=Sample --mode=page &&
${
callSealgenBin
()
}
build`
);
console
.
log
(
"\tstarting the database...(if timeouts here, run 'docker pull mongo:4.4-bionic' to solve)"
);
const
mongo_port
=
await
getPort
();
const
app_port
=
await
getPort
();
await
execAsync
(
`docker run -p
${
mongo_port
}
:27017 --name
${
container_name
}
-d mongo:4.4-bionic`
);
console
.
log
(
"\trunning app and making request to the generated url..."
);
const
env
=
{
...
process
.
env
,
SEALIOUS_MONGO_PORT
:
mongo_port
.
toString
(),
SEALIOUS_PORT
:
app_port
.
toString
(),
};
const
node_args
=
[
`
${
app_path
}
/dist/back/index.js`
];
console
.
log
(
"EXECUTING APP"
,
`
${
Object
.
entries
(
env
)
.
map
(([
key
,
value
])
=>
`
${
key
}
=
${
value
}
`
)
.
join
(
" "
)
}
node
${
node_args
.
join
(
" "
)
}
`
);
let
app_start
=
spawn
(
`node`
,
node_args
,
{
env
,
});
app_start
.
stdout
.
on
(
"data"
,
(
data
)
=>
console
.
log
(
"APP OUTPUT:"
,
data
.
toString
()));
app_start
.
stderr
.
on
(
"data"
,
(
data
)
=>
console
.
log
(
data
.
toString
()));
if
(
app_start
.
pid
==
undefined
)
throw
new
Error
(
"node failed to start"
);
node_pid
=
app_start
.
pid
;
await
waitPort
({
host
:
"localhost"
,
port
:
app_port
,
output
:
"silent"
,
timeout
:
6000
,
});
const
res
=
await
axios
.
get
(
`http://localhost:
${
app_port
}
/sample`
);
if
(
res
.
status
!=
200
)
{
throw
new
Error
(
"url generated by add-route exists but doesnt return 200"
);
}
});
});
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Fri, Jan 24, 16:50 (2 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
600246
Default Alt Text
add-route.test.ts (3 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline
Log In to Comment