2025-01-23 14:35:06 +01:00
|
|
|
import { tap, expect } from '@push.rocks/tapbundle';
|
2016-11-13 23:11:49 +01:00
|
|
|
|
2025-01-23 14:35:06 +01:00
|
|
|
import * as smartfm from '../ts/index.js';
|
2016-11-13 23:11:49 +01:00
|
|
|
|
2018-08-27 02:01:18 +02:00
|
|
|
let testSmartfm = new smartfm.Smartfm({ fmType: 'yaml' });
|
2017-05-27 23:02:51 +02:00
|
|
|
tap.test('.parse()', async () => {
|
|
|
|
let testString = `---
|
2016-11-13 23:11:49 +01:00
|
|
|
testKey: testValue
|
|
|
|
testKey2: testValue2
|
|
|
|
---
|
2017-05-27 23:02:51 +02:00
|
|
|
# some markdown
|
2018-08-27 02:01:18 +02:00
|
|
|
`;
|
|
|
|
let parsedString = testSmartfm.parse(testString);
|
2025-01-23 14:35:06 +01:00
|
|
|
expect(parsedString.data).toHaveProperty('testKey', 'testValue');
|
|
|
|
expect(parsedString.data).toHaveProperty('testKey2', 'testValue2');
|
|
|
|
expect(parsedString.orig.toString()).toEqual(testString);
|
2018-08-27 02:01:18 +02:00
|
|
|
});
|
2019-09-04 14:13:42 +02:00
|
|
|
tap.test('should stringify data', async () => {
|
2018-08-27 02:01:18 +02:00
|
|
|
let testStringPure = `# some markdown heading\nsome first row`;
|
|
|
|
let testStringCombined = testSmartfm.stringify(testStringPure, { testData: 'hi' });
|
|
|
|
let resultString = '---\ntestData: hi\n---\n# some markdown heading\nsome first row\n';
|
2025-01-23 14:35:06 +01:00
|
|
|
expect(resultString).toEqual(testStringCombined);
|
2018-08-27 02:01:18 +02:00
|
|
|
});
|
2017-05-27 23:02:51 +02:00
|
|
|
|
2019-09-04 14:13:42 +02:00
|
|
|
tap.test('should parse a normal frontmatter file', async () => {
|
2019-09-04 15:45:18 +02:00
|
|
|
const normalFile = `---
|
|
|
|
heythere: awesome
|
|
|
|
---
|
|
|
|
really
|
|
|
|
`;
|
|
|
|
let result = testSmartfm.parse(normalFile);
|
2025-01-23 14:35:06 +01:00
|
|
|
expect(result.data.heythere).toEqual('awesome');
|
2019-09-04 15:45:18 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
tap.test('should parse a commented out frontmatter file', async () => {
|
|
|
|
const commentedFile = `# ---
|
|
|
|
# heythere: awesome
|
|
|
|
# ---
|
|
|
|
really
|
|
|
|
`;
|
|
|
|
let result = testSmartfm.parseFromComments('# ', commentedFile);
|
|
|
|
console.log(result);
|
2019-09-04 14:13:42 +02:00
|
|
|
});
|
|
|
|
|
2018-08-27 02:01:18 +02:00
|
|
|
tap.start();
|