-
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 12e91d8
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
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,47 @@ | ||
// 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); | ||
|
||
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); | ||
await restApp.stop(); | ||
}); | ||
|
||
it('returns 404 if asset is not found', async () => { | ||
await client.get('/404.html').expect(404); | ||
await restApp.stop(); | ||
}); | ||
|
||
function givenAnApplication() { | ||
const root = FIXTURES; | ||
restApp = new RestApplication({port: 0, host: '127.0.0.1'}); | ||
restApp.static('/', root); | ||
} | ||
|
||
async function givenClient() { | ||
await restApp.start(); | ||
return (client = createRestAppClient(restApp)); | ||
} | ||
}); |