Skip to content

Commit

Permalink
fix(index): remove default export and rename createMiddleware
Browse files Browse the repository at this point in the history
as building default export of this package makes CommonJS users
need to access it via 'default' property, as there is no perfect
way to handle this due to a TypeScript issue, remove default export
and export createMiddleware so it is accessible via a property; rename
createMiddleware to createMockMiddleware that I personnaly find more meaningful;
update index spec and app testing

#9
  • Loading branch information
adrienv1520 committed Jun 28, 2020
1 parent 83e1bc8 commit 91d90d3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import path from 'path';

import { Router } from 'express';

import createMiddleware from './index';
import { createMockMiddleware } from './index';

describe('createMiddleware', () => {
describe('createMockMiddleware', () => {
it('should return an instance of the express router', async () => {
const middleware = createMiddleware({
const middleware = createMockMiddleware({
file: path.resolve(__dirname, '../test/fixtures/petstore.yaml'),
});

Expand All @@ -15,7 +15,7 @@ describe('createMiddleware', () => {

it('should throw an error if the given file does not exist', () => {
try {
createMiddleware({
createMockMiddleware({
file: path.resolve(__dirname, '../test/fixtures/petstore_not_exist.yaml'),
});
throw new Error('exit');
Expand Down
4 changes: 1 addition & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface MiddlewareOptions {
options?: Partial<JSFOptions>;
}

const createMiddleware = ({
export const createMockMiddleware = ({
file,
locale = 'en',
options = {},
Expand Down Expand Up @@ -52,5 +52,3 @@ const createMiddleware = ({

return router;
};

export default createMiddleware;
4 changes: 2 additions & 2 deletions test/helpers/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import path from 'path';

import express from 'express';

import createMiddleware from '../../src';
import { createMockMiddleware } from '../../src';

const app = express();

const middleware = createMiddleware({
const middleware = createMockMiddleware({
file: path.resolve(__dirname, '../fixtures/petstore.yaml'),
});

Expand Down

0 comments on commit 91d90d3

Please sign in to comment.