diff --git a/.github/actions/test/action.yml b/.github/actions/test/action.yml index 6ef49c9..3b928fd 100644 --- a/.github/actions/test/action.yml +++ b/.github/actions/test/action.yml @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fdc4a9c..a749f2b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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: diff --git a/test/runner/module-windows.ts b/test/runner/module-windows.ts index 24ea378..08cf47b 100644 --- a/test/runner/module-windows.ts +++ b/test/runner/module-windows.ts @@ -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() } } \ No newline at end of file diff --git a/test/runner/nwjs/module-prepare.sh b/test/runner/nwjs/module-prepare.sh index cd265f0..b1ab9fb 100755 --- a/test/runner/nwjs/module-prepare.sh +++ b/test/runner/nwjs/module-prepare.sh @@ -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 \ No newline at end of file +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" \ No newline at end of file diff --git a/test/runner/nwjs/package.nw/main.js b/test/runner/nwjs/package.nw/main.js index 4e0a979..252ae92 100644 --- a/test/runner/nwjs/package.nw/main.js +++ b/test/runner/nwjs/package.nw/main.js @@ -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)); diff --git a/test/spec/wcc/module/module.spec.ts b/test/spec/wcc/module/module.spec.ts index 986fa61..0a15b50 100644 --- a/test/spec/wcc/module/module.spec.ts +++ b/test/spec/wcc/module/module.spec.ts @@ -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()