Skip to content

Commit

Permalink
refactor: reorganize test fixtures to avoid need for resource copying
Browse files Browse the repository at this point in the history
Move test fixtures from `/test` to package root directories. This way
the build step does not have to copy them over to `/dist`, which
saves time and will make the watch mode more effective once we enable
it.
  • Loading branch information
bajtos committed Oct 8, 2018
1 parent 73e19ff commit 1a8c8c1
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 18 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,14 @@ describe('HttpServer (integration)', () => {
host?: string;
}): HttpServer {
const options: HttpServerOptions = {protocol: 'https', host};
const certDir = path.resolve(__dirname, '../../../fixtures');
if (usePfx) {
const pfxPath = path.join(__dirname, 'pfx.pfx');
const pfxPath = path.join(certDir, 'pfx.pfx');
options.pfx = fs.readFileSync(pfxPath);
options.passphrase = 'loopback4';
} else {
const keyPath = path.join(__dirname, 'key.pem');
const certPath = path.join(__dirname, 'cert.pem');
const keyPath = path.join(certDir, 'key.pem');
const certPath = path.join(certDir, 'cert.pem');
options.key = fs.readFileSync(keyPath);
options.cert = fs.readFileSync(certPath);
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
30 changes: 16 additions & 14 deletions packages/rest/test/integration/rest.server.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import * as path from 'path';
import * as fs from 'fs';
import {RestServerConfig} from '../..';

const FIXTURES = path.resolve(__dirname, '../../../fixtures');

describe('RestServer (integration)', () => {
it('exports url property', async () => {
// Explicitly setting host to IPv4 address so test runs on Travis
Expand Down Expand Up @@ -79,7 +81,7 @@ describe('RestServer (integration)', () => {
});

it('does not allow static assets to be mounted at /', async () => {
const root = path.join(__dirname, 'fixtures');
const root = FIXTURES;
const server = await givenAServer({
rest: {
port: 0,
Expand Down Expand Up @@ -112,7 +114,7 @@ describe('RestServer (integration)', () => {
});

it('allows static assets via api', async () => {
const root = path.join(__dirname, 'fixtures');
const root = FIXTURES;
const server = await givenAServer({
rest: {
port: 0,
Expand All @@ -130,7 +132,7 @@ describe('RestServer (integration)', () => {
});

it('allows static assets via api after start', async () => {
const root = path.join(__dirname, 'fixtures');
const root = FIXTURES;
const server = await givenAServer({
rest: {
port: 0,
Expand All @@ -148,7 +150,7 @@ describe('RestServer (integration)', () => {
});

it('allows non-static routes after assets', async () => {
const root = path.join(__dirname, 'fixtures');
const root = FIXTURES;
const server = await givenAServer({
rest: {
port: 0,
Expand All @@ -163,7 +165,7 @@ describe('RestServer (integration)', () => {
});

it('serve static assets if matches before other routes', async () => {
const root = path.join(__dirname, 'fixtures');
const root = FIXTURES;
const server = await givenAServer({
rest: {
port: 0,
Expand Down Expand Up @@ -492,8 +494,8 @@ paths:
});

it('supports HTTPS protocol with key and certificate files', async () => {
const keyPath = path.join(__dirname, 'key.pem');
const certPath = path.join(__dirname, 'cert.pem');
const keyPath = path.join(FIXTURES, 'key.pem');
const certPath = path.join(FIXTURES, 'cert.pem');
const options = {
port: 0,
protocol: 'https',
Expand All @@ -510,7 +512,7 @@ paths:
});

it('supports HTTPS protocol with a pfx file', async () => {
const pfxPath = path.join(__dirname, 'pfx.pfx');
const pfxPath = path.join(FIXTURES, 'pfx.pfx');
const options = {
port: 0,
protocol: 'https',
Expand All @@ -528,8 +530,8 @@ paths:
});

itSkippedOnTravis('handles IPv6 loopback address in HTTPS', async () => {
const keyPath = path.join(__dirname, 'key.pem');
const certPath = path.join(__dirname, 'cert.pem');
const keyPath = path.join(FIXTURES, 'key.pem');
const certPath = path.join(FIXTURES, 'cert.pem');
const server = await givenAServer({
rest: {
port: 0,
Expand All @@ -549,8 +551,8 @@ paths:

// https://github.com/strongloop/loopback-next/issues/1623
itSkippedOnTravis('handles IPv6 address for API Explorer UI', async () => {
const keyPath = path.join(__dirname, 'key.pem');
const certPath = path.join(__dirname, 'cert.pem');
const keyPath = path.join(FIXTURES, 'key.pem');
const certPath = path.join(FIXTURES, 'cert.pem');
const server = await givenAServer({
rest: {
port: 0,
Expand All @@ -576,8 +578,8 @@ paths:
});

it('honors HTTPS config binding after instantiation', async () => {
const keyPath = path.join(__dirname, 'key.pem');
const certPath = path.join(__dirname, 'cert.pem');
const keyPath = path.join(FIXTURES, 'key.pem');
const certPath = path.join(FIXTURES, 'cert.pem');
const options = {
port: 0,
protocol: 'https',
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import {TestSandbox, expect} from '../..';
import {resolve} from 'path';
import {remove, pathExists, readFile, writeJSON} from 'fs-extra';

const FIXTURES = resolve(__dirname, '../../../fixtures');

describe('TestSandbox integration tests', () => {
let sandbox: TestSandbox;
let path: string;
const COPY_FILE = 'copy-me.txt';
const COPY_FILE_PATH = resolve(__dirname, '../fixtures', COPY_FILE);
const COPY_FILE_PATH = resolve(FIXTURES, COPY_FILE);

beforeEach(createSandbox);
beforeEach(givenPath);
Expand Down

0 comments on commit 1a8c8c1

Please sign in to comment.