metalsmith-markdown-partials 2.4.0 → 2.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/test/cjs.test.cjs DELETED
@@ -1,55 +0,0 @@
1
- // Minimal CommonJS test file - just verifies the CJS module works
2
- const assert = require('node:assert').strict;
3
- const path = require('node:path');
4
- const fs = require('node:fs');
5
- const metalsmith = require('metalsmith');
6
-
7
- // Import the plugin using the CommonJS format
8
- const plugin = require('../lib/index.cjs');
9
-
10
- describe('metalsmith-markdown-partials (CommonJS)', () => {
11
- // Verify the module loads correctly and exports a function
12
- it('should be properly importable as a CommonJS module', () => {
13
- assert.strictEqual(typeof plugin, 'function', 'Plugin should be a function when required with CommonJS');
14
- assert.strictEqual(typeof plugin(), 'function', 'Plugin should return a function when called');
15
- });
16
-
17
- // Add a basic functionality test to verify the plugin works
18
- it('should process markdown partials correctly', (done) => {
19
- const fixturesDir = path.join(__dirname, 'fixtures');
20
-
21
- const instance = plugin({
22
- libraryPath: path.join(fixturesDir, '/src/md-partials/'),
23
- fileSuffix: '.md',
24
- });
25
-
26
- // Create a fake metalsmith instance
27
- const metalsmithInstance = metalsmith(fixturesDir);
28
-
29
- // Load a test file
30
- const markdownContent = fs.readFileSync(path.join(fixturesDir, 'src/markdown.md'), 'utf8');
31
- const partialContent = fs.readFileSync(path.join(fixturesDir, 'src/md-partials/test-partial.md'), 'utf8');
32
- const expectedContent = fs.readFileSync(path.join(fixturesDir, 'expected/final-markdown.md'), 'utf8');
33
-
34
- // Setup files object
35
- const files = {
36
- 'markdown.md': {
37
- contents: Buffer.from(markdownContent)
38
- },
39
- 'md-partials/test-partial.md': {
40
- contents: Buffer.from(partialContent)
41
- }
42
- };
43
-
44
- // Run the plugin
45
- instance(files, metalsmithInstance, (err) => {
46
- assert.strictEqual(err, undefined, 'No error should occur');
47
- assert.strictEqual(
48
- files['markdown.md'].contents.toString().trim(),
49
- expectedContent.trim(),
50
- 'Content should be properly processed'
51
- );
52
- done();
53
- });
54
- });
55
- });
@@ -1,11 +0,0 @@
1
- # Markdown page... testing markdown partials plugin
2
-
3
- Nullam quis risus eget urna mollis ornare vel eu leo. Curabitur blandit tempus porttitor. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Donec sed odio dui.
4
-
5
- ## Test partial title
6
-
7
- Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Sed posuere consectetur est at lobortis. Maecenas faucibus mollis interdum. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.
8
-
9
- Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla vitae elit libero, a pharetra augue. Maecenas faucibus mollis interdum. Maecenas faucibus mollis interdum. Sed posuere consectetur est at lobortis.
10
-
11
- Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Aenean lacinia bibendum nulla sed consectetur.
@@ -1,11 +0,0 @@
1
- # Markdown page... testing markdown partials plugin
2
-
3
- Nullam quis risus eget urna mollis ornare vel eu leo. Curabitur blandit tempus porttitor. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Donec sed odio dui.
4
-
5
- ## Test partial title
6
-
7
- Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Sed posuere consectetur est at lobortis. Maecenas faucibus mollis interdum. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.
8
-
9
- Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla vitae elit libero, a pharetra augue. Maecenas faucibus mollis interdum. Maecenas faucibus mollis interdum. Sed posuere consectetur est at lobortis.
10
-
11
- Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Aenean lacinia bibendum nulla sed consectetur.
@@ -1,9 +0,0 @@
1
- # Markdown page... testing markdown partials plugin
2
-
3
- Nullam quis risus eget urna mollis ornare vel eu leo. Curabitur blandit tempus porttitor. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Donec sed odio dui.
4
-
5
- {#md "test-partial.md" #}
6
-
7
- Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla vitae elit libero, a pharetra augue. Maecenas faucibus mollis interdum. Maecenas faucibus mollis interdum. Sed posuere consectetur est at lobortis.
8
-
9
- Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Aenean lacinia bibendum nulla sed consectetur.
@@ -1,3 +0,0 @@
1
- ## Test partial title
2
-
3
- Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Sed posuere consectetur est at lobortis. Maecenas faucibus mollis interdum. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.
package/test/index.js DELETED
@@ -1,139 +0,0 @@
1
- // ESM test file for Metalsmith plugins
2
- import { strict as assert } from 'node:assert';
3
- import { fileURLToPath } from 'node:url';
4
- import { dirname, resolve, join } from 'node:path';
5
- import { readFileSync } from 'node:fs';
6
- import metalsmith from 'metalsmith';
7
-
8
- // Import the plugin directly from src for accurate coverage
9
- import plugin from '../src/index.js';
10
-
11
- // Get current directory and setup path utilities
12
- const __dirname = dirname(fileURLToPath(import.meta.url));
13
- const fixture = resolve.bind(resolve, __dirname, 'fixtures');
14
-
15
- function file(_path) {
16
- return readFileSync(fixture(_path), 'utf8');
17
- }
18
-
19
- describe('metalsmith-markdown-partials (ESM)', () => {
20
- // Verify ESM module loading
21
- it('should be importable as an ES module', () => {
22
- assert.strictEqual(typeof plugin, 'function', 'Plugin should be a function when imported with ESM');
23
- assert.strictEqual(typeof plugin(), 'function', 'Plugin should return a function when called');
24
- });
25
-
26
- it('should replace marker with markdown partial', (done) => {
27
- metalsmith(fixture())
28
- .use(
29
- plugin({
30
- libraryPath: join(fixture(), `/src/md-partials/`),
31
- fileSuffix: '.md'
32
- })
33
- )
34
- .build((err) => {
35
- if (err) {
36
- return done(err);
37
- }
38
- assert.strictEqual(
39
- file('build/markdown.md').trim(),
40
- file('expected/final-markdown.md').trim(),
41
- 'Content should match expected output'
42
- );
43
- done();
44
- });
45
- });
46
-
47
- it('should use metalsmith debug when available', (done) => {
48
- // Create a mock debug function that records calls
49
- const debugCalls = [];
50
- const mockMetalsmith = {
51
- debug:
52
- () =>
53
- (...args) => {
54
- debugCalls.push(args);
55
- return true;
56
- }
57
- };
58
-
59
- // Create test files
60
- const files = {
61
- 'test.md': {
62
- contents: Buffer.from('Test content {#md "partial.md" #} more content')
63
- },
64
- 'md-partials/partial.md': {
65
- contents: Buffer.from('Partial content')
66
- }
67
- };
68
-
69
- // Create and call the plugin
70
- const pluginInstance = plugin({
71
- libraryPath: './md-partials/',
72
- fileSuffix: '.md'
73
- });
74
-
75
- pluginInstance(files, mockMetalsmith, () => {
76
- assert(debugCalls.length > 0, 'Debug function should have been called');
77
- assert(debugCalls[0][0].includes('options'), 'Should include options message');
78
- done();
79
- });
80
- });
81
-
82
- it('should handle missing debug method gracefully', (done) => {
83
- // Create a metalsmith mock without debug method
84
- const mockMetalsmith = {};
85
-
86
- // Create test files
87
- const files = {
88
- 'test.md': {
89
- contents: Buffer.from('Test content {#md "partial.md" #} more content')
90
- },
91
- 'md-partials/partial.md': {
92
- contents: Buffer.from('Partial content')
93
- }
94
- };
95
-
96
- // Should not throw error when debug is missing
97
- const pluginInstance = plugin({
98
- libraryPath: './md-partials/',
99
- fileSuffix: '.md'
100
- });
101
-
102
- pluginInstance(files, mockMetalsmith, (err) => {
103
- assert.strictEqual(err, undefined, 'No error should occur when debug is missing');
104
- done();
105
- });
106
- });
107
-
108
- it('should handle files without markers correctly', (done) => {
109
- // Create a metalsmith mock
110
- const mockMetalsmith = {};
111
-
112
- // Create test files
113
- const files = {
114
- 'test.md': {
115
- contents: Buffer.from('Test content without any markers')
116
- },
117
- 'md-partials/partial.md': {
118
- contents: Buffer.from('Partial content')
119
- }
120
- };
121
-
122
- // Should not throw error when no markers are found
123
- const pluginInstance = plugin({
124
- libraryPath: './md-partials/',
125
- fileSuffix: '.md'
126
- });
127
-
128
- pluginInstance(files, mockMetalsmith, (err) => {
129
- assert.strictEqual(err, undefined, 'No error should occur when no markers are present');
130
- // Content should remain unchanged
131
- assert.strictEqual(
132
- files['test.md'].contents.toString(),
133
- 'Test content without any markers',
134
- 'Content should remain unchanged'
135
- );
136
- done();
137
- });
138
- });
139
- });