From ab77c1f8b5ad63f14c210ae16e1debc4c12f6d49 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 27 May 2024 17:24:49 +0000 Subject: [PATCH] Change: fix text by increase timeouts and run sync --- .github/workflows/npm-publish.yml | 67 +++++++++++++++++++++++++++++ .github/workflows/publish.yml | 37 ---------------- package-lock.json | 4 +- package.json | 7 +-- src/test/e2e.ts | 20 +++++---- src/test/e2e/cli.test.ts | 13 +++--- src/test/e2e/env.test.ts | 8 ++-- src/test/e2e/https-redirect.test.ts | 7 ++- src/test/e2e/load-balancer.test.ts | 11 +++-- src/test/e2e/proxy.test.ts | 8 ++-- src/test/e2e/static.test.ts | 7 ++- 11 files changed, 119 insertions(+), 70 deletions(-) create mode 100644 .github/workflows/npm-publish.yml delete mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml new file mode 100644 index 0000000..21f9735 --- /dev/null +++ b/.github/workflows/npm-publish.yml @@ -0,0 +1,67 @@ +name: NPM Publish + +on: + push: + branches: [ "main" ] + paths: + - 'package.json' + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [20.x] + + steps: + - uses: actions/checkout@v4 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + - run: npm ci + - run: npm run build --if-present + - run: npm run test --if-present + - uses: actions/upload-artifact@v4 + with: + name: build-artifacts + path: dist + +# publish-gpr: +# needs: build +# runs-on: ubuntu-latest +# permissions: +# contents: read +# packages: write +# steps: +# - uses: actions/checkout@v4 +# - uses: actions/setup-node@v3 +# with: +# node-version: 20 +# registry-url: https://npm.pkg.github.com/ +# - uses: actions/download-artifact@v4 +# with: +# name: build-artifacts +# path: dist +# - run: npm publish +# env: +# NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} + + publish-npm: + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v3 + with: + node-version: 20 + registry-url: https://registry.npmjs.org/ + - uses: actions/download-artifact@v4 + with: + name: build-artifacts + path: dist + - run: npm publish + env: + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index 7845faf..0000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Publish - -on: - push: - branches: - - main - -jobs: - publish: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v2 - - uses: technote-space/can-npm-publish-action@v1 - - name: Use Node.js 20 - uses: actions/setup-node@v1 - with: - node-version: 20 - cache: 'npm' - cache-dependency-path: 'package-lock.json' - - run: npm i -g npm@9 - - run: npm ci - - run: npm run build - - run: ls -al 'src'; ls -al 'src/test'; ls -al 'src/test/e2e' - - run: npm test - - name: npmjs.org npm publish - uses: JS-DevTools/npm-publish@v1 - with: - token: ${{ secrets.NPM_TOKEN }} - registry: https://registry.npmjs.org - access: public - - run: npm pkg set "name=@${{ GITHUB.REPOSITORY }}" - - name: github.com npm publish - uses: JS-DevTools/npm-publish@v1 - with: - token: ${{ GITHUB.TOKEN }} - registry: https://npm.pkg.github.com - access: public diff --git a/package-lock.json b/package-lock.json index 3d45c96..7993557 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cprox", - "version": "1.9.9", + "version": "1.9.11", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "cprox", - "version": "1.9.9", + "version": "1.9.11", "license": "MIT", "dependencies": { "cmdy": "^1.4.5", diff --git a/package.json b/package.json index d78ea9b..98a1b83 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "cprox", "description": "A easy to configure redirect, static serve, proxy and load balancer web server.", - "version": "1.9.9", + "version": "1.9.11", "main": "dist/index.js", "author": "NobleMajo", "license": "MIT", @@ -27,7 +27,8 @@ "tsc": "tsc -p tsconfig.json", "start": "ts-node src/index.ts *=STATIC:/var/www/html --dry-run", "exec": "node dist/index.js", - "test": "mocha --parallel --exit --require ts-node/register 'src/test/**/*.test.ts'", + "test": "mocha --exit --require ts-node/register 'src/test/**/*.test.ts'", + "test-parallel": "mocha --parallel --exit --require ts-node/register 'src/test/**/*.test.ts'", "build": "npm run tsc", "dev": "nodemon -w ./src -x \"npm run build; npm run test; npm run start\" --ext *.ts" }, @@ -53,4 +54,4 @@ "serve-static": "^1.15.0", "typenvy": "^1.5.15" } -} +} \ No newline at end of file diff --git a/src/test/e2e.ts b/src/test/e2e.ts index e329824..c49a9e4 100644 --- a/src/test/e2e.ts +++ b/src/test/e2e.ts @@ -58,7 +58,7 @@ export const defaultAsyncForkSettings: AsyncForkSettings = { env: {}, spawnTimeout: 1000 * 4, timeout: 1000 * 8, - closeTimeout: 1000 * 4, + closeTimeout: -1, } export async function asyncFork( @@ -310,7 +310,7 @@ export function asyncSleep(millis: number): Promise { export async function startCprox( args: string[], - timeoutMillis: number = 1000 * 8, + timeoutMillis: number, checkIntervalMillis: number = 200, ): Promise { if (timeoutMillis < 100) { @@ -323,7 +323,7 @@ export async function startCprox( __dirname + "/../index", { args: args, - timeout: defaultE2ETimeout - 5 + timeout: timeoutMillis - 1000 } ) await result.spawnPromise @@ -333,7 +333,8 @@ export async function startCprox( resolved = true await result.close() rej(new Error( - "Can't find started message!\n" + + "Can't find started message for:\n" + + args.join(" ") + "\n\n" + ( result.output.length == 0 ? "No error or standard output!" : @@ -343,6 +344,7 @@ export async function startCprox( }, timeoutMillis) while (!resolved) { await asyncSleep(checkIntervalMillis) + if (result.getStdOutput().includes("CProX| Server started!")) { resolved = true break @@ -357,11 +359,11 @@ export async function startCprox( return result } -export const defaultE2ETimeout: number = 1000 * 16 -export const defaultBeforeTimeout: number = 1000 * 8 -export const defaultAfterTimeout: number = 1000 * 4 -export const defaultCliTimeout: number = 1000 * 8 -export const defaultTestTimeout: number = 1000 * 2 +export const defaultE2ETimeout: number = 1000 * 60 +export const defaultBeforeTimeout: number = 1000 * 40 +export const defaultAfterTimeout: number = 1000 * 10 +export const defaultCliTimeout: number = 1000 * 30 +export const defaultTestTimeout: number = 1000 * 10 const defaultRequestTimeout: number = 140 diff --git a/src/test/e2e/cli.test.ts b/src/test/e2e/cli.test.ts index f6633e9..8562e8d 100644 --- a/src/test/e2e/cli.test.ts +++ b/src/test/e2e/cli.test.ts @@ -1,9 +1,10 @@ +import { expect } from 'chai'; import 'mocha'; -import { expect } from 'chai' import { - defaultE2ETimeout, defaultCliTimeout, asyncFork, -} from '../e2e' + defaultCliTimeout, + defaultE2ETimeout, +} from '../e2e'; describe('Live cli', function () { this.timeout(defaultE2ETimeout) @@ -14,7 +15,8 @@ describe('Live cli', function () { const result = await asyncFork( __dirname + "/../../index", { - args: ["--help"] + args: ["--help"], + closeTimeout: defaultCliTimeout - 2000, } ) await result.spawnPromise @@ -44,7 +46,8 @@ describe('Live cli', function () { args: [ "--dry-run", "*=STATIC:/var/www/html" - ] + ], + closeTimeout: defaultCliTimeout - 2000, } ) await result.spawnPromise diff --git a/src/test/e2e/env.test.ts b/src/test/e2e/env.test.ts index 02a7d14..582a982 100644 --- a/src/test/e2e/env.test.ts +++ b/src/test/e2e/env.test.ts @@ -18,11 +18,12 @@ describe('Live env', function () { { args: [ "--dry-run", - "*=STATIC:/var/www/html" + "*=STATIC:/var/www/html", ], env: { "VERBOSE": "true", - } + }, + closeTimeout: defaultCliTimeout - 2000, } ) await result.spawnPromise @@ -118,7 +119,8 @@ describe('Live env', function () { "DRYRUN": "true", "TRUST_ALL_CERTS": "true", "SELF_SINGED_DOMAIN": "test.com", - } + }, + closeTimeout: defaultCliTimeout - 2000, } ) await result.spawnPromise diff --git a/src/test/e2e/https-redirect.test.ts b/src/test/e2e/https-redirect.test.ts index c2ec668..e3567f5 100644 --- a/src/test/e2e/https-redirect.test.ts +++ b/src/test/e2e/https-redirect.test.ts @@ -5,7 +5,9 @@ import { after, before } from 'mocha'; import fetch from 'node-fetch'; import { AsyncForkResult, defaultAfterTimeout, - defaultBeforeTimeout, defaultE2ETimeout, + defaultBeforeTimeout, + defaultCliTimeout, + defaultE2ETimeout, defaultFetchOptions, defaultTestTimeout, getRandomTestPort, @@ -29,7 +31,7 @@ describe('Live E2E http to https redirect tests', function () { "-s", "" + httpsPort, "-b", "127.0.0.1", "localhost=STATIC:" + __dirname + "/../html", - ]) + ], defaultCliTimeout) }) after(async function () { @@ -58,6 +60,7 @@ describe('Live E2E http to https redirect tests', function () { it('request without host', async function () { this.timeout(defaultTestTimeout) + const resp = await fetch("http://127.0.0.1:" + httpPort, { ...defaultFetchOptions, }) diff --git a/src/test/e2e/load-balancer.test.ts b/src/test/e2e/load-balancer.test.ts index b811b1d..efe4536 100644 --- a/src/test/e2e/load-balancer.test.ts +++ b/src/test/e2e/load-balancer.test.ts @@ -5,11 +5,14 @@ import { after, before } from 'mocha'; import fetch, { Response } from "node-fetch"; import { AsyncForkResult, defaultAfterTimeout, - defaultBeforeTimeout, defaultE2ETimeout, - defaultFetchOptions, defaultTestTimeout, + defaultBeforeTimeout, + defaultCliTimeout, + defaultE2ETimeout, + defaultFetchOptions, + defaultTestTimeout, getLogMessage, getRandomTestPort, - startCprox, + startCprox } from '../e2e'; describe('Live E2E load balancer webserver tests', function () { @@ -27,7 +30,7 @@ describe('Live E2E load balancer webserver tests', function () { "-b", "127.0.0.1", "localhost=REDIRECT:http://127.0.0.1:8080,http://127.0.0.1:8081,http://127.0.0.1:8082", "test.com=REDIRECT:http://127.0.0.1:8080,http://127.0.0.1:8081,http://127.0.0.1:8082,http://127.0.0.1:8083", - ]) + ], defaultCliTimeout) }) after(async function () { diff --git a/src/test/e2e/proxy.test.ts b/src/test/e2e/proxy.test.ts index 58ad8b4..8ca17a7 100644 --- a/src/test/e2e/proxy.test.ts +++ b/src/test/e2e/proxy.test.ts @@ -5,7 +5,9 @@ import { after, before } from 'mocha'; import fetch, { Response } from 'node-fetch'; import { AsyncForkResult, defaultAfterTimeout, - defaultBeforeTimeout, defaultE2ETimeout, + defaultBeforeTimeout, + defaultCliTimeout, + defaultE2ETimeout, defaultFetchOptions, defaultTestTimeout, getRandomTestPort, @@ -30,13 +32,13 @@ describe('Live E2E proxy webserver tests', function () { "-b", "127.0.0.1", "localhost=PROXY:http://127.0.0.1:" + port2, "sub.com=PROXY:http://127.0.0.1:50404", - ]) + ], defaultCliTimeout) const p2 = startCprox([ "-p", "" + port2, "-b", "127.0.0.1", "localhost=STATIC:" + __dirname + "/../html", "sub.com=STATIC:" + __dirname + "/../html/sub", - ]) + ], defaultCliTimeout) result2 = await p2 result = await p1 diff --git a/src/test/e2e/static.test.ts b/src/test/e2e/static.test.ts index 2e27e5c..72b45a1 100644 --- a/src/test/e2e/static.test.ts +++ b/src/test/e2e/static.test.ts @@ -5,7 +5,9 @@ import { after, before } from 'mocha'; import fetch, { Response } from 'node-fetch'; import { AsyncForkResult, defaultAfterTimeout, - defaultBeforeTimeout, defaultE2ETimeout, + defaultBeforeTimeout, + defaultCliTimeout, + defaultE2ETimeout, defaultFetchOptions, defaultTestTimeout, getRandomTestPort, startCprox @@ -20,12 +22,13 @@ describe('Live E2E static webserver tests', function () { this.timeout(defaultBeforeTimeout) port = getRandomTestPort() + result = await startCprox([ "-p", "" + port, "-b", "127.0.0.1", "localhost=STATIC:" + __dirname + "/../html", "sub.com=STATIC:" + __dirname + "/../html/sub", - ]) + ], defaultCliTimeout) }) after(async function () {