Skip to content

Commit

Permalink
refactor(): Refactor Controller class visitor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmiguelbesada committed Feb 15, 2021
1 parent 4564117 commit cd75f5d
Showing 1 changed file with 31 additions and 21 deletions.
52 changes: 31 additions & 21 deletions test/plugin/controller-class-visitor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,39 @@ import {
appControllerTextTranspiled
} from './fixtures/app.controller';

const compilerOptions: ts.CompilerOptions = {
module: ts.ModuleKind.CommonJS,
target: ts.ScriptTarget.ESNext,
newLine: ts.NewLineKind.LineFeed,
noEmitHelpers: true
}

const transpileModule = (filename, controllerText, compilerOptions, swaggerDocumentOptions = {}) => {
const fakeProgram = ts.createProgram([filename], compilerOptions);

return ts.transpileModule(controllerText, {
compilerOptions,
fileName: filename,
transformers: {
before: [
before(
{...swaggerDocumentOptions, introspectComments: true },
fakeProgram
)
]
}
})
}

describe('Controller methods', () => {
it('should add response based on the return value', () => {
const options: ts.CompilerOptions = {
module: ts.ModuleKind.CommonJS,
target: ts.ScriptTarget.ESNext,
newLine: ts.NewLineKind.LineFeed,
noEmitHelpers: true
};
const filename = 'app.controller.ts';
const fakeProgram = ts.createProgram([filename], options);
it('Should generate summary property', () => {
const result = transpileModule(
'app.controller.ts',
appControllerText,
compilerOptions,
{controllerKeyOfComment: 'summary'}
);

const result = ts.transpileModule(appControllerText, {
compilerOptions: options,
fileName: filename,
transformers: {
before: [
before(
{ controllerKeyOfComment: 'summary', introspectComments: true },
fakeProgram
)
]
}
});
expect(result.outputText).toEqual(appControllerTextTranspiled);
});
});

0 comments on commit cd75f5d

Please sign in to comment.