From 8fe2c32ddddd0c4a771481a297f25996ce61836a Mon Sep 17 00:00:00 2001 From: nitintejuja Date: Tue, 16 Aug 2022 16:05:51 +0530 Subject: [PATCH] fix: simplified example tests (#864) --- examples/TEMPLATE/index.spec.ts | 5 +- examples/TEMPLATE/index.ts | 4 +- .../adapting-input-and-output/index.spec.ts | 5 +- examples/adapting-input-and-output/index.ts | 4 +- examples/asyncapi-from-object/index.spec.ts | 5 +- examples/asyncapi-from-object/index.ts | 4 +- examples/asyncapi-from-parser/index.spec.ts | 5 +- examples/asyncapi-from-parser/index.ts | 4 +- examples/change-type-mapping/index.spec.ts | 5 +- examples/change-type-mapping/index.ts | 4 +- .../index.spec.ts | 5 +- .../index.ts | 4 +- .../index.spec.ts | 5 +- .../csharp-change-collection-type/index.ts | 4 +- .../index.spec.ts | 5 +- .../index.ts | 4 +- .../index.spec.ts | 5 +- .../index.ts | 4 +- .../csharp-generate-serializer/index.spec.ts | 5 +- examples/csharp-generate-serializer/index.ts | 4 +- .../index.spec.ts | 5 +- .../csharp-overwrite-enum-naming/index.ts | 4 +- examples/csharp-use-inheritance/index.spec.ts | 5 +- examples/csharp-use-inheritance/index.ts | 4 +- examples/custom-logging/index.spec.ts | 4 +- examples/custom-logging/index.ts | 4 +- .../index.spec.ts | 4 +- .../dart-generate-json-annotation/index.ts | 4 +- examples/generate-csharp-models/index.spec.ts | 5 +- examples/generate-csharp-models/index.ts | 4 +- examples/generate-dart-models/index.spec.ts | 4 +- examples/generate-dart-models/index.ts | 4 +- examples/generate-go-enums/index.spec.ts | 3 +- examples/generate-go-enums/index.ts | 4 +- examples/generate-go-models/index.spec.ts | 4 +- examples/generate-go-models/index.ts | 4 +- examples/generate-java-models/index.spec.ts | 4 +- examples/generate-java-models/index.ts | 4 +- .../generate-javascript-models/index.spec.ts | 5 +- examples/generate-javascript-models/index.ts | 4 +- examples/generate-to-files/index.ts | 4 +- .../generate-typescript-models/index.spec.ts | 4 +- examples/generate-typescript-models/index.ts | 4 +- .../include-custom-function/index.spec.ts | 5 +- examples/include-custom-function/index.ts | 4 +- .../indentation-type-and-size/index.spec.ts | 5 +- examples/indentation-type-and-size/index.ts | 4 +- .../java-change-collection-type/index.spec.ts | 5 +- examples/java-change-collection-type/index.ts | 4 +- .../index.spec.ts | 3 +- .../index.ts | 4 +- .../java-from-typescript-type/index.spec.ts | 3 +- examples/java-from-typescript-type/index.ts | 4 +- examples/java-generate-equals/index.spec.ts | 5 +- examples/java-generate-equals/index.ts | 4 +- examples/java-generate-hashcode/index.spec.ts | 5 +- examples/java-generate-hashcode/index.ts | 4 +- .../index.spec.ts | 5 +- .../java-generate-jackson-annotation/index.ts | 4 +- examples/java-generate-javadoc/index.spec.ts | 4 +- examples/java-generate-javadoc/index.ts | 4 +- .../index.spec.ts | 4 +- .../index.ts | 4 +- .../java-generate-marshalling/index.spec.ts | 5 +- examples/java-generate-marshalling/index.ts | 4 +- examples/java-generate-tostring/index.spec.ts | 5 +- examples/java-generate-tostring/index.ts | 4 +- .../javascript-generate-example/index.spec.ts | 5 +- examples/javascript-generate-example/index.ts | 4 +- .../index.spec.ts | 5 +- .../javascript-generate-marshalling/index.ts | 4 +- .../__snapshots__/index.spec.ts.snap | 20 -------- examples/javascript-use-cjs/index.spec.ts | 4 +- examples/javascript-use-cjs/index.ts | 4 +- .../__snapshots__/index.spec.ts.snap | 21 --------- examples/javascript-use-esm/index.spec.ts | 4 +- examples/javascript-use-esm/index.ts | 4 +- .../index.spec.ts | 5 +- .../json-schema-draft7-from-object/index.ts | 4 +- examples/meta-model/index.spec.ts | 5 +- examples/meta-model/index.ts | 4 +- examples/openapi-from-object/index.spec.ts | 7 ++- examples/openapi-from-object/index.ts | 4 +- .../index.spec.ts | 5 +- .../overwrite-default-constraint/index.ts | 4 +- .../overwrite-naming-formatting/index.spec.ts | 5 +- examples/overwrite-naming-formatting/index.ts | 4 +- .../__snapshots__/index.spec.ts.snap | 46 ------------------- examples/rust-generate-crate/index.spec.ts | 3 -- examples/swagger2.0-from-object/index.spec.ts | 7 ++- examples/swagger2.0-from-object/index.ts | 4 +- examples/typescript-enum-type/index.spec.ts | 13 ++---- examples/typescript-enum-type/index.ts | 4 +- .../__snapshots__/index.spec.ts.snap | 27 ----------- .../index.spec.ts | 2 +- .../typescript-generate-comments/index.ts | 4 +- .../typescript-generate-example/index.spec.ts | 5 +- examples/typescript-generate-example/index.ts | 4 +- .../index.spec.ts | 5 +- .../typescript-generate-marshalling/index.ts | 4 +- examples/typescript-interface/index.spec.ts | 5 +- examples/typescript-interface/index.ts | 4 +- .../__snapshots__/index.spec.ts.snap | 19 -------- examples/typescript-use-cjs/index.spec.ts | 4 +- examples/typescript-use-cjs/index.ts | 4 +- .../__snapshots__/index.spec.ts.snap | 20 -------- examples/typescript-use-esm/index.spec.ts | 4 +- examples/typescript-use-esm/index.ts | 4 +- 108 files changed, 248 insertions(+), 353 deletions(-) diff --git a/examples/TEMPLATE/index.spec.ts b/examples/TEMPLATE/index.spec.ts index a30b648126..c77a887d93 100644 --- a/examples/TEMPLATE/index.spec.ts +++ b/examples/TEMPLATE/index.spec.ts @@ -7,8 +7,7 @@ describe('Should be able to render TEMPLATE', () => { }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/TEMPLATE/index.ts b/examples/TEMPLATE/index.ts index f18220a373..4df638eb57 100644 --- a/examples/TEMPLATE/index.ts +++ b/examples/TEMPLATE/index.ts @@ -19,4 +19,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/adapting-input-and-output/index.spec.ts b/examples/adapting-input-and-output/index.spec.ts index 96f6ba64f2..c598484c17 100644 --- a/examples/adapting-input-and-output/index.spec.ts +++ b/examples/adapting-input-and-output/index.spec.ts @@ -8,8 +8,7 @@ describe('Should be able to generate a model with custom input and output ', () test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/adapting-input-and-output/index.ts b/examples/adapting-input-and-output/index.ts index 4469debd6e..c7fb45f225 100644 --- a/examples/adapting-input-and-output/index.ts +++ b/examples/adapting-input-and-output/index.ts @@ -51,4 +51,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/asyncapi-from-object/index.spec.ts b/examples/asyncapi-from-object/index.spec.ts index 340f32473e..e58490514d 100644 --- a/examples/asyncapi-from-object/index.spec.ts +++ b/examples/asyncapi-from-object/index.spec.ts @@ -6,8 +6,7 @@ describe('Should be able to process a pure AsyncAPI object', () => { }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/asyncapi-from-object/index.ts b/examples/asyncapi-from-object/index.ts index 58caf69177..e828942f55 100644 --- a/examples/asyncapi-from-object/index.ts +++ b/examples/asyncapi-from-object/index.ts @@ -35,4 +35,6 @@ export async function generate(): Promise { } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/asyncapi-from-parser/index.spec.ts b/examples/asyncapi-from-parser/index.spec.ts index ebd46480c5..30e917b02e 100644 --- a/examples/asyncapi-from-parser/index.spec.ts +++ b/examples/asyncapi-from-parser/index.spec.ts @@ -7,8 +7,7 @@ describe('Should be able to process AsyncAPI object from parser', () => { }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/asyncapi-from-parser/index.ts b/examples/asyncapi-from-parser/index.ts index e17abbbf54..0580ddeecb 100644 --- a/examples/asyncapi-from-parser/index.ts +++ b/examples/asyncapi-from-parser/index.ts @@ -36,4 +36,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/change-type-mapping/index.spec.ts b/examples/change-type-mapping/index.spec.ts index a547641ec9..0f54c447ac 100644 --- a/examples/change-type-mapping/index.spec.ts +++ b/examples/change-type-mapping/index.spec.ts @@ -7,8 +7,7 @@ describe('Should be able to render models with custom naming formatter', () => { }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/change-type-mapping/index.ts b/examples/change-type-mapping/index.ts index 896cc42ed2..f6b4d8d06f 100644 --- a/examples/change-type-mapping/index.ts +++ b/examples/change-type-mapping/index.ts @@ -26,4 +26,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/csharp-auto-implemented-properties/index.spec.ts b/examples/csharp-auto-implemented-properties/index.spec.ts index b06b481db0..4efbab1158 100644 --- a/examples/csharp-auto-implemented-properties/index.spec.ts +++ b/examples/csharp-auto-implemented-properties/index.spec.ts @@ -7,8 +7,7 @@ describe('Should be able to render auto-implemented properties in CSharp', () => }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/csharp-auto-implemented-properties/index.ts b/examples/csharp-auto-implemented-properties/index.ts index d94599eba9..3ef98ef54c 100644 --- a/examples/csharp-auto-implemented-properties/index.ts +++ b/examples/csharp-auto-implemented-properties/index.ts @@ -37,4 +37,6 @@ export async function generate(): Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/csharp-change-collection-type/index.spec.ts b/examples/csharp-change-collection-type/index.spec.ts index 104bee728e..87c1069add 100644 --- a/examples/csharp-change-collection-type/index.spec.ts +++ b/examples/csharp-change-collection-type/index.spec.ts @@ -7,8 +7,7 @@ describe('Should be able to render collections in C# as IEnumerable', () => { }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/csharp-change-collection-type/index.ts b/examples/csharp-change-collection-type/index.ts index 2788d91289..3717566cae 100644 --- a/examples/csharp-change-collection-type/index.ts +++ b/examples/csharp-change-collection-type/index.ts @@ -24,4 +24,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/csharp-generate-equals-and-hashcode/index.spec.ts b/examples/csharp-generate-equals-and-hashcode/index.spec.ts index 27b79e2baf..e6327b7199 100644 --- a/examples/csharp-generate-equals-and-hashcode/index.spec.ts +++ b/examples/csharp-generate-equals-and-hashcode/index.spec.ts @@ -7,8 +7,7 @@ describe('Should be able to generate a model to overwrite the Equal and GetHashC }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/csharp-generate-equals-and-hashcode/index.ts b/examples/csharp-generate-equals-and-hashcode/index.ts index 5dc20f5d20..e3155f698a 100644 --- a/examples/csharp-generate-equals-and-hashcode/index.ts +++ b/examples/csharp-generate-equals-and-hashcode/index.ts @@ -30,4 +30,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/csharp-generate-required-properties/index.spec.ts b/examples/csharp-generate-required-properties/index.spec.ts index bf35ba6885..6ae82e0185 100644 --- a/examples/csharp-generate-required-properties/index.spec.ts +++ b/examples/csharp-generate-required-properties/index.spec.ts @@ -7,8 +7,7 @@ describe('Should be able to render required properties without the question mark }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/csharp-generate-required-properties/index.ts b/examples/csharp-generate-required-properties/index.ts index a88e60a6f7..43cab37d29 100644 --- a/examples/csharp-generate-required-properties/index.ts +++ b/examples/csharp-generate-required-properties/index.ts @@ -28,4 +28,6 @@ export async function generate(): Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/csharp-generate-serializer/index.spec.ts b/examples/csharp-generate-serializer/index.spec.ts index daa49a7090..534a2241e1 100644 --- a/examples/csharp-generate-serializer/index.spec.ts +++ b/examples/csharp-generate-serializer/index.spec.ts @@ -8,8 +8,7 @@ describe('Should be able to generate a model with functions to serialize the dat test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/csharp-generate-serializer/index.ts b/examples/csharp-generate-serializer/index.ts index 2751d2346e..efe7fedf79 100644 --- a/examples/csharp-generate-serializer/index.ts +++ b/examples/csharp-generate-serializer/index.ts @@ -24,4 +24,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/csharp-overwrite-enum-naming/index.spec.ts b/examples/csharp-overwrite-enum-naming/index.spec.ts index 890ec61d94..856b5a2d29 100644 --- a/examples/csharp-overwrite-enum-naming/index.spec.ts +++ b/examples/csharp-overwrite-enum-naming/index.spec.ts @@ -8,8 +8,7 @@ describe('Should be able to generate enums with custom value names', () => { test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/csharp-overwrite-enum-naming/index.ts b/examples/csharp-overwrite-enum-naming/index.ts index 65461a8891..c6c98df420 100644 --- a/examples/csharp-overwrite-enum-naming/index.ts +++ b/examples/csharp-overwrite-enum-naming/index.ts @@ -41,4 +41,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/csharp-use-inheritance/index.spec.ts b/examples/csharp-use-inheritance/index.spec.ts index cdd2dc1010..87b3444a41 100644 --- a/examples/csharp-use-inheritance/index.spec.ts +++ b/examples/csharp-use-inheritance/index.spec.ts @@ -7,8 +7,7 @@ describe('Should be able to render inheritance', () => { }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/csharp-use-inheritance/index.ts b/examples/csharp-use-inheritance/index.ts index 88eca435f3..c6f3cc875b 100644 --- a/examples/csharp-use-inheritance/index.ts +++ b/examples/csharp-use-inheritance/index.ts @@ -49,4 +49,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/custom-logging/index.spec.ts b/examples/custom-logging/index.spec.ts index 9b23762dd2..a139b87bf8 100644 --- a/examples/custom-logging/index.spec.ts +++ b/examples/custom-logging/index.spec.ts @@ -11,7 +11,7 @@ describe('Should be able to use custom logging interface', () => { test('and should log expected output to console', async () => { await generate(); - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/custom-logging/index.ts b/examples/custom-logging/index.ts index a63257e7e4..48ea9aa5a2 100644 --- a/examples/custom-logging/index.ts +++ b/examples/custom-logging/index.ts @@ -27,4 +27,6 @@ export async function generate(): Promise { } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/dart-generate-json-annotation/index.spec.ts b/examples/dart-generate-json-annotation/index.spec.ts index 04d73e2656..deaea18240 100644 --- a/examples/dart-generate-json-annotation/index.spec.ts +++ b/examples/dart-generate-json-annotation/index.spec.ts @@ -7,7 +7,7 @@ describe('Should be able to render Dart Models', () => { }); test('and should log expected output to console', async () => { await generate(); - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/dart-generate-json-annotation/index.ts b/examples/dart-generate-json-annotation/index.ts index f27a8e74cb..5f1a1d6de2 100644 --- a/examples/dart-generate-json-annotation/index.ts +++ b/examples/dart-generate-json-annotation/index.ts @@ -20,5 +20,7 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/generate-csharp-models/index.spec.ts b/examples/generate-csharp-models/index.spec.ts index adf3b7871d..0725be88a8 100644 --- a/examples/generate-csharp-models/index.spec.ts +++ b/examples/generate-csharp-models/index.spec.ts @@ -7,8 +7,7 @@ describe('Should be able to render C# models ', () => { }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/generate-csharp-models/index.ts b/examples/generate-csharp-models/index.ts index 9cdff58448..8024160535 100644 --- a/examples/generate-csharp-models/index.ts +++ b/examples/generate-csharp-models/index.ts @@ -19,4 +19,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/generate-dart-models/index.spec.ts b/examples/generate-dart-models/index.spec.ts index 04d73e2656..deaea18240 100644 --- a/examples/generate-dart-models/index.spec.ts +++ b/examples/generate-dart-models/index.spec.ts @@ -7,7 +7,7 @@ describe('Should be able to render Dart Models', () => { }); test('and should log expected output to console', async () => { await generate(); - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/generate-dart-models/index.ts b/examples/generate-dart-models/index.ts index 711416f428..c5da7e7106 100644 --- a/examples/generate-dart-models/index.ts +++ b/examples/generate-dart-models/index.ts @@ -19,4 +19,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/generate-go-enums/index.spec.ts b/examples/generate-go-enums/index.spec.ts index c7e70d5cff..f7539985df 100644 --- a/examples/generate-go-enums/index.spec.ts +++ b/examples/generate-go-enums/index.spec.ts @@ -7,8 +7,7 @@ describe('Should be able to render Go Enums', () => { }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 3 model (root and three different enums type), we double it - expect(spy.mock.calls.length).toEqual(6); + expect(spy.mock.calls.length).toEqual(3); expect(spy.mock.calls[0]).toMatchSnapshot(); expect(spy.mock.calls[1]).toMatchSnapshot(); expect(spy.mock.calls[2]).toMatchSnapshot(); diff --git a/examples/generate-go-enums/index.ts b/examples/generate-go-enums/index.ts index 99c44dda72..0d5f7e9776 100644 --- a/examples/generate-go-enums/index.ts +++ b/examples/generate-go-enums/index.ts @@ -25,4 +25,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/generate-go-models/index.spec.ts b/examples/generate-go-models/index.spec.ts index aec289cd64..a2fcfde63b 100644 --- a/examples/generate-go-models/index.spec.ts +++ b/examples/generate-go-models/index.spec.ts @@ -7,7 +7,7 @@ describe('Should be able to render Go Models', () => { }); test('and should log expected output to console', async () => { await generate(); - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/generate-go-models/index.ts b/examples/generate-go-models/index.ts index 5401dc8f93..7f8ee5b759 100644 --- a/examples/generate-go-models/index.ts +++ b/examples/generate-go-models/index.ts @@ -19,4 +19,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/generate-java-models/index.spec.ts b/examples/generate-java-models/index.spec.ts index 3784c9d664..3e6e222d60 100644 --- a/examples/generate-java-models/index.spec.ts +++ b/examples/generate-java-models/index.spec.ts @@ -7,7 +7,7 @@ describe('Should be able to render Java Models', () => { }); test('and should log expected output to console', async () => { await generate(); - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/generate-java-models/index.ts b/examples/generate-java-models/index.ts index 7909d85845..871257c5c4 100644 --- a/examples/generate-java-models/index.ts +++ b/examples/generate-java-models/index.ts @@ -19,4 +19,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/generate-javascript-models/index.spec.ts b/examples/generate-javascript-models/index.spec.ts index ed43798407..6fa900210f 100644 --- a/examples/generate-javascript-models/index.spec.ts +++ b/examples/generate-javascript-models/index.spec.ts @@ -7,8 +7,7 @@ describe('Should be able to render Javascript models', () => { }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/generate-javascript-models/index.ts b/examples/generate-javascript-models/index.ts index 3d67efde6c..39b6fa6a78 100644 --- a/examples/generate-javascript-models/index.ts +++ b/examples/generate-javascript-models/index.ts @@ -19,4 +19,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/generate-to-files/index.ts b/examples/generate-to-files/index.ts index 727eb06144..adf1f80938 100644 --- a/examples/generate-to-files/index.ts +++ b/examples/generate-to-files/index.ts @@ -23,4 +23,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/generate-typescript-models/index.spec.ts b/examples/generate-typescript-models/index.spec.ts index e11e37fc0e..efc2e60e23 100644 --- a/examples/generate-typescript-models/index.spec.ts +++ b/examples/generate-typescript-models/index.spec.ts @@ -7,7 +7,7 @@ describe('Should be able to render TypeScript Models', () => { }); test('and should log expected output to console', async () => { await generate(); - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/generate-typescript-models/index.ts b/examples/generate-typescript-models/index.ts index f18220a373..4df638eb57 100644 --- a/examples/generate-typescript-models/index.ts +++ b/examples/generate-typescript-models/index.ts @@ -19,4 +19,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/include-custom-function/index.spec.ts b/examples/include-custom-function/index.spec.ts index 1efd876bca..def89ad5bc 100644 --- a/examples/include-custom-function/index.spec.ts +++ b/examples/include-custom-function/index.spec.ts @@ -7,8 +7,7 @@ describe('Should be able to render custom function', () => { }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/include-custom-function/index.ts b/examples/include-custom-function/index.ts index 699deb716c..472a185fdf 100644 --- a/examples/include-custom-function/index.ts +++ b/examples/include-custom-function/index.ts @@ -32,4 +32,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/indentation-type-and-size/index.spec.ts b/examples/indentation-type-and-size/index.spec.ts index 2e7f9a4e1e..59fb8e68a8 100644 --- a/examples/indentation-type-and-size/index.spec.ts +++ b/examples/indentation-type-and-size/index.spec.ts @@ -7,8 +7,7 @@ describe('Should render the typescript class with 4 tabs as indentation', () => }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/indentation-type-and-size/index.ts b/examples/indentation-type-and-size/index.ts index b31c977551..ca4fcde522 100644 --- a/examples/indentation-type-and-size/index.ts +++ b/examples/indentation-type-and-size/index.ts @@ -24,4 +24,6 @@ export async function generate(): Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/java-change-collection-type/index.spec.ts b/examples/java-change-collection-type/index.spec.ts index 16f6686758..b6dd02723f 100644 --- a/examples/java-change-collection-type/index.spec.ts +++ b/examples/java-change-collection-type/index.spec.ts @@ -7,8 +7,7 @@ describe('Should be able to render collections in Java as List', () => { }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/java-change-collection-type/index.ts b/examples/java-change-collection-type/index.ts index ec637f7076..a988b33f59 100644 --- a/examples/java-change-collection-type/index.ts +++ b/examples/java-change-collection-type/index.ts @@ -24,4 +24,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/java-from-typescript-type-with-options/index.spec.ts b/examples/java-from-typescript-type-with-options/index.spec.ts index 00c8385064..11854f14e5 100644 --- a/examples/java-from-typescript-type-with-options/index.spec.ts +++ b/examples/java-from-typescript-type-with-options/index.spec.ts @@ -8,8 +8,7 @@ along with specific options`, () => { }); test('and should log expected output to console', async () => { await generate(); - //GenerateWithOptions is called 4x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(4); + expect(spy.mock.calls.length).toEqual(2); expect(spy.mock.calls[1]).toMatchSnapshot(); }); }); diff --git a/examples/java-from-typescript-type-with-options/index.ts b/examples/java-from-typescript-type-with-options/index.ts index ac5e9b4c6c..336726c039 100644 --- a/examples/java-from-typescript-type-with-options/index.ts +++ b/examples/java-from-typescript-type-with-options/index.ts @@ -28,4 +28,6 @@ export async function generate() : Promise { } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/java-from-typescript-type/index.spec.ts b/examples/java-from-typescript-type/index.spec.ts index 1992f55ff2..f0987b2584 100644 --- a/examples/java-from-typescript-type/index.spec.ts +++ b/examples/java-from-typescript-type/index.spec.ts @@ -7,8 +7,7 @@ describe('Should be able to generate Java model from a TypeScript type file', () }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 4x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(4); + expect(spy.mock.calls.length).toEqual(2); expect(spy.mock.calls[1]).toMatchSnapshot(); }); }); diff --git a/examples/java-from-typescript-type/index.ts b/examples/java-from-typescript-type/index.ts index 72495af0fe..078facd387 100644 --- a/examples/java-from-typescript-type/index.ts +++ b/examples/java-from-typescript-type/index.ts @@ -18,4 +18,6 @@ export async function generate() : Promise { } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/java-generate-equals/index.spec.ts b/examples/java-generate-equals/index.spec.ts index 905b579e2b..9bc785baa8 100644 --- a/examples/java-generate-equals/index.spec.ts +++ b/examples/java-generate-equals/index.spec.ts @@ -7,8 +7,7 @@ describe('Should be able to generate a model to overwrite the Equal methods', () }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/java-generate-equals/index.ts b/examples/java-generate-equals/index.ts index ba80aed520..1fcf53a1a8 100644 --- a/examples/java-generate-equals/index.ts +++ b/examples/java-generate-equals/index.ts @@ -32,4 +32,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/java-generate-hashcode/index.spec.ts b/examples/java-generate-hashcode/index.spec.ts index 11cc623a40..6f48c3c99b 100644 --- a/examples/java-generate-hashcode/index.spec.ts +++ b/examples/java-generate-hashcode/index.spec.ts @@ -7,8 +7,7 @@ describe('Should be able to generate a model to overwrite the hashCode method', }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/java-generate-hashcode/index.ts b/examples/java-generate-hashcode/index.ts index 9caabfd64f..64bc283d18 100644 --- a/examples/java-generate-hashcode/index.ts +++ b/examples/java-generate-hashcode/index.ts @@ -32,4 +32,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/java-generate-jackson-annotation/index.spec.ts b/examples/java-generate-jackson-annotation/index.spec.ts index 34cc2aaa96..7608d82d09 100644 --- a/examples/java-generate-jackson-annotation/index.spec.ts +++ b/examples/java-generate-jackson-annotation/index.spec.ts @@ -7,8 +7,7 @@ describe('Should be able to generate data models for jackson annotation', () => }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/java-generate-jackson-annotation/index.ts b/examples/java-generate-jackson-annotation/index.ts index 3a1d4e2f31..3e096c1eb5 100644 --- a/examples/java-generate-jackson-annotation/index.ts +++ b/examples/java-generate-jackson-annotation/index.ts @@ -19,4 +19,6 @@ export async function generate(): Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/java-generate-javadoc/index.spec.ts b/examples/java-generate-javadoc/index.spec.ts index 07188ca52a..5792a0a381 100644 --- a/examples/java-generate-javadoc/index.spec.ts +++ b/examples/java-generate-javadoc/index.spec.ts @@ -7,7 +7,7 @@ describe('Should be able to generate JavaDocs', () => { }); test('and should log expected output to console', async () => { await generate(); - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/java-generate-javadoc/index.ts b/examples/java-generate-javadoc/index.ts index a40dcc3b7a..285331135f 100644 --- a/examples/java-generate-javadoc/index.ts +++ b/examples/java-generate-javadoc/index.ts @@ -20,4 +20,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/java-generate-javax-constraint-annotation/index.spec.ts b/examples/java-generate-javax-constraint-annotation/index.spec.ts index b70419b2ad..00b271863c 100644 --- a/examples/java-generate-javax-constraint-annotation/index.spec.ts +++ b/examples/java-generate-javax-constraint-annotation/index.spec.ts @@ -7,7 +7,7 @@ describe('Should be able to generate models with javax.validation.constraints an }); test('and should log expected output to console', async () => { await generate(); - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/java-generate-javax-constraint-annotation/index.ts b/examples/java-generate-javax-constraint-annotation/index.ts index 66af786d44..0955e3bce6 100644 --- a/examples/java-generate-javax-constraint-annotation/index.ts +++ b/examples/java-generate-javax-constraint-annotation/index.ts @@ -22,4 +22,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/java-generate-marshalling/index.spec.ts b/examples/java-generate-marshalling/index.spec.ts index 28b2ada9c0..88724b803f 100644 --- a/examples/java-generate-marshalling/index.spec.ts +++ b/examples/java-generate-marshalling/index.spec.ts @@ -7,8 +7,7 @@ describe('Should be able to generate ts data model with marshal und unmarshal fu }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/java-generate-marshalling/index.ts b/examples/java-generate-marshalling/index.ts index 06d21f8afd..30e4722368 100644 --- a/examples/java-generate-marshalling/index.ts +++ b/examples/java-generate-marshalling/index.ts @@ -32,4 +32,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/java-generate-tostring/index.spec.ts b/examples/java-generate-tostring/index.spec.ts index e0ac74b01e..c23d851854 100644 --- a/examples/java-generate-tostring/index.spec.ts +++ b/examples/java-generate-tostring/index.spec.ts @@ -7,8 +7,7 @@ describe('Should be able to generate a model to overwrite the toString method', }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/java-generate-tostring/index.ts b/examples/java-generate-tostring/index.ts index 07ac50142f..d61ede70bb 100644 --- a/examples/java-generate-tostring/index.ts +++ b/examples/java-generate-tostring/index.ts @@ -32,4 +32,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/javascript-generate-example/index.spec.ts b/examples/javascript-generate-example/index.spec.ts index 3436cf41e5..9561122cae 100644 --- a/examples/javascript-generate-example/index.spec.ts +++ b/examples/javascript-generate-example/index.spec.ts @@ -7,8 +7,7 @@ describe('Should be able to generate ts data model with example function', () => }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/javascript-generate-example/index.ts b/examples/javascript-generate-example/index.ts index f9473cbac4..8e3a3b568a 100644 --- a/examples/javascript-generate-example/index.ts +++ b/examples/javascript-generate-example/index.ts @@ -29,4 +29,6 @@ export async function generate(): Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/javascript-generate-marshalling/index.spec.ts b/examples/javascript-generate-marshalling/index.spec.ts index f279d13040..4e1227ba5a 100644 --- a/examples/javascript-generate-marshalling/index.spec.ts +++ b/examples/javascript-generate-marshalling/index.spec.ts @@ -7,8 +7,7 @@ describe('Should be able to generate ts data model with marshal und unmarshal fu }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/javascript-generate-marshalling/index.ts b/examples/javascript-generate-marshalling/index.ts index dfdc5e2826..a6e5af0b23 100644 --- a/examples/javascript-generate-marshalling/index.ts +++ b/examples/javascript-generate-marshalling/index.ts @@ -30,4 +30,6 @@ export async function generate(): Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/javascript-use-cjs/__snapshots__/index.spec.ts.snap b/examples/javascript-use-cjs/__snapshots__/index.spec.ts.snap index 10f1cd67da..7ab7a1ff6b 100644 --- a/examples/javascript-use-cjs/__snapshots__/index.spec.ts.snap +++ b/examples/javascript-use-cjs/__snapshots__/index.spec.ts.snap @@ -19,23 +19,3 @@ class Person { module.exports = Person;", ] `; - -exports[`Should be able to render models to ESM module system and should log expected output to console 2`] = ` -Array [ - "const Person = require('./Person'); - -class Root { - person; - - constructor(input) { - if (input.hasOwnProperty('person')) { - this.person = input.person; - } - } - - get person() { return this.person; } - set person(person) { this.person = person; } -} -module.exports = Root;", -] -`; diff --git a/examples/javascript-use-cjs/index.spec.ts b/examples/javascript-use-cjs/index.spec.ts index 1bdece5160..b59976d2e0 100644 --- a/examples/javascript-use-cjs/index.spec.ts +++ b/examples/javascript-use-cjs/index.spec.ts @@ -7,9 +7,7 @@ describe('Should be able to render models to ESM module system', () => { }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 2 models, we double it - expect(spy.mock.calls.length).toEqual(4); + expect(spy.mock.calls.length).toEqual(2); expect(spy.mock.calls[1]).toMatchSnapshot(); - expect(spy.mock.calls[2]).toMatchSnapshot(); }); }); diff --git a/examples/javascript-use-cjs/index.ts b/examples/javascript-use-cjs/index.ts index e2225d5a71..fc65d9b167 100644 --- a/examples/javascript-use-cjs/index.ts +++ b/examples/javascript-use-cjs/index.ts @@ -32,4 +32,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/javascript-use-esm/__snapshots__/index.spec.ts.snap b/examples/javascript-use-esm/__snapshots__/index.spec.ts.snap index 4eca8f9fdd..d542161615 100644 --- a/examples/javascript-use-esm/__snapshots__/index.spec.ts.snap +++ b/examples/javascript-use-esm/__snapshots__/index.spec.ts.snap @@ -20,24 +20,3 @@ export default Person; ", ] `; - -exports[`Should be able to render models to ESM module system and should log expected output to console 2`] = ` -Array [ - "import Person from './Person'; - -class Root { - person; - - constructor(input) { - if (input.hasOwnProperty('person')) { - this.person = input.person; - } - } - - get person() { return this.person; } - set person(person) { this.person = person; } -} -export default Root; -", -] -`; diff --git a/examples/javascript-use-esm/index.spec.ts b/examples/javascript-use-esm/index.spec.ts index 1bdece5160..b59976d2e0 100644 --- a/examples/javascript-use-esm/index.spec.ts +++ b/examples/javascript-use-esm/index.spec.ts @@ -7,9 +7,7 @@ describe('Should be able to render models to ESM module system', () => { }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 2 models, we double it - expect(spy.mock.calls.length).toEqual(4); + expect(spy.mock.calls.length).toEqual(2); expect(spy.mock.calls[1]).toMatchSnapshot(); - expect(spy.mock.calls[2]).toMatchSnapshot(); }); }); diff --git a/examples/javascript-use-esm/index.ts b/examples/javascript-use-esm/index.ts index 77620962b6..67fd9b6421 100644 --- a/examples/javascript-use-esm/index.ts +++ b/examples/javascript-use-esm/index.ts @@ -32,4 +32,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/json-schema-draft7-from-object/index.spec.ts b/examples/json-schema-draft7-from-object/index.spec.ts index 96af1291c6..76ec14a659 100644 --- a/examples/json-schema-draft7-from-object/index.spec.ts +++ b/examples/json-schema-draft7-from-object/index.spec.ts @@ -7,8 +7,7 @@ describe('Should be able to process JSON Schema draft 7 object', () => { }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/json-schema-draft7-from-object/index.ts b/examples/json-schema-draft7-from-object/index.ts index f18220a373..4df638eb57 100644 --- a/examples/json-schema-draft7-from-object/index.ts +++ b/examples/json-schema-draft7-from-object/index.ts @@ -19,4 +19,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/meta-model/index.spec.ts b/examples/meta-model/index.spec.ts index baa18ca77f..43b94b2eb4 100644 --- a/examples/meta-model/index.spec.ts +++ b/examples/meta-model/index.spec.ts @@ -7,8 +7,7 @@ describe('Should be able to use generator with meta model', () => { }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/meta-model/index.ts b/examples/meta-model/index.ts index 4f9de644ac..cdd97f0103 100644 --- a/examples/meta-model/index.ts +++ b/examples/meta-model/index.ts @@ -15,4 +15,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/openapi-from-object/index.spec.ts b/examples/openapi-from-object/index.spec.ts index 771d530e6b..4f2f6e555f 100644 --- a/examples/openapi-from-object/index.spec.ts +++ b/examples/openapi-from-object/index.spec.ts @@ -6,9 +6,8 @@ describe('Should be able to process a pure OpenAPI object', () => { }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 2 models, we double it - expect(spy.mock.calls.length).toEqual(4); - expect(spy.mock.calls[2]).toMatchSnapshot(); - expect(spy.mock.calls[3]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(2); + expect(spy.mock.calls[0]).toMatchSnapshot(); + expect(spy.mock.calls[1]).toMatchSnapshot(); }); }); diff --git a/examples/openapi-from-object/index.ts b/examples/openapi-from-object/index.ts index 92a3c9db7d..ba89a24da0 100644 --- a/examples/openapi-from-object/index.ts +++ b/examples/openapi-from-object/index.ts @@ -59,4 +59,6 @@ export async function generate(): Promise { } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/overwrite-default-constraint/index.spec.ts b/examples/overwrite-default-constraint/index.spec.ts index a920b85c9d..a7483b15e2 100644 --- a/examples/overwrite-default-constraint/index.spec.ts +++ b/examples/overwrite-default-constraint/index.spec.ts @@ -7,8 +7,7 @@ describe('Should be able to render models with custom constrain logic', () => { }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/overwrite-default-constraint/index.ts b/examples/overwrite-default-constraint/index.ts index deaed75936..05a86b8399 100644 --- a/examples/overwrite-default-constraint/index.ts +++ b/examples/overwrite-default-constraint/index.ts @@ -27,4 +27,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/overwrite-naming-formatting/index.spec.ts b/examples/overwrite-naming-formatting/index.spec.ts index a547641ec9..0f54c447ac 100644 --- a/examples/overwrite-naming-formatting/index.spec.ts +++ b/examples/overwrite-naming-formatting/index.spec.ts @@ -7,8 +7,7 @@ describe('Should be able to render models with custom naming formatter', () => { }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/overwrite-naming-formatting/index.ts b/examples/overwrite-naming-formatting/index.ts index a156ac8ee9..0e7cb29be3 100644 --- a/examples/overwrite-naming-formatting/index.ts +++ b/examples/overwrite-naming-formatting/index.ts @@ -29,4 +29,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/rust-generate-crate/__snapshots__/index.spec.ts.snap b/examples/rust-generate-crate/__snapshots__/index.spec.ts.snap index 795357d5e3..a9bfbbdc9f 100644 --- a/examples/rust-generate-crate/__snapshots__/index.spec.ts.snap +++ b/examples/rust-generate-crate/__snapshots__/index.spec.ts.snap @@ -79,49 +79,3 @@ impl TupleType { ", ] `; - -exports[`Should be able to render Rust Models and should log expected output to console 4`] = ` -Array [ - "[package] -name = \\"asyncapi-rs-example\\" -version = \\"1.0.0\\" -authors = [\\"AsyncAPI Rust Champions\\"] -homepage = \\"https://www.asyncapi.com/tools/modelina\\" -repository = \\"https://github.com/asyncapi/modelina\\" -license = \\"Apache-2.0\\" -description = \\"Rust models generated by AsyncAPI Modelina\\" -edition = \\"2018\\" - -[dependencies] -serde = { version = \\"1\\", features = [\\"derive\\"] } -serde_json = { version=\\"1\\", optional = true } - -[dev-dependencies] - -[features] -default = [\\"json\\"] -json = [\\"dep:serde_json\\"]", -] -`; - -exports[`Should be able to render Rust Models and should log expected output to console 5`] = ` -Array [ - "#[macro_use] -extern crate serde; -extern crate serde_json; - -pub mod address; -pub use self::address::*; - -pub mod members; -pub use self::members::*; - -pub mod tuple_type; -pub use self::tuple_type::*; - -pub mod enum_type; -pub use self::enum_type::*;", -] -`; - -exports[`Should be able to render Rust Models and should log expected output to console 6`] = `undefined`; diff --git a/examples/rust-generate-crate/index.spec.ts b/examples/rust-generate-crate/index.spec.ts index cb19459294..0e50f1eaae 100644 --- a/examples/rust-generate-crate/index.spec.ts +++ b/examples/rust-generate-crate/index.spec.ts @@ -10,8 +10,5 @@ describe('Should be able to render Rust Models', () => { expect(spy.mock.calls[0]).toMatchSnapshot(); expect(spy.mock.calls[1]).toMatchSnapshot(); expect(spy.mock.calls[2]).toMatchSnapshot(); - expect(spy.mock.calls[4]).toMatchSnapshot(); - expect(spy.mock.calls[5]).toMatchSnapshot(); - expect(spy.mock.calls[6]).toMatchSnapshot(); }); }); diff --git a/examples/swagger2.0-from-object/index.spec.ts b/examples/swagger2.0-from-object/index.spec.ts index 285ddfb5b1..1e95110f22 100644 --- a/examples/swagger2.0-from-object/index.spec.ts +++ b/examples/swagger2.0-from-object/index.spec.ts @@ -6,9 +6,8 @@ describe('Should be able to process a pure Swagger 2.0 object', () => { }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 2 models, we double it - expect(spy.mock.calls.length).toEqual(4); - expect(spy.mock.calls[2]).toMatchSnapshot(); - expect(spy.mock.calls[3]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(2); + expect(spy.mock.calls[0]).toMatchSnapshot(); + expect(spy.mock.calls[1]).toMatchSnapshot(); }); }); diff --git a/examples/swagger2.0-from-object/index.ts b/examples/swagger2.0-from-object/index.ts index 41cb6a351c..e56175aad4 100644 --- a/examples/swagger2.0-from-object/index.ts +++ b/examples/swagger2.0-from-object/index.ts @@ -55,4 +55,6 @@ export async function generate(): Promise { } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/typescript-enum-type/index.spec.ts b/examples/typescript-enum-type/index.spec.ts index 050533c22b..949d84ef72 100644 --- a/examples/typescript-enum-type/index.spec.ts +++ b/examples/typescript-enum-type/index.spec.ts @@ -7,17 +7,10 @@ describe('Should be able to render correct enums based on options', () => { afterAll(() => { jest.restoreAllMocks(); }); - test('and should log expected output to console', async function testIt(): Promise { - // Wait for first call to the `generate` function is over, and we can reliably know the output - if (spy.mock.calls.length !== 6) { - await timeout(50); - return testIt(); - } - + test('and should log expected output to console', async (): Promise => { await generate(); - //Generate is called 2 times, so even though we expect 6 console logs we double it - expect(spy.mock.calls.length).toEqual(12); - const generatedContent = spy.mock.calls.slice(6).join('\n'); + expect(spy.mock.calls.length).toEqual(6); + const generatedContent = spy.mock.calls.join('\n'); expect(generatedContent).toMatchSnapshot(); }); }); diff --git a/examples/typescript-enum-type/index.ts b/examples/typescript-enum-type/index.ts index f2b989676e..c962be46fe 100644 --- a/examples/typescript-enum-type/index.ts +++ b/examples/typescript-enum-type/index.ts @@ -27,4 +27,6 @@ export async function generate(): Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/typescript-generate-comments/__snapshots__/index.spec.ts.snap b/examples/typescript-generate-comments/__snapshots__/index.spec.ts.snap index 620a07f8eb..92d0b34a78 100644 --- a/examples/typescript-generate-comments/__snapshots__/index.spec.ts.snap +++ b/examples/typescript-generate-comments/__snapshots__/index.spec.ts.snap @@ -27,33 +27,6 @@ interface Test { interface NestedTest { stringProp?: string; additionalProperties?: Map; -}", - ], - Array [ - "/** - * Main Description - */ -interface Test { - stringProp: string; - /** - * Description - * @example Example - */ - numberProp?: number; - /** - * @example Example 1, Example 2 - */ - objectProp?: NestedTest; - additionalProperties?: Map; -}", - ], - Array [ - "/** - * @example Example 1, Example 2 - */ -interface NestedTest { - stringProp?: string; - additionalProperties?: Map; }", ], ] diff --git a/examples/typescript-generate-comments/index.spec.ts b/examples/typescript-generate-comments/index.spec.ts index 5e8e211e47..70838e3881 100644 --- a/examples/typescript-generate-comments/index.spec.ts +++ b/examples/typescript-generate-comments/index.spec.ts @@ -7,7 +7,7 @@ describe('Should be able to generate ts data model with comments', () => { }); test('and should log expected output to console', async () => { await generate(); - expect(spy.mock.calls.length).toEqual(4); + expect(spy.mock.calls.length).toEqual(2); expect(spy.mock.calls).toMatchSnapshot(); }); }); diff --git a/examples/typescript-generate-comments/index.ts b/examples/typescript-generate-comments/index.ts index cf755d0e38..8948efe977 100644 --- a/examples/typescript-generate-comments/index.ts +++ b/examples/typescript-generate-comments/index.ts @@ -35,4 +35,6 @@ export async function generate(): Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/typescript-generate-example/index.spec.ts b/examples/typescript-generate-example/index.spec.ts index 53f18af361..ae9e1b9e39 100644 --- a/examples/typescript-generate-example/index.spec.ts +++ b/examples/typescript-generate-example/index.spec.ts @@ -7,8 +7,7 @@ describe('Should be able to generate ts data model with example function', () => }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/typescript-generate-example/index.ts b/examples/typescript-generate-example/index.ts index e2aaf6b18d..90c67cb9cd 100644 --- a/examples/typescript-generate-example/index.ts +++ b/examples/typescript-generate-example/index.ts @@ -29,4 +29,6 @@ export async function generate(): Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/typescript-generate-marshalling/index.spec.ts b/examples/typescript-generate-marshalling/index.spec.ts index 28b2ada9c0..88724b803f 100644 --- a/examples/typescript-generate-marshalling/index.spec.ts +++ b/examples/typescript-generate-marshalling/index.spec.ts @@ -7,8 +7,7 @@ describe('Should be able to generate ts data model with marshal und unmarshal fu }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/typescript-generate-marshalling/index.ts b/examples/typescript-generate-marshalling/index.ts index 0bd2e52675..7d17d08024 100644 --- a/examples/typescript-generate-marshalling/index.ts +++ b/examples/typescript-generate-marshalling/index.ts @@ -30,4 +30,6 @@ export async function generate(): Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/typescript-interface/index.spec.ts b/examples/typescript-interface/index.spec.ts index 75da2e1a1e..a92073f0ab 100644 --- a/examples/typescript-interface/index.spec.ts +++ b/examples/typescript-interface/index.spec.ts @@ -7,8 +7,7 @@ describe('Should be able to render typescript interface', () => { }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 1 model, we double it - expect(spy.mock.calls.length).toEqual(2); - expect(spy.mock.calls[1]).toMatchSnapshot(); + expect(spy.mock.calls.length).toEqual(1); + expect(spy.mock.calls[0]).toMatchSnapshot(); }); }); diff --git a/examples/typescript-interface/index.ts b/examples/typescript-interface/index.ts index 9497f17523..50576cd157 100644 --- a/examples/typescript-interface/index.ts +++ b/examples/typescript-interface/index.ts @@ -19,4 +19,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/typescript-use-cjs/__snapshots__/index.spec.ts.snap b/examples/typescript-use-cjs/__snapshots__/index.spec.ts.snap index 700591b314..9fe4e31ed3 100644 --- a/examples/typescript-use-cjs/__snapshots__/index.spec.ts.snap +++ b/examples/typescript-use-cjs/__snapshots__/index.spec.ts.snap @@ -18,22 +18,3 @@ class Person { module.exports = Person;", ] `; - -exports[`Should be able to render models to ESM module system and should log expected output to console 2`] = ` -Array [ - "const Person = require('./Person'); -class Root { - private _person?: Person; - - constructor(input: { - person?: Person, - }) { - this._person = input.person; - } - - get person(): Person | undefined { return this._person; } - set person(person: Person | undefined) { this._person = person; } -} -module.exports = Root;", -] -`; diff --git a/examples/typescript-use-cjs/index.spec.ts b/examples/typescript-use-cjs/index.spec.ts index 1bdece5160..b59976d2e0 100644 --- a/examples/typescript-use-cjs/index.spec.ts +++ b/examples/typescript-use-cjs/index.spec.ts @@ -7,9 +7,7 @@ describe('Should be able to render models to ESM module system', () => { }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 2 models, we double it - expect(spy.mock.calls.length).toEqual(4); + expect(spy.mock.calls.length).toEqual(2); expect(spy.mock.calls[1]).toMatchSnapshot(); - expect(spy.mock.calls[2]).toMatchSnapshot(); }); }); diff --git a/examples/typescript-use-cjs/index.ts b/examples/typescript-use-cjs/index.ts index ca9269308e..268d898363 100644 --- a/examples/typescript-use-cjs/index.ts +++ b/examples/typescript-use-cjs/index.ts @@ -32,4 +32,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +} diff --git a/examples/typescript-use-esm/__snapshots__/index.spec.ts.snap b/examples/typescript-use-esm/__snapshots__/index.spec.ts.snap index 33aaa27df4..a8f7734995 100644 --- a/examples/typescript-use-esm/__snapshots__/index.spec.ts.snap +++ b/examples/typescript-use-esm/__snapshots__/index.spec.ts.snap @@ -19,23 +19,3 @@ export default Person; ", ] `; - -exports[`Should be able to render models to ESM module system and should log expected output to console 2`] = ` -Array [ - "import Person from './Person'; -class Root { - private _person?: Person; - - constructor(input: { - person?: Person, - }) { - this._person = input.person; - } - - get person(): Person | undefined { return this._person; } - set person(person: Person | undefined) { this._person = person; } -} -export default Root; -", -] -`; diff --git a/examples/typescript-use-esm/index.spec.ts b/examples/typescript-use-esm/index.spec.ts index 1bdece5160..b59976d2e0 100644 --- a/examples/typescript-use-esm/index.spec.ts +++ b/examples/typescript-use-esm/index.spec.ts @@ -7,9 +7,7 @@ describe('Should be able to render models to ESM module system', () => { }); test('and should log expected output to console', async () => { await generate(); - //Generate is called 2x, so even though we expect 2 models, we double it - expect(spy.mock.calls.length).toEqual(4); + expect(spy.mock.calls.length).toEqual(2); expect(spy.mock.calls[1]).toMatchSnapshot(); - expect(spy.mock.calls[2]).toMatchSnapshot(); }); }); diff --git a/examples/typescript-use-esm/index.ts b/examples/typescript-use-esm/index.ts index 90d0447e51..5e9de0f504 100644 --- a/examples/typescript-use-esm/index.ts +++ b/examples/typescript-use-esm/index.ts @@ -32,4 +32,6 @@ export async function generate() : Promise { console.log(model.result); } } -generate(); +if (require.main === module) { + generate(); +}