Skip to content

Commit

Permalink
Added a basic unittest.
Browse files Browse the repository at this point in the history
  • Loading branch information
evert committed Jan 15, 2024
1 parent 8a73187 commit 7c0e21f
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 8 deletions.
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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)
------------------

Expand Down
2 changes: 1 addition & 1 deletion src/html-index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<!DOCTYPE html>\n' + ReactDOMServer.renderToString(
<App
resourceState={state}
options={options}
Expand Down
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Middleware, invokeMiddlewares } from '@curveball/kernel';
import generateHtmlIndex from './html-index.js';
import { NavigationLinkMap, Options } from './types.js';
import staticMw from '@curveball/static';
import { fileURLToPath } from 'node:url';
import { join } from 'node:path';

export const supportedContentTypes = [
'application/json',
Expand Down Expand Up @@ -107,10 +109,13 @@ const defaultNavigationLinks: NavigationLinkMap = {

export { Options } from './types.js';

const assetsPath = join(fileURLToPath(new URL(import.meta.url)),'..');
console.log(assetsPath);

Check failure on line 113 in src/index.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected console statement

export default function browser(options?: Partial<Options>): Middleware {

const stat = staticMw({
staticDir: __dirname + '/../assets',
staticDir: assetsPath,
pathPrefix: '/_hal-browser/assets',
maxAge: 3600,
});
Expand Down
28 changes: 28 additions & 0 deletions test/json-test.ts
Original file line number Diff line number Diff line change
@@ -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'

Check failure on line 15 in test/json-test.ts

View workflow job for this annotation

GitHub Actions / Lint

Missing semicolon
});

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('<html><head>');

});

});
5 changes: 0 additions & 5 deletions test/test.ts

This file was deleted.

3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"resolveJsonModule": true
},
"include": [
"src/**/*"
"src/**/*",
"test/**/*"
]
}

0 comments on commit 7c0e21f

Please sign in to comment.