Skip to content

Commit

Permalink
test: check ts version and compare diff output if v5
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Mar 31, 2023
1 parent 4858616 commit 508a206
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
27 changes: 27 additions & 0 deletions test/plugin/fixtures/es5-class.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,33 @@ exports.CreateCatDtoEs5 = void 0;
var openapi = require(\"@nestjs/swagger\");
var status_1 = require(\"./status\");
var constants_1 = require(\"./constants\");
var CreateCatDtoEs5 = /** @class */ (function () {
function CreateCatDtoEs5() {
// field name
this.name = constants_1.CONSTANT_STRING;
/** status */
this.status = status_1.Status.ENABLED;
this.obj = constants_1.CONSTANT_OBJECT;
this.age = 3;
}
CreateCatDtoEs5._OPENAPI_METADATA_FACTORY = function () {
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 } };
};
__decorate([
Min(constants_1.MIN_VAL),
Max(10)
], CreateCatDtoEs5.prototype, \"age\", void 0);
return CreateCatDtoEs5;
}());
exports.CreateCatDtoEs5 = CreateCatDtoEs5;
`;

export const es5CreateCatDtoTextTranspiledV5 = `\"use strict\";
Object.defineProperty(exports, \"__esModule\", { value: true });
exports.CreateCatDtoEs5 = void 0;
var openapi = require(\"@nestjs/swagger\");
var status_1 = require(\"./status\");
var constants_1 = require(\"./constants\");
var CreateCatDtoEs5 = exports.CreateCatDtoEs5 = /** @class */ (function () {
function CreateCatDtoEs5() {
// field name
Expand Down
12 changes: 10 additions & 2 deletions test/plugin/model-class-visitor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import {
} from './fixtures/create-cat.dto';
import {
es5CreateCatDtoText,
es5CreateCatDtoTextTranspiled
es5CreateCatDtoTextTranspiled,
es5CreateCatDtoTextTranspiledV5
} from './fixtures/es5-class.dto';
import {
nullableDtoText,
Expand Down Expand Up @@ -135,7 +136,14 @@ describe('API model properties', () => {
]
}
});
expect(result.outputText).toEqual(es5CreateCatDtoTextTranspiled);

const [tsVersionMajor] = ts.versionMajorMinor?.split('.').map((x) => +x);

if (tsVersionMajor === 5) {
expect(result.outputText).toEqual(es5CreateCatDtoTextTranspiledV5);
} else {
expect(result.outputText).toEqual(es5CreateCatDtoTextTranspiled);
}
});

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

0 comments on commit 508a206

Please sign in to comment.