File size: 1,892 Bytes
c92aa92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import {fetchCsdnArticle} from "../engines/csdn/fetchCsdnArticle.js";

/**
 * Test suite for CSDN article fetching functionality
 */
async function testFetchCsdnArticle() {
  console.error('πŸ” Starting CSDN article fetch test...');

  try {
    const url = 'https://blog.csdn.net/weixin_45801664/article/details/149000138';

    console.error(`πŸ“ Fetching article from URL: ${url}`);

    const result = await fetchCsdnArticle(url);

    console.error(`πŸŽ‰ Article fetched successfully!`);
    console.error(`\nπŸ“„ Content preview (first 200 chars):`);
    console.error(`   ${result.content}`);
    console.error(`\nπŸ“Š Total content length: ${result.content.length} characters`);

    return result;
  } catch (error) {
    console.error('❌ Test failed:', error);
    if (error instanceof Error) {
      console.error(`   Error message: ${error.message}`);
    }
    return { content: '' };
  }
}

/**
 * Test with an invalid URL to verify error handling
 */
async function testInvalidUrl() {
  console.error('\nπŸ” Testing with invalid URL...');

  try {
    const invalidUrl = 'https://blog.csdn.net/invalid_path';

    console.error(`πŸ“ Attempting to fetch from invalid URL: ${invalidUrl}`);

    const result = await fetchCsdnArticle(invalidUrl);
    console.log(`πŸŽ‰ Result: ${result.content.substring(0, 100)}...`);

    return result;
  } catch (error) {
    console.error('❌ Test failed (expected for invalid URL):', error);
    if (error instanceof Error) {
      console.error(`   Error message: ${error.message}`);
    }
    return { content: '' };
  }
}

/**
 * Run all test cases in sequence
 */
async function runTests() {
  console.log('πŸ§ͺ Running tests for fetchCsdnArticle function\n');

  await testFetchCsdnArticle();
  // await testInvalidUrl();

  console.log('\nβœ… All tests completed');
}

// Execute the test suite
runTests().catch(console.error);