Skip to content

Commit cd75f5d

Browse files
committedFeb 15, 2021
refactor(): Refactor Controller class visitor tests
1 parent 4564117 commit cd75f5d

File tree

1 file changed

+31
-21
lines changed

1 file changed

+31
-21
lines changed
 

‎test/plugin/controller-class-visitor.spec.ts

+31-21
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,39 @@ import {
55
appControllerTextTranspiled
66
} from './fixtures/app.controller';
77

8+
const compilerOptions: ts.CompilerOptions = {
9+
module: ts.ModuleKind.CommonJS,
10+
target: ts.ScriptTarget.ESNext,
11+
newLine: ts.NewLineKind.LineFeed,
12+
noEmitHelpers: true
13+
}
14+
15+
const transpileModule = (filename, controllerText, compilerOptions, swaggerDocumentOptions = {}) => {
16+
const fakeProgram = ts.createProgram([filename], compilerOptions);
17+
18+
return ts.transpileModule(controllerText, {
19+
compilerOptions,
20+
fileName: filename,
21+
transformers: {
22+
before: [
23+
before(
24+
{...swaggerDocumentOptions, introspectComments: true },
25+
fakeProgram
26+
)
27+
]
28+
}
29+
})
30+
}
31+
832
describe('Controller methods', () => {
9-
it('should add response based on the return value', () => {
10-
const options: ts.CompilerOptions = {
11-
module: ts.ModuleKind.CommonJS,
12-
target: ts.ScriptTarget.ESNext,
13-
newLine: ts.NewLineKind.LineFeed,
14-
noEmitHelpers: true
15-
};
16-
const filename = 'app.controller.ts';
17-
const fakeProgram = ts.createProgram([filename], options);
33+
it('Should generate summary property', () => {
34+
const result = transpileModule(
35+
'app.controller.ts',
36+
appControllerText,
37+
compilerOptions,
38+
{controllerKeyOfComment: 'summary'}
39+
);
1840

19-
const result = ts.transpileModule(appControllerText, {
20-
compilerOptions: options,
21-
fileName: filename,
22-
transformers: {
23-
before: [
24-
before(
25-
{ controllerKeyOfComment: 'summary', introspectComments: true },
26-
fakeProgram
27-
)
28-
]
29-
}
30-
});
3141
expect(result.outputText).toEqual(appControllerTextTranspiled);
3242
});
3343
});

0 commit comments

Comments
 (0)
Please sign in to comment.