From 7c0e21f6a4cc4c874325d2c342763e43e95e427b Mon Sep 17 00:00:00 2001 From: Evert Pot Date: Mon, 15 Jan 2024 11:36:21 -0500 Subject: [PATCH 1/5] Added a basic unittest. --- changelog.md | 7 +++++++ src/html-index.tsx | 2 +- src/index.ts | 7 ++++++- test/json-test.ts | 28 ++++++++++++++++++++++++++++ test/test.ts | 5 ----- tsconfig.json | 3 ++- 6 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 test/json-test.ts delete mode 100644 test/test.ts diff --git a/changelog.md b/changelog.md index d4cb994..d6cc8fa 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,13 @@ Changelog ========= +1.0.3 (????-??-??) +------------------ + +* Added a DOCTYPE so we're not in quircks mode. +* Added a bug related to loading image assets. + + 1.0.2 (2024-01-15) ------------------ diff --git a/src/html-index.tsx b/src/html-index.tsx index a0ba4ec..aca74e1 100644 --- a/src/html-index.tsx +++ b/src/html-index.tsx @@ -41,7 +41,7 @@ export default async function generateHtmlIndex(ctx: Context, options: Options) } ctx.response.type = 'text/html; charset=utf-8'; - ctx.response.body = ReactDOMServer.renderToString( + ctx.response.body = '\n' + ReactDOMServer.renderToString( ): Middleware { const stat = staticMw({ - staticDir: __dirname + '/../assets', + staticDir: assetsPath, pathPrefix: '/_hal-browser/assets', maxAge: 3600, }); diff --git a/test/json-test.ts b/test/json-test.ts new file mode 100644 index 0000000..c2f4a7a --- /dev/null +++ b/test/json-test.ts @@ -0,0 +1,28 @@ +import { Application } from '@curveball/kernel'; +import browser from '../src/index.js'; +import { expect } from 'chai'; + +describe('Browser middleware integration test', () => { + + it('should render a HTML page when an `Accept` header with text/html is emitted', async() => { + + const app = new Application(); + const mw = browser(); + app.use(mw); + + app.use( ctx => { + ctx.response.body = { hello: 'world' }; + ctx.response.type = 'application/json' + }); + + const resp = await app.subRequest('GET', '/', { + Accept: 'text/html' + }); + + expect(resp.status).to.equal(200); + expect(resp.is('html')).to.equal(true); + expect(resp.body).to.contain(''); + + }); + +}); diff --git a/test/test.ts b/test/test.ts deleted file mode 100644 index 7107a75..0000000 --- a/test/test.ts +++ /dev/null @@ -1,5 +0,0 @@ -describe('this package', () => { - it('should have tests', () => { - // Tests go here! - }); -}); diff --git a/tsconfig.json b/tsconfig.json index 72f8a6f..32bb281 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -24,6 +24,7 @@ "resolveJsonModule": true }, "include": [ - "src/**/*" + "src/**/*", + "test/**/*" ] } From 0b04792da944a1dc44f9f6c66994bec430bc582b Mon Sep 17 00:00:00 2001 From: Evert Pot Date: Mon, 15 Jan 2024 11:38:08 -0500 Subject: [PATCH 2/5] Shouldn't hae been committed --- tsconfig.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index 32bb281..72f8a6f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -24,7 +24,6 @@ "resolveJsonModule": true }, "include": [ - "src/**/*", - "test/**/*" + "src/**/*" ] } From 1d2074ceba1e8f926c7bb1d286919969c3cc3c91 Mon Sep 17 00:00:00 2001 From: Evert Pot Date: Mon, 15 Jan 2024 15:06:30 -0500 Subject: [PATCH 3/5] Fix asset path --- src/index.ts | 2 +- test/json-test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 1fa7feb..6c9b425 100644 --- a/src/index.ts +++ b/src/index.ts @@ -109,7 +109,7 @@ const defaultNavigationLinks: NavigationLinkMap = { export { Options } from './types.js'; -const assetsPath = join(fileURLToPath(new URL(import.meta.url)),'..'); +const assetsPath = join(fileURLToPath(new URL(import.meta.url)),'../../assets'); console.log(assetsPath); export default function browser(options?: Partial): Middleware { diff --git a/test/json-test.ts b/test/json-test.ts index c2f4a7a..85b8981 100644 --- a/test/json-test.ts +++ b/test/json-test.ts @@ -12,7 +12,7 @@ describe('Browser middleware integration test', () => { app.use( ctx => { ctx.response.body = { hello: 'world' }; - ctx.response.type = 'application/json' + ctx.response.type = 'application/json'; }); const resp = await app.subRequest('GET', '/', { From b9184660e64fe8520710a6298a471c2c9bac120c Mon Sep 17 00:00:00 2001 From: Evert Pot Date: Mon, 15 Jan 2024 15:07:35 -0500 Subject: [PATCH 4/5] Remove console statement --- src/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 6c9b425..c16ecb7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -110,7 +110,6 @@ const defaultNavigationLinks: NavigationLinkMap = { export { Options } from './types.js'; const assetsPath = join(fileURLToPath(new URL(import.meta.url)),'../../assets'); -console.log(assetsPath); export default function browser(options?: Partial): Middleware { From da88102abb91183a14b280402eeaa64b11606848 Mon Sep 17 00:00:00 2001 From: Evert Pot Date: Mon, 15 Jan 2024 16:31:33 -0500 Subject: [PATCH 5/5] Releasing 1.0.3 --- changelog.md | 2 +- package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/changelog.md b/changelog.md index d6cc8fa..cad96d1 100644 --- a/changelog.md +++ b/changelog.md @@ -1,7 +1,7 @@ Changelog ========= -1.0.3 (????-??-??) +1.0.3 (2024-01-15) ------------------ * Added a DOCTYPE so we're not in quircks mode. diff --git a/package-lock.json b/package-lock.json index 5973198..cee3531 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@curveball/browser", - "version": "1.0.2", + "version": "1.0.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@curveball/browser", - "version": "1.0.2", + "version": "1.0.3", "license": "MIT", "dependencies": { "@curveball/static": "^1", diff --git a/package.json b/package.json index c39afda..b8cf753 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@curveball/browser", - "version": "1.0.2", + "version": "1.0.3", "description": "Automatic API browser generator. A middleware that turns your JSON responses into HTML if accessed by a browser.", "type": "module", "exports": "./dist/index.js",