Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brotheroftux authored and 3y3 committed Sep 2, 2024
1 parent 5d9de26 commit 6a14ebe
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,13 @@ prop7: '{{this}} one is a multiline {{property}}.'
Blah.
"
`;

exports[`Front matter (metadata) transformations emit valid metadata when a variable is substituted with an ampty string 1`] = `
"---
prop1: ''
prop2: ''
prop3: ''
prop4: ''
---
"
`;
13 changes: 13 additions & 0 deletions tests/integrations/services/liquidInFrontMatter.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import liquid from '@diplodoc/transform/lib/liquid';
import {readFile} from 'fs/promises';
import {parseExistingMetadata} from 'services/metadata/parse';
import {emplaceMetadata} from 'services/metadata/utils';

const propValuesMockPath = 'mocks/fileContent/metadata/substitutionsInMetadataPropertyValues.md';
const propKeysMockPath = 'mocks/fileContent/metadata/substitutionsInMetadataPropertyKeys.md';
const emptyStringMockPath = 'mocks/fileContent/metadata/substitutionsWithEmptyString.md';

describe('Front matter (metadata) transformations', () => {
it('do not break when a property value contains Liquid-style variable substitutions', async () => {
Expand All @@ -25,4 +27,15 @@ describe('Front matter (metadata) transformations', () => {
expect(metadata).toMatchSnapshot();
expect(processedContent).toMatchSnapshot();
});

it('emit valid metadata when a variable is substituted with an ampty string', async () => {
const fileContent = await readFile(emptyStringMockPath, {encoding: 'utf-8'});

const {metadata, metadataStrippedContent} = parseExistingMetadata(fileContent);
const processedContent = emplaceMetadata(metadataStrippedContent, metadata);

const liquidProcessedInput = liquid(processedContent, {var: ''});

expect(liquidProcessedInput).toMatchSnapshot();
});
});
19 changes: 15 additions & 4 deletions tests/integrations/services/metadataAuthors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ describe('getContentWithUpdatedMetadata (Authors)', () => {
resolvedFrontMatterVars: {},
});

expect(updatedFileContent).toEqual(fileContent);
const {metadata: metadataBeforeEnrichment} = parseExistingMetadata(fileContent);
const {metadata: metadataAfterEnrichment} = parseExistingMetadata(updatedFileContent);

expect(metadataAfterEnrichment).toEqual(metadataBeforeEnrichment);
});

test(
Expand All @@ -136,7 +139,11 @@ describe('getContentWithUpdatedMetadata (Authors)', () => {
resolvedFrontMatterVars: {},
});

expect(updatedFileContent).toEqual(fileContent);
const {metadata: metadataBeforeEnrichment} = parseExistingMetadata(fileContent);
const {metadata: metadataAfterEnrichment} =
parseExistingMetadata(updatedFileContent);

expect(metadataAfterEnrichment).toEqual(metadataBeforeEnrichment);
},
);

Expand All @@ -158,7 +165,11 @@ describe('getContentWithUpdatedMetadata (Authors)', () => {
resolvedFrontMatterVars: {},
});

expect(updatedFileContent).toEqual(fileContent);
const {metadata: metadataBeforeEnrichment} = parseExistingMetadata(fileContent);
const {metadata: metadataAfterEnrichment} =
parseExistingMetadata(updatedFileContent);

expect(metadataAfterEnrichment).toEqual(metadataBeforeEnrichment);
},
);

Expand All @@ -172,7 +183,7 @@ describe('getContentWithUpdatedMetadata (Authors)', () => {
metadataOptions,
resolvedFrontMatterVars: {},
});

const {metadata: originalMeta} = parseExistingMetadata(fileContent);
const {metadata: updatedMeta} = parseExistingMetadata(updatedFileContent);

Expand Down
11 changes: 9 additions & 2 deletions tests/integrations/services/metadataContributors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,10 @@ describe('getContentWithUpdatedMetadata (Contributors)', () => {
resolvedFrontMatterVars: {},
});

expect(updatedFileContent).toEqual(fileContent);
const {metadata: metadataBeforeEnrichment} = parseExistingMetadata(fileContent);
const {metadata: metadataAfterEnrichment} = parseExistingMetadata(updatedFileContent);

expect(metadataAfterEnrichment).toEqual(metadataBeforeEnrichment);
});

test(
Expand All @@ -297,7 +300,11 @@ describe('getContentWithUpdatedMetadata (Contributors)', () => {
resolvedFrontMatterVars: {},
});

expect(updatedFileContent).toEqual(fileContent);
const {metadata: metadataBeforeEnrichment} = parseExistingMetadata(fileContent);
const {metadata: metadataAfterEnrichment} =
parseExistingMetadata(updatedFileContent);

expect(metadataAfterEnrichment).toEqual(metadataBeforeEnrichment);
},
);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
prop1: {{var}}
prop2: '{{var}}'
prop3: '{{var}}'
prop4: >-
{{var}}
---

0 comments on commit 6a14ebe

Please sign in to comment.