Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Do not use a .ts extension for snapshot #2797

Merged
merged 6 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ describe('BackbonePlugin', () => {
expect(files.length).to.equal(4);

const [endpointFile, grandParentModelEntityFile, modelEntityFile, parentModelEntityFile] = files;
await expect(await endpointFile.text()).toMatchSnapshot(`${sectionName}Endpoint`, import.meta.url);
await expect(await modelEntityFile.text()).toMatchSnapshot('Model.entity', import.meta.url);
await expect(await parentModelEntityFile.text()).toMatchSnapshot('ParentModel.entity', import.meta.url);
await expect(await grandParentModelEntityFile.text()).toMatchSnapshot('GrandParentModel.entity', import.meta.url);
await expect(await endpointFile.text()).toMatchSnapshot(`${sectionName}Endpoint.snap.ts`, import.meta.url);
await expect(await modelEntityFile.text()).toMatchSnapshot('Model.entity.snap.ts', import.meta.url);
await expect(await parentModelEntityFile.text()).toMatchSnapshot('ParentModel.entity.snap.ts', import.meta.url);
await expect(await grandParentModelEntityFile.text()).toMatchSnapshot(
'GrandParentModel.entity.snap.ts',
import.meta.url,
);
expect(endpointFile.name).to.equal(`${sectionName}Endpoint.ts`);
expect(modelEntityFile.name).to.equal(`${modelSectionPath}/ComplexHierarchyModel.ts`);
expect(parentModelEntityFile.name).to.equal(`${modelSectionPath}/ComplexHierarchyParentModel.ts`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ describe('BackbonePlugin', () => {
expect(files.length).to.equal(2);

const [endpointFile, enumEntity] = files;
await expect(await endpointFile.text()).toMatchSnapshot(`${sectionName}Endpoint`, import.meta.url);
await expect(await enumEntity.text()).toMatchSnapshot('ComplexTypeModel.entity', import.meta.url);
await expect(await endpointFile.text()).toMatchSnapshot(`${sectionName}Endpoint.snap.ts`, import.meta.url);
await expect(await enumEntity.text()).toMatchSnapshot('ComplexTypeModel.entity.snap.ts', import.meta.url);
expect(endpointFile.name).to.equal(`${sectionName}Endpoint.ts`);
expect(enumEntity.name).to.equal(`${modelSectionPath}/ComplexTypeModel.ts`);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('BackbonePlugin', () => {
expect(files.length).to.equal(1);

const [endpointFile] = files;
await expect(await endpointFile.text()).toMatchSnapshot(`${sectionName}Endpoint`, import.meta.url);
await expect(await endpointFile.text()).toMatchSnapshot(`${sectionName}Endpoint.snap.ts`, import.meta.url);
expect(endpointFile.name).to.equal(`${sectionName}Endpoint.ts`);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ describe('BackbonePlugin', () => {
expect(files.length).to.equal(2);

const [endpointFile, enumEntity] = files;
await expect(await endpointFile.text()).toMatchSnapshot(`${sectionName}Endpoint`, import.meta.url);
await expect(await enumEntity.text()).toMatchSnapshot('EnumEntity.entity', import.meta.url);
await expect(await endpointFile.text()).toMatchSnapshot(`${sectionName}Endpoint.snap.ts`, import.meta.url);
await expect(await enumEntity.text()).toMatchSnapshot('EnumEntity.entity.snap.ts', import.meta.url);
expect(endpointFile.name).to.equal(`${sectionName}Endpoint.ts`);
expect(enumEntity.name).to.equal(`${modelSectionPath}/EnumEntity.ts`);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ describe('BackbonePlugin', () => {
expect(files.length).to.equal(2);

const [endpointFile, entity] = files;
await expect(await entity.text()).toMatchSnapshot('GenericTypesEntity', import.meta.url);
await expect(await endpointFile.text()).toMatchSnapshot(`${sectionName}Endpoint`, import.meta.url);
await expect(await entity.text()).toMatchSnapshot('GenericTypesEntity.snap.ts', import.meta.url);
await expect(await endpointFile.text()).toMatchSnapshot(`${sectionName}Endpoint.snap.ts`, import.meta.url);
expect(entity.name).to.equal(`${modelSectionPath}/GenericTypesEntity.ts`);
expect(endpointFile.name).to.equal(`${sectionName}Endpoint.ts`);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ describe('BackbonePlugin', () => {
expect(files.length).to.equal(3);

const [endpointFile, entity] = files;
await expect(await endpointFile.text()).toMatchSnapshot(`${sectionName}Endpoint`, import.meta.url);
await expect(await entity.text()).toMatchSnapshot('HierarchyRef.entity', import.meta.url);
await expect(await endpointFile.text()).toMatchSnapshot(`${sectionName}Endpoint.snap.ts`, import.meta.url);
await expect(await entity.text()).toMatchSnapshot('HierarchyRef.entity.snap.ts', import.meta.url);
expect(endpointFile.name).to.equal(`${sectionName}Endpoint.ts`);
expect(entity.name).to.equal(`${modelSectionPath}/HierarchyRef.ts`);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('BackbonePlugin', () => {
expect(files.length).to.equal(1);

const [endpointFile] = files;
await expect(await endpointFile.text()).toMatchSnapshot(`${sectionName}Endpoint`, import.meta.url);
await expect(await endpointFile.text()).toMatchSnapshot(`${sectionName}Endpoint.snap.ts`, import.meta.url);
expect(endpointFile.name).to.equal(`${sectionName}Endpoint.ts`);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ describe('BackbonePlugin', () => {

const [endpointFile, entity1, entity2] = files;

await expect(await endpointFile.text()).toMatchSnapshot(`${sectionName}Endpoint`, import.meta.url);
await expect(await endpointFile.text()).toMatchSnapshot(`${sectionName}Endpoint.snap.ts`, import.meta.url);
expect(endpointFile.name).to.equal(`${sectionName}Endpoint.ts`);

await expect(await entity1.text()).toMatchSnapshot(`ExampleEntity`, import.meta.url);
await expect(await entity1.text()).toMatchSnapshot(`ExampleEntity.snap.ts`, import.meta.url);
expect(entity1.name).to.equal(`com/example/application/entities/ExampleEntity.ts`);

await expect(await entity2.text()).toMatchSnapshot(`CoreEntity`, import.meta.url);
await expect(await entity2.text()).toMatchSnapshot(`CoreEntity.snap.ts`, import.meta.url);
expect(entity2.name).to.equal(`com/example/application/entities/CoreEntity.ts`);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('BackbonePlugin', () => {
expect(files.length).to.equal(1);

const [endpointFile] = files;
await expect(await endpointFile.text()).toMatchSnapshot(`${sectionName}Endpoint`, import.meta.url);
await expect(await endpointFile.text()).toMatchSnapshot(`${sectionName}Endpoint.snap.ts`, import.meta.url);
expect(endpointFile.name).to.equal(`${sectionName}Endpoint.ts`);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('BarrelPlugin', () => {

const barrelFile = files[files.length - 1];

await expect(await barrelFile.text()).toMatchSnapshot(`barrel`, import.meta.url);
await expect(await barrelFile.text()).toMatchSnapshot(`barrel.snap.ts`, import.meta.url);
expect(barrelFile.name).to.equal(`endpoints.ts`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('ClientPlugin', () => {

const [clientFile] = files;

await expect(await clientFile.text()).toMatchSnapshot(`client`, import.meta.url);
await expect(await clientFile.text()).toMatchSnapshot(`client.snap.ts`, import.meta.url);
expect(clientFile.name).to.equal(`connect-client.default.ts`);
});
});
5 changes: 4 additions & 1 deletion packages/ts/generator-plugin-model/test/model/Model.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ describe('FormPlugin', () => {
const fileName = `com/example/application/endpoints/TsFormEndpoint/${modelName}.ts`;
const modelFile = filesByName[fileName];
expect(modelFile, `${fileName} file`).to.not.be.undefined;
await expect(await modelFile.text(), `${fileName} file`).toMatchSnapshot(modelName, import.meta.url);
await expect(await modelFile.text(), `${fileName} file`).toMatchSnapshot(
`${modelName}.snap.ts`,
import.meta.url,
);
}),
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('PushPlugin', () => {

const endpointFile = files.find((f) => f.name === 'PushTypeEndpoint.ts')!;
expect(endpointFile).to.exist;
await expect(await endpointFile.text()).toMatchSnapshot(`${sectionName}Endpoint`, import.meta.url);
await expect(await endpointFile.text()).toMatchSnapshot(`${sectionName}Endpoint.snap.ts`, import.meta.url);
expect(endpointFile.name).to.equal(`${sectionName}Endpoint.ts`);
});

Expand All @@ -39,7 +39,7 @@ describe('PushPlugin', () => {

const endpointFile = files.find((f) => f.name === 'PushTypeOnlyEndpoint.ts')!;
expect(endpointFile).to.exist;
await expect(await endpointFile.text()).toMatchSnapshot(`${sectionName}Endpoint`, import.meta.url);
await expect(await endpointFile.text()).toMatchSnapshot(`${sectionName}Endpoint.snap.ts`, import.meta.url);
expect(endpointFile.name).to.equal(`${sectionName}Endpoint.ts`);
});
});
Expand Down
24 changes: 18 additions & 6 deletions packages/ts/generator-plugin-signals/test/SignalsEndpoints.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ describe('SignalsPlugin', () => {

const generatedNumberSignalService = files.find((f) => f.name === 'NumberSignalService.ts')!;
await expect(await generatedNumberSignalService.text()).toMatchSnapshot(
`NumberSignalServiceMix`,
`NumberSignalServiceMix.snap.ts`,
import.meta.url,
);

// Non-signal returning services should remain unchanged as before:
const generatedHelloWorldService = files.find((f) => f.name === 'HelloWorldService.ts')!;
await expect(await generatedHelloWorldService.text()).toMatchSnapshot(`HelloWorldService`, import.meta.url);
await expect(await generatedHelloWorldService.text()).toMatchSnapshot(
`HelloWorldService.snap.ts`,
import.meta.url,
);
});

it('removes unused request init import', async () => {
Expand All @@ -40,13 +43,16 @@ describe('SignalsPlugin', () => {
// Signal-only returning services should have the init import removed:
const generatedNumberSignalService = files.find((f) => f.name === 'NumberSignalService.ts')!;
await expect(await generatedNumberSignalService.text()).toMatchSnapshot(
`NumberSignalServiceSignalOnly`,
`NumberSignalServiceSignalOnly.snap.ts`,
import.meta.url,
);

// Non-signal returning services should remain unchanged as before:
const generatedHelloWorldService = files.find((f) => f.name === 'HelloWorldService.ts')!;
await expect(await generatedHelloWorldService.text()).toMatchSnapshot(`HelloWorldService`, import.meta.url);
await expect(await generatedHelloWorldService.text()).toMatchSnapshot(
`HelloWorldService.snap.ts`,
import.meta.url,
);
});

it('correctly generates service with mixture of normal and ValueSignal returning methods', async () => {
Expand All @@ -57,11 +63,17 @@ describe('SignalsPlugin', () => {
const files = await generator.process(input);

const generatedValueSignalService = files.find((f) => f.name === 'PersonService.ts')!;
await expect(await generatedValueSignalService.text()).toMatchSnapshot(`ValueSignalServiceMix`, import.meta.url);
await expect(await generatedValueSignalService.text()).toMatchSnapshot(
`ValueSignalServiceMix.snap.ts`,
import.meta.url,
);

// Non-signal returning services should remain unchanged as before:
const generatedHelloWorldService = files.find((f) => f.name === 'HelloWorldService.ts')!;
await expect(await generatedHelloWorldService.text()).toMatchSnapshot(`HelloWorldService`, import.meta.url);
await expect(await generatedHelloWorldService.text()).toMatchSnapshot(
`HelloWorldService.snap.ts`,
import.meta.url,
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@ describe('SubTypesPlugin', () => {

const endpointFile = files.find((f) => f.name === 'SubTypesEndpoint.ts')!;
expect(endpointFile).to.exist;
await expect(await endpointFile.text()).toMatchSnapshot(`${sectionName}Endpoint`, import.meta.url);
await expect(await endpointFile.text()).toMatchSnapshot(`${sectionName}Endpoint.snap.ts`, import.meta.url);
expect(endpointFile.name).to.equal(`${sectionName}Endpoint.ts`);

const baseEventUnionFile = files.find(
(f) => f.name === 'com/vaadin/hilla/parser/plugins/subtypes/BaseEventUnion.ts',
)!;
expect(baseEventUnionFile).to.exist;
await expect(await baseEventUnionFile.text()).toMatchSnapshot('BaseEventUnion', import.meta.url);
await expect(await baseEventUnionFile.text()).toMatchSnapshot('BaseEventUnion.snap.ts', import.meta.url);
expect(baseEventUnionFile.name).to.equal('com/vaadin/hilla/parser/plugins/subtypes/BaseEventUnion.ts');

const baseEventFile = files.find((f) => f.name === 'com/vaadin/hilla/parser/plugins/subtypes/BaseEvent.ts')!;
expect(baseEventFile).to.exist;
await expect(await baseEventFile.text()).toMatchSnapshot('BaseEvent', import.meta.url);
await expect(await baseEventFile.text()).toMatchSnapshot('BaseEvent.snap.ts', import.meta.url);
expect(baseEventFile.name).to.equal('com/vaadin/hilla/parser/plugins/subtypes/BaseEvent.ts');

const addEventFile = files.find((f) => f.name === 'com/vaadin/hilla/parser/plugins/subtypes/AddEvent.ts')!;
expect(addEventFile).to.exist;
await expect(await addEventFile.text()).toMatchSnapshot('AddEvent', import.meta.url);
await expect(await addEventFile.text()).toMatchSnapshot('AddEvent.snap.ts', import.meta.url);
expect(addEventFile.name).to.equal('com/vaadin/hilla/parser/plugins/subtypes/AddEvent.ts');

const addEventModelFile = files.find(
(f) => f.name === 'com/vaadin/hilla/parser/plugins/subtypes/AddEventModel.ts',
)!;
expect(addEventModelFile).to.exist;
await expect(await addEventModelFile.text()).toMatchSnapshot('AddEventModel', import.meta.url);
await expect(await addEventModelFile.text()).toMatchSnapshot('AddEventModel.snap.ts', import.meta.url);
expect(addEventModelFile.name).to.equal('com/vaadin/hilla/parser/plugins/subtypes/AddEventModel.ts');
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/ts/generator-utils/src/testing/snapshotMatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function snapshotMatcher(chai: Chai.ChaiStatic, utils: Chai.ChaiU
// eslint-disable-next-line prefer-arrow-callback
async function toMatchSnapshot(this: object, snapshotName: string, importMetaUrl: string): Promise<void> {
const obj = utils.flag(this, 'object');
const snapshotURL = new URL(`./fixtures/${snapshotName}.snap.ts`, importMetaUrl);
const snapshotURL = new URL(`./fixtures/${snapshotName}`, importMetaUrl);
const snapshotPath = fileURLToPath(snapshotURL);

if (shouldUpdate) {
Expand Down
2 changes: 1 addition & 1 deletion packages/ts/generator-utils/test/ImportManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('ImportManager', () => {
const file = createSourceFile(code, 'foo.ts');
const printer = ts.createPrinter();

await expect(printer.printFile(file)).toMatchSnapshot('ImportManager', import.meta.url);
await expect(printer.printFile(file)).toMatchSnapshot('ImportManager.snap', import.meta.url);
});

it('should extract imports from a code', () => {
Expand Down