Files
Meting/test/test.js
METO 041d6b56df refactor: 重构为 nodejs 语言 (#118)
* feat: migrate from PHP to Node.js implementation

- Replace PHP implementation with Node.js version
- Add Node.js package configuration (package.json, package-lock.json)
- Add Rollup build configuration for browser compatibility
- Update README with Node.js usage examples and API documentation
- Add comprehensive test suite for all supported platforms
- Add Claude Code development instructions (CLAUDE.md)
- Remove PHP-specific files (composer.json, src/Meting.php)
- Update GitHub workflows for Node.js environment

This migration maintains API compatibility while providing:
- Promise-based async/await support
- ES6 class design with method chaining
- Zero external dependencies (Node.js built-in modules only)
- Support for all existing music platforms (netease, tencent, xiami, kugou, baidu, kuwo)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>

* refactor: 重构为 Provider 模式架构

- 引入统一的 Provider 接口,实现平台解耦
- 将原有单体文件拆分为模块化 Provider 系统
- 实现真正的内部闭环设计,每个 Provider 独立处理编码/解码
- 优化构建系统,支持版本号注入和 TypeScript 定义生成
- 完善测试覆盖,支持独立平台测试
- 新增架构文档,详细说明设计模式和开发流程

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>

* fix: 修复 ES Module 导入问题,添加 package.json exports 配置

- 添加 module 字段指向 ESM 版本构建文件
- 添加 exports 字段支持双包发布模式
- 修正 main 字段路径格式
- 解决 import Meting from '@meting/core'; 导入失败问题

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Happy <[email protected]>

* refactor: 简化网易云音乐架构并恢复 search option 参数支持

- 移除 WebAPI 支持,统一使用 EAPI 架构,简化代码结构
- 删除复杂的选项管理系统和全局配置
- 恢复 search 接口的 option 参数支持(type, page, limit)
- 优化构建配置和代码压缩设置
- 更新文档和测试以反映新的 API 结构

Breaking Changes:
- 移除 setOption() 方法
- 删除 WebAPI (weapi) 相关代码
- 简化 netease provider 为纯 EAPI 实现

🤖 Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Happy <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
Co-authored-by: Happy <[email protected]>
2025-10-10 13:00:21 +08:00

98 lines
3.0 KiB
JavaScript

/**
* Meting Node.js 基础测试
*/
import Meting from '../src/meting.js';
async function runTests() {
console.log('=== Meting Node.js 基础测试 ===\n');
const platforms = ['netease', 'tencent', 'kugou', 'baidu', 'kuwo'];
const testKeyword = '周杰伦';
for (const platform of platforms) {
console.log(`\n--- 测试平台: ${platform} ---`);
try {
const meting = new Meting(platform);
meting.format(true);
// 测试搜索功能
console.log('测试搜索功能...');
const searchResult = await meting.search(testKeyword, { limit: 1 });
const songs = JSON.parse(searchResult);
if (songs.length > 0) {
const song = songs[0];
console.log(`✓ 搜索成功: ${song.name} - ${song.artist.join(', ')}`);
// 测试歌曲详情
console.log('测试获取歌曲详情...');
const songDetail = await meting.song(song.id);
const songData = JSON.parse(songDetail);
if (songData.length > 0) {
console.log(`✓ 获取歌曲详情成功: ${songData[0].name}`);
} else {
console.log('✗ 获取歌曲详情失败');
}
// 测试获取播放链接
console.log('测试获取播放链接...');
try {
const url = await meting.url(song.url_id, 128);
const urlData = JSON.parse(url);
if (urlData.url) {
console.log('✓ 获取播放链接成功');
} else {
console.log('✗ 获取播放链接失败(可能需要会员或已下架)');
}
} catch (error) {
console.log('✗ 获取播放链接出错:', error.message);
}
// 测试获取歌词
console.log('测试获取歌词...');
try {
const lyric = await meting.lyric(song.lyric_id);
const lyricData = JSON.parse(lyric);
if (lyricData.lyric) {
console.log('✓ 获取歌词成功');
} else {
console.log('✗ 获取歌词失败(可能无歌词)');
}
} catch (error) {
console.log('✗ 获取歌词出错:', error.message);
}
// 测试获取封面
console.log('测试获取封面图片...');
try {
const pic = await meting.pic(song.pic_id, 200);
const picData = JSON.parse(pic);
if (picData.url) {
console.log('✓ 获取封面图片成功');
} else {
console.log('✗ 获取封面图片失败');
}
} catch (error) {
console.log('✗ 获取封面图片出错:', error.message);
}
} else {
console.log('✗ 搜索失败或无结果');
}
} catch (error) {
console.log(`✗ 平台 ${platform} 测试失败:`, error.message);
}
// 添加延迟避免请求过快
await new Promise(resolve => setTimeout(resolve, 2000));
}
console.log('\n=== 测试完成 ===');
}
// 执行测试
runTests().catch(console.error);