-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests for RestApplication
- Loading branch information
Hage Yaapa
committed
Oct 26, 2018
1 parent
79b268c
commit 17deb27
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
packages/rest/test/integration/rest.application.integration.ts
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright IBM Corp. 2017,2018. All Rights Reserved. | ||
// Node module: @loopback/rest | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
import {createRestAppClient, Client} from '@loopback/testlab'; | ||
import {RestApplication} from '../..'; | ||
import * as path from 'path'; | ||
import * as fs from 'fs'; | ||
|
||
const FIXTURES = path.resolve(__dirname, '../../../fixtures'); | ||
|
||
describe('RestApplication (integration)', () => { | ||
let restApp: RestApplication; | ||
let client: Client; | ||
|
||
beforeEach(givenAnApplication); | ||
beforeEach(givenClient); | ||
afterEach(async () => { | ||
await restApp.stop(); | ||
}); | ||
|
||
it('serves static assets', async () => { | ||
const root = FIXTURES; | ||
const content = fs | ||
.readFileSync(path.join(root, 'index.html')) | ||
.toString('utf-8'); | ||
await client | ||
.get('/index.html') | ||
.expect(200) | ||
.expect(content); | ||
}); | ||
|
||
it('returns 404 if asset is not found', async () => { | ||
await client.get('/404.html').expect(404); | ||
}); | ||
|
||
function givenAnApplication() { | ||
const root = FIXTURES; | ||
restApp = new RestApplication({rest: {port: 0, host: '127.0.0.1'}}); | ||
restApp.static('/', root); | ||
} | ||
|
||
async function givenClient() { | ||
await restApp.start(); | ||
return (client = createRestAppClient(restApp)); | ||
} | ||
}); |