fix: test for module

This commit is contained in:
msojocs 2024-07-06 21:23:34 +08:00
parent b7fbc2061b
commit 73408a773c
6 changed files with 45 additions and 14 deletions

View File

@ -8,5 +8,19 @@ inputs:
runs:
using: "composite"
steps:
- name: Run Nginx server
run: |
docker run -d -p 8080:80 nginx
shell: bash
- name: Wait for Nginx to be up
run: |
until $(curl --output /dev/null --silent --head --fail http://127.0.0.1:8080); do
printf '.'
sleep 1
done
shell: bash
- run: pnpm run test
shell: bash

View File

@ -149,6 +149,7 @@ jobs:
ls -l test/wine
# ./test/wine/wcc.exe
pnpm run test-prepare
sudo apt install -y xvfb
# pnpm run test
- uses: ./.github/actions/test
with:

View File

@ -13,7 +13,7 @@ const HTTP = {
const postData = JSON.stringify(compilerOptions);
const options = {
hostname: 'localhost',
hostname: '127.0.0.1',
port: 8083,
path: `/${type}`,
method: 'POST',
@ -71,9 +71,9 @@ export default {
wcsc: wcscNative,
wcc: wccNative,
start: () => {
execFileSync(path.resolve(__dirname, './nwjs/module-prepare.sh'))
execFileSync(path.resolve(__dirname, './nwjs/module-prepare.sh'), { stdio: 'inherit' })
},
close: () => {
request('http://localhost:8083/close').end()
request('http://127.0.0.1:8083/close').end()
}
}

View File

@ -1,6 +1,8 @@
#! /bin/bash
set -ex
Xvfb :98 & # Start xvfb on display :98
export DISPLAY=:98
set -x
root_dir=$(cd `dirname $0`/../../.. && pwd -P)
cur_dir=$(cd `dirname $0` && pwd -P)
@ -10,6 +12,11 @@ if [ ! -f "$root_dir/cache/nwjs-sdk-v$nw_version-win-x64.zip" ];then
wget -c -O "$root_dir/cache/nwjs-sdk-v$nw_version-win-x64.zip.tmp" "https://dl.nwjs.io/v0.55.0/nwjs-sdk-v0.55.0-win-x64.zip"
mv "$root_dir/cache/nwjs-sdk-v$nw_version-win-x64.zip.tmp" "$root_dir/cache/nwjs-sdk-v$nw_version-win-x64.zip"
fi
if [ ! -d "$root_dir/cache/nwjs-sdk-v$nw_version-win-x64" ];then
cd "$root_dir/cache"
unzip "nwjs-sdk-v$nw_version-win-x64.zip"
fi
if [ ! -f "$root_dir/cache/nwjs-sdk-v$nw_version-linux-x64.tar.gz" ];then
wget -c -O "$root_dir/cache/nwjs-sdk-v$nw_version-linux-x64.tar.gz.tmp" "https://dl.nwjs.io/v0.55.0/nwjs-sdk-v0.55.0-linux-x64.tar.gz"
mv "$root_dir/cache/nwjs-sdk-v$nw_version-linux-x64.tar.gz.tmp" "$root_dir/cache/nwjs-sdk-v$nw_version-linux-x64.tar.gz"
@ -23,7 +30,7 @@ fi
rm -rf "$root_dir/cache/nwjs-sdk-v$nw_version-win-x64/package.nw"
cp -r "$cur_dir/package.nw" "$root_dir/cache/nwjs-sdk-v$nw_version-win-x64"
docker run -d -it\
docker run -d -i\
--volume=$root_dir:/workspace\
--env=USE_XVFB=yes\
--env=XVFB_SERVER=:95\
@ -31,7 +38,7 @@ docker run -d -it\
--env=XVFB_RESOLUTION=320x240x8\
--env=DISPLAY=:95\
--rm\
--hostname=DESKTOP-1TV4OAG\
--hostname=DESKTOP-1TV4OA1\
--name=wine\
--shm-size=1g\
--workdir=/home/wineuser\
@ -40,10 +47,9 @@ docker run -d -it\
-p 8083:8083\
scottyhardy/docker-wine:latest\
wine /workspace/cache/nwjs-sdk-v$nw_version-win-x64/nw.exe
sleep 10
curl http://localhost:8083
docker ps
exit 0
# curl http://localhost:8083/close
# docker stop wine
until $(curl --output /dev/null --silent --head --fail http://127.0.0.1:8083/check); do
printf '.'
curl http://127.0.0.1:8083/check
sleep 1
done
echo "success"

View File

@ -36,9 +36,17 @@ const server = createServer(async (req, resp) => {
// and the second param is response header info
try {
console.log("server is working...");
if (req.url?.includes("check")) {
resp.writeHead(200, { "Content-Type": "text/plain" });
resp.end('ok');
return;
}
if(req.url?.includes("close"))
{
resp.writeHead(200, { "Content-Type": "text/plain" });
resp.end('ok');
nw.App.quit()
return;
}
const body = JSON.parse(await Handle.readBody(req));

View File

@ -7,8 +7,10 @@ import windows from '../../../runner/module-windows'
import * as fs from 'fs'
describe("wcc - module", function () {
this.beforeAll(() => {
this.beforeAll(function(done) {
this.timeout(60000)
windows.start()
done()
})
this.afterAll(() => {
windows.close()