-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add tests for metadata transformations with substitutions
- Loading branch information
1 parent
8275680
commit bee51f5
Showing
5 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
tests/integrations/services/__snapshots__/liquidInFrontMatter.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Front matter (metadata) transformations do not break when a property key contains Liquid-style variable substitutions 1`] = ` | ||
{ | ||
"(({{ key-name }}))": "This one's key employs a different whitespace style in a substitution.", | ||
"(({{key-name}}))": "This one's key only consists of a substitution.", | ||
"(({{key-name}}))-prop": "This one's key starts with a substitution.", | ||
"prop-(({{key-name}}))": "This one has a substitution in a key name.", | ||
} | ||
`; | ||
|
||
exports[`Front matter (metadata) transformations do not break when a property key contains Liquid-style variable substitutions 2`] = ` | ||
"--- | ||
prop-{{key-name}}: This one has a substitution in a key name. | ||
{{key-name}}-prop: This one's key starts with a substitution. | ||
{{key-name}}: This one's key only consists of a substitution. | ||
{{ key-name }}: This one's key employs a different whitespace style in a substitution. | ||
--- | ||
Blah. | ||
" | ||
`; | ||
|
||
exports[`Front matter (metadata) transformations do not break when a property value contains Liquid-style variable substitutions 1`] = ` | ||
{ | ||
"prop1": "This is a metadata property with a (({{substitution}})) in it.", | ||
"prop2": "This one contains (({{multiple}})) (({{substitutions}})).", | ||
"prop3": "This one has (({{substitutions}})) of (({{ different }})) (({{ styles}})).", | ||
"prop4": "This one has a (({{substitution}})) as well, but the string literal is single-quoted.", | ||
"prop5": "This one has no quotes at (({{all}})).", | ||
"prop6": "(({{this}})) starts with a substitution.", | ||
"prop7": "(({{this}})) one is a multiline (({{property}})).", | ||
} | ||
`; | ||
|
||
exports[`Front matter (metadata) transformations do not break when a property value contains Liquid-style variable substitutions 2`] = ` | ||
"--- | ||
prop1: This is a metadata property with a {{substitution}} in it. | ||
prop2: This one contains {{multiple}} {{substitutions}}. | ||
prop3: This one has {{substitutions}} of {{ different }} {{ styles}}. | ||
prop4: >- | ||
This one has a {{substitution}} as well, but the string literal is | ||
single-quoted. | ||
prop5: This one has no quotes at {{all}}. | ||
prop6: {{this}} starts with a substitution. | ||
prop7: {{this}} one is a multiline {{property}}. | ||
--- | ||
Blah. | ||
" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
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'; | ||
|
||
describe('Front matter (metadata) transformations', () => { | ||
it('do not break when a property value contains Liquid-style variable substitutions', async () => { | ||
const fileContent = await readFile(propValuesMockPath, {encoding: 'utf-8'}); | ||
|
||
const {metadata, metadataStrippedContent} = parseExistingMetadata(fileContent); | ||
const processedContent = emplaceMetadata(metadataStrippedContent, metadata); | ||
|
||
expect(metadata).toMatchSnapshot(); | ||
expect(processedContent).toMatchSnapshot(); | ||
}); | ||
|
||
it('do not break when a property key contains Liquid-style variable substitutions', async () => { | ||
const fileContent = await readFile(propKeysMockPath, {encoding: 'utf-8'}); | ||
|
||
const {metadata, metadataStrippedContent} = parseExistingMetadata(fileContent); | ||
const processedContent = emplaceMetadata(metadataStrippedContent, metadata); | ||
|
||
expect(metadata).toMatchSnapshot(); | ||
expect(processedContent).toMatchSnapshot(); | ||
}); | ||
}); |
7 changes: 7 additions & 0 deletions
7
tests/mocks/fileContent/metadata/substitutionsInMetadataPropertyKeys.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
prop-{{key-name}}: This one has a substitution in a key name. | ||
{{key-name}}-prop: This one's key starts with a substitution. | ||
{{key-name}}: This one's key only consists of a substitution. | ||
{{ key-name }}: This one's key employs a different whitespace style in a substitution. | ||
--- | ||
Blah. |
11 changes: 11 additions & 0 deletions
11
tests/mocks/fileContent/metadata/substitutionsInMetadataPropertyValues.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
prop1: "This is a metadata property with a {{substitution}} in it." | ||
prop2: "This one contains {{multiple}} {{substitutions}}." | ||
prop3: "This one has {{substitutions}} of {{ different }} {{ styles}}." | ||
prop4: 'This one has a {{substitution}} as well, but the string literal is single-quoted.' | ||
prop5: This one has no quotes at {{all}}. | ||
prop6: {{this}} starts with a substitution. | ||
prop7: >- | ||
{{this}} one is a multiline {{property}}. | ||
--- | ||
Blah. |