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: runs:
using: "composite" using: "composite"
steps: 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 - run: pnpm run test
shell: bash shell: bash

View File

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

View File

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

View File

@ -1,6 +1,8 @@
#! /bin/bash #! /bin/bash
set -ex Xvfb :98 & # Start xvfb on display :98
export DISPLAY=:98
set -x
root_dir=$(cd `dirname $0`/../../.. && pwd -P) root_dir=$(cd `dirname $0`/../../.. && pwd -P)
cur_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" 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" 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 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 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" 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" 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" 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" 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\ --volume=$root_dir:/workspace\
--env=USE_XVFB=yes\ --env=USE_XVFB=yes\
--env=XVFB_SERVER=:95\ --env=XVFB_SERVER=:95\
@ -31,7 +38,7 @@ docker run -d -it\
--env=XVFB_RESOLUTION=320x240x8\ --env=XVFB_RESOLUTION=320x240x8\
--env=DISPLAY=:95\ --env=DISPLAY=:95\
--rm\ --rm\
--hostname=DESKTOP-1TV4OAG\ --hostname=DESKTOP-1TV4OA1\
--name=wine\ --name=wine\
--shm-size=1g\ --shm-size=1g\
--workdir=/home/wineuser\ --workdir=/home/wineuser\
@ -40,10 +47,9 @@ docker run -d -it\
-p 8083:8083\ -p 8083:8083\
scottyhardy/docker-wine:latest\ scottyhardy/docker-wine:latest\
wine /workspace/cache/nwjs-sdk-v$nw_version-win-x64/nw.exe wine /workspace/cache/nwjs-sdk-v$nw_version-win-x64/nw.exe
until $(curl --output /dev/null --silent --head --fail http://127.0.0.1:8083/check); do
sleep 10 printf '.'
curl http://localhost:8083 curl http://127.0.0.1:8083/check
docker ps sleep 1
exit 0 done
# curl http://localhost:8083/close echo "success"
# docker stop wine

View File

@ -36,9 +36,17 @@ const server = createServer(async (req, resp) => {
// and the second param is response header info // and the second param is response header info
try { try {
console.log("server is working..."); 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")) if(req.url?.includes("close"))
{ {
resp.writeHead(200, { "Content-Type": "text/plain" });
resp.end('ok');
nw.App.quit() nw.App.quit()
return;
} }
const body = JSON.parse(await Handle.readBody(req)); 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' import * as fs from 'fs'
describe("wcc - module", function () { describe("wcc - module", function () {
this.beforeAll(() => { this.beforeAll(function(done) {
this.timeout(60000)
windows.start() windows.start()
done()
}) })
this.afterAll(() => { this.afterAll(() => {
windows.close() windows.close()