Skip to content

Commit 508a206

Browse files
test: check ts version and compare diff output if v5
1 parent 4858616 commit 508a206

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

test/plugin/fixtures/es5-class.dto.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,33 @@ exports.CreateCatDtoEs5 = void 0;
2222
var openapi = require(\"@nestjs/swagger\");
2323
var status_1 = require(\"./status\");
2424
var constants_1 = require(\"./constants\");
25+
var CreateCatDtoEs5 = /** @class */ (function () {
26+
function CreateCatDtoEs5() {
27+
// field name
28+
this.name = constants_1.CONSTANT_STRING;
29+
/** status */
30+
this.status = status_1.Status.ENABLED;
31+
this.obj = constants_1.CONSTANT_OBJECT;
32+
this.age = 3;
33+
}
34+
CreateCatDtoEs5._OPENAPI_METADATA_FACTORY = function () {
35+
return { name: { required: true, type: function () { return String; }, default: constants_1.CONSTANT_STRING }, status: { required: true, type: function () { return Object; }, description: "status", default: status_1.Status.ENABLED }, obj: { required: true, type: function () { return Object; }, default: constants_1.CONSTANT_OBJECT }, age: { required: true, type: function () { return Number; }, default: 3, minimum: constants_1.MIN_VAL, maximum: 10 } };
36+
};
37+
__decorate([
38+
Min(constants_1.MIN_VAL),
39+
Max(10)
40+
], CreateCatDtoEs5.prototype, \"age\", void 0);
41+
return CreateCatDtoEs5;
42+
}());
43+
exports.CreateCatDtoEs5 = CreateCatDtoEs5;
44+
`;
45+
46+
export const es5CreateCatDtoTextTranspiledV5 = `\"use strict\";
47+
Object.defineProperty(exports, \"__esModule\", { value: true });
48+
exports.CreateCatDtoEs5 = void 0;
49+
var openapi = require(\"@nestjs/swagger\");
50+
var status_1 = require(\"./status\");
51+
var constants_1 = require(\"./constants\");
2552
var CreateCatDtoEs5 = exports.CreateCatDtoEs5 = /** @class */ (function () {
2653
function CreateCatDtoEs5() {
2754
// field name

test/plugin/model-class-visitor.spec.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import {
1919
} from './fixtures/create-cat.dto';
2020
import {
2121
es5CreateCatDtoText,
22-
es5CreateCatDtoTextTranspiled
22+
es5CreateCatDtoTextTranspiled,
23+
es5CreateCatDtoTextTranspiledV5
2324
} from './fixtures/es5-class.dto';
2425
import {
2526
nullableDtoText,
@@ -135,7 +136,14 @@ describe('API model properties', () => {
135136
]
136137
}
137138
});
138-
expect(result.outputText).toEqual(es5CreateCatDtoTextTranspiled);
139+
140+
const [tsVersionMajor] = ts.versionMajorMinor?.split('.').map((x) => +x);
141+
142+
if (tsVersionMajor === 5) {
143+
expect(result.outputText).toEqual(es5CreateCatDtoTextTranspiledV5);
144+
} else {
145+
expect(result.outputText).toEqual(es5CreateCatDtoTextTranspiled);
146+
}
139147
});
140148

141149
it('should support & understand nullable type unions', () => {

0 commit comments

Comments
 (0)