This repository has been archived by the owner on Nov 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hapi): upgrade to Hapi v17 (#1015)
BREAKING CHANGE: * The `ngHapiEngine` is no longer supported for Hapi v16. The `RESPONSE` token provided under `@nguniversal/hapi-engine/tokens` now uses the new `ResponseToolkit`, which is unavailable in Hapi v16. Updated instructions are available in the package's README
- Loading branch information
1 parent
b417300
commit 311b9fe
Showing
11 changed files
with
291 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,69 @@ | ||
import {Component, destroyPlatform, getPlatform, NgModule} from '@angular/core'; | ||
import {ServerModule} from '@angular/platform-server'; | ||
import {ngHapiEngine} from '@nguniversal/hapi-engine'; | ||
import {ServerInjectResponse, Request, Server} from 'hapi'; | ||
import 'zone.js'; | ||
import {BrowserModule} from '@angular/platform-browser'; | ||
|
||
@Component({selector: 'app', template: `Works!`}) | ||
class MyServerApp { | ||
} | ||
|
||
|
||
@NgModule({ | ||
bootstrap: [MyServerApp], | ||
declarations: [MyServerApp], | ||
imports: [ServerModule, BrowserModule.withServerTransition({appId: 'hapi-test'})], | ||
}) | ||
class ExampleModule { | ||
} | ||
|
||
|
||
describe('test runner', () => { | ||
it('can run a test', () => { | ||
expect(true).toBe(true); | ||
|
||
const server = new Server({ debug: false }); | ||
server.route([ | ||
{ | ||
method: 'GET', | ||
path: '/', | ||
handler: (req: Request) => ngHapiEngine({ | ||
bootstrap: ExampleModule, | ||
req, | ||
document: '<html><body><app></app></body></html>' | ||
}) | ||
}, | ||
{ | ||
method: 'GET', | ||
path: '/test', | ||
handler: () => 'ok' | ||
}, | ||
]); | ||
|
||
beforeEach(async () => { | ||
if (getPlatform()) { | ||
destroyPlatform(); | ||
} | ||
}); | ||
|
||
it('should test the server', async () => { | ||
const request = { | ||
method: 'GET', | ||
url: '/test' | ||
}; | ||
|
||
const res = await server.inject(request); | ||
expect(res.result).toBeDefined(); | ||
expect(res.result).toBe('ok' as any); | ||
}); | ||
|
||
it('Returns a reply on successful request', async () => { | ||
const request = { | ||
method: 'GET', | ||
url: '/' | ||
}; | ||
|
||
const res: ServerInjectResponse = await server.inject(request); | ||
expect(res.result).toBeDefined(); | ||
expect(res.result).toContain('Works!'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.