1
+ 'use strict'
2
+
3
+ const assert = require ( 'assert' )
4
+ const fs = require ( 'fs' )
5
+ const path = require ( 'path' )
6
+
7
+ // Test the PDF generation functionality
8
+ // This test mocks dependencies to verify the logic without requiring full installation
9
+
10
+ describe ( 'PDF Generation Tests' , function ( ) {
11
+ const testMarkdown = `# Test Document
12
+
13
+ This is a **test** document with some content.
14
+
15
+ ## Code Block
16
+ \`\`\`javascript
17
+ console.log('Hello World');
18
+ \`\`\`
19
+
20
+ - List item 1
21
+ - List item 2
22
+ `
23
+
24
+ it ( 'should have the markdown-to-pdf utility' , function ( ) {
25
+ const filePath = path . join ( __dirname , '../lib/utils/markdown-to-pdf.js' )
26
+ assert ( fs . existsSync ( filePath ) , 'markdown-to-pdf.js should exist' )
27
+ } )
28
+
29
+ it ( 'should have updated actionPDF function' , function ( ) {
30
+ const filePath = path . join ( __dirname , '../lib/note/noteActions.js' )
31
+ const content = fs . readFileSync ( filePath , 'utf8' )
32
+
33
+ // Should not contain markdown-pdf references
34
+ assert ( ! content . includes ( "require('markdown-pdf')" ) , 'Should not import markdown-pdf' )
35
+ assert ( ! content . includes ( 'markdownpdf(' ) , 'Should not use markdownpdf function' )
36
+
37
+ // Should contain puppeteer-based implementation
38
+ assert ( content . includes ( 'convertMarkdownToPDF' ) , 'Should use convertMarkdownToPDF' )
39
+ assert ( content . includes ( 'async function actionPDF' ) , 'actionPDF should be async' )
40
+ assert ( content . includes ( 'await convertMarkdownToPDF' ) , 'Should await PDF conversion' )
41
+ } )
42
+
43
+ it ( 'should export convertMarkdownToPDF function' , function ( ) {
44
+ const filePath = path . join ( __dirname , '../lib/utils/markdown-to-pdf.js' )
45
+ const content = fs . readFileSync ( filePath , 'utf8' )
46
+
47
+ assert ( content . includes ( 'convertMarkdownToPDF' ) , 'Should define convertMarkdownToPDF function' )
48
+ assert ( content . includes ( 'module.exports' ) , 'Should export the function' )
49
+ assert ( content . includes ( 'puppeteer' ) , 'Should use puppeteer' )
50
+ assert ( content . includes ( 'markdownit' ) , 'Should use markdown-it' )
51
+ } )
52
+
53
+ it ( 'should have puppeteer in package.json dependencies' , function ( ) {
54
+ const packagePath = path . join ( __dirname , '../package.json' )
55
+ const packageJson = JSON . parse ( fs . readFileSync ( packagePath , 'utf8' ) )
56
+
57
+ assert ( packageJson . dependencies . puppeteer , 'puppeteer should be in dependencies' )
58
+ assert ( ! packageJson . dependencies [ 'markdown-pdf' ] , 'markdown-pdf should be removed' )
59
+ } )
60
+ } )
61
+
62
+ // If running this file directly, run a simple test
63
+ if ( require . main === module ) {
64
+ console . log ( 'Running PDF generation tests...' )
65
+
66
+ try {
67
+ const testDir = path . dirname ( __filename )
68
+
69
+ // Test 1: Check files exist
70
+ const markdownToPdfPath = path . join ( testDir , '../lib/utils/markdown-to-pdf.js' )
71
+ const noteActionsPath = path . join ( testDir , '../lib/note/noteActions.js' )
72
+
73
+ console . log ( '✅ Checking file existence...' )
74
+ assert ( fs . existsSync ( markdownToPdfPath ) , 'markdown-to-pdf.js should exist' )
75
+ assert ( fs . existsSync ( noteActionsPath ) , 'noteActions.js should exist' )
76
+
77
+ // Test 2: Check content
78
+ console . log ( '✅ Checking file content...' )
79
+ const noteActionsContent = fs . readFileSync ( noteActionsPath , 'utf8' )
80
+ assert ( noteActionsContent . includes ( 'convertMarkdownToPDF' ) , 'Should use convertMarkdownToPDF' )
81
+ assert ( ! noteActionsContent . includes ( "require('markdown-pdf')" ) , 'Should not import markdown-pdf' )
82
+
83
+ const markdownToPdfContent = fs . readFileSync ( markdownToPdfPath , 'utf8' )
84
+ assert ( markdownToPdfContent . includes ( 'puppeteer' ) , 'Should use puppeteer' )
85
+ assert ( markdownToPdfContent . includes ( 'module.exports' ) , 'Should export functions' )
86
+
87
+ // Test 3: Check package.json
88
+ console . log ( '✅ Checking package.json...' )
89
+ const packagePath = path . join ( testDir , '../package.json' )
90
+ const packageJson = JSON . parse ( fs . readFileSync ( packagePath , 'utf8' ) )
91
+ assert ( packageJson . dependencies . puppeteer , 'puppeteer should be in dependencies' )
92
+ assert ( ! packageJson . dependencies [ 'markdown-pdf' ] , 'markdown-pdf should be removed' )
93
+
94
+ console . log ( '✅ All tests passed!' )
95
+
96
+ } catch ( error ) {
97
+ console . error ( '❌ Test failed:' , error . message )
98
+ process . exit ( 1 )
99
+ }
100
+ }
0 commit comments