From 0bb5581d0b203d5a4d85ee86cba5c1c95d71a10f Mon Sep 17 00:00:00 2001 From: Arvin Wilderink Date: Mon, 13 Jan 2025 14:01:39 +0000 Subject: [PATCH 1/4] fix: handlerPossibleHtml should keep the original response if not html --- src/html.ts | 2 +- test/html.test.ts | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/html.ts b/src/html.ts index 0ca7f33..d73bab5 100644 --- a/src/html.ts +++ b/src/html.ts @@ -61,7 +61,7 @@ export function html(options: HtmlOptions = {}) { return new Response(response) } - return undefined + return value } ) diff --git a/test/html.test.ts b/test/html.test.ts index b3465ca..20c850c 100644 --- a/test/html.test.ts +++ b/test/html.test.ts @@ -77,4 +77,19 @@ describe('HTML', () => { 'text/html; charset=utf8' ) }) + + it('should keep the original request when the response is not html', async () => { + const app = new Elysia() + .use(html()) + .onError(() => { + return new Response('ok') + }) + .get('/', () => { + throw 'error' + }) + + let res = await app.handle(request('/')) + expect(res.status).toBe(200) + expect(await res.text()).toBe('ok') + }) }) From 276d3e4fe1548c3351f8eab815f349001d30627a Mon Sep 17 00:00:00 2001 From: Arvin Wilderink Date: Thu, 20 Feb 2025 09:31:23 +0000 Subject: [PATCH 2/4] test: update test --- src/html.ts | 2 +- test/html.test.ts | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/html.ts b/src/html.ts index d73bab5..e5091aa 100644 --- a/src/html.ts +++ b/src/html.ts @@ -61,7 +61,7 @@ export function html(options: HtmlOptions = {}) { return new Response(response) } - return value + return value as Response } ) diff --git a/test/html.test.ts b/test/html.test.ts index 20c850c..6e80ead 100644 --- a/test/html.test.ts +++ b/test/html.test.ts @@ -78,15 +78,19 @@ describe('HTML', () => { ) }) - it('should keep the original request when the response is not html', async () => { + it('keeps the original request when in autoDetect and html is not detected', async () => { const app = new Elysia() .use(html()) - .onError(() => { - return new Response('ok') - }) - .get('/', () => { - throw 'error' + .onError(({ set} ) => { + set.status = 'OK' + return 'ok' }) + .get( + '/', + () => { + throw 'not ok' + } + ) let res = await app.handle(request('/')) expect(res.status).toBe(200) From dbe80ad960fdaeb30838e4ba25cc02ad19e0002b Mon Sep 17 00:00:00 2001 From: Arvin Wilderink Date: Thu, 20 Feb 2025 10:39:38 +0000 Subject: [PATCH 3/4] Create npm-publish-github-packages.yml --- .../workflows/npm-publish-github-packages.yml | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 .github/workflows/npm-publish-github-packages.yml diff --git a/.github/workflows/npm-publish-github-packages.yml b/.github/workflows/npm-publish-github-packages.yml new file mode 100644 index 0000000..c3cf7c5 --- /dev/null +++ b/.github/workflows/npm-publish-github-packages.yml @@ -0,0 +1,49 @@ +# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created +# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages + +name: Node.js Package + +on: + release: + types: [created] + +defaults: + run: + shell: bash + +permissions: + id-token: write + +env: + # Enable debug logging for actions + ACTIONS_RUNNER_DEBUG: true + +jobs: + publish-gpr: + name: 'Publish: npm Registry' + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v4 + - uses: oven-sh/setup-bun@v1 + - uses: actions/setup-node@v4 + with: + node-version: 20 + registry-url: https://npm.pkg.github.com/ + + - name: Install packages + run: bun install + + - name: Build code + run: bun run build + + - name: Test + run: bun run test + + - name: 'Publish' + env: + NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} + run: | + npm publish --provenance --access=public From bf394b449c5f4d447fb6e274ebcd1dc62a9459a1 Mon Sep 17 00:00:00 2001 From: Arvin Wilderink Date: Tue, 4 Mar 2025 11:36:11 +0000 Subject: [PATCH 4/4] Revert "Create npm-publish-github-packages.yml" This reverts commit dbe80ad960fdaeb30838e4ba25cc02ad19e0002b. --- .../workflows/npm-publish-github-packages.yml | 49 ------------------- 1 file changed, 49 deletions(-) delete mode 100644 .github/workflows/npm-publish-github-packages.yml diff --git a/.github/workflows/npm-publish-github-packages.yml b/.github/workflows/npm-publish-github-packages.yml deleted file mode 100644 index c3cf7c5..0000000 --- a/.github/workflows/npm-publish-github-packages.yml +++ /dev/null @@ -1,49 +0,0 @@ -# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created -# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages - -name: Node.js Package - -on: - release: - types: [created] - -defaults: - run: - shell: bash - -permissions: - id-token: write - -env: - # Enable debug logging for actions - ACTIONS_RUNNER_DEBUG: true - -jobs: - publish-gpr: - name: 'Publish: npm Registry' - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - steps: - - uses: actions/checkout@v4 - - uses: oven-sh/setup-bun@v1 - - uses: actions/setup-node@v4 - with: - node-version: 20 - registry-url: https://npm.pkg.github.com/ - - - name: Install packages - run: bun install - - - name: Build code - run: bun run build - - - name: Test - run: bun run test - - - name: 'Publish' - env: - NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} - run: | - npm publish --provenance --access=public