Skip to content

Commit

Permalink
fix: tests for RestApplication
Browse files Browse the repository at this point in the history
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.
47 changes: 47 additions & 0 deletions packages/rest/test/integration/rest.application.integration.ts
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));
}
});

0 comments on commit 12e91d8

Please sign in to comment.