feat: 初始化文件哈希 GitHub Action 项目
This commit is contained in:
1021
tests/index.test.js
Normal file
1021
tests/index.test.js
Normal file
File diff suppressed because it is too large
Load Diff
53
tests/utils.js
Normal file
53
tests/utils.js
Normal file
@@ -0,0 +1,53 @@
|
||||
import fs from 'fs/promises';
|
||||
import path from 'path';
|
||||
import os from 'os';
|
||||
|
||||
/**
|
||||
* 创建一个临时测试目录
|
||||
*
|
||||
* @returns {Promise<string>} 临时目录路径
|
||||
*/
|
||||
export async function createTestDir() {
|
||||
return await fs.mkdtemp(path.join(os.tmpdir(), 'files-hash-test-'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个测试文件
|
||||
*
|
||||
* @param {string} filePath - 要创建的文件路径
|
||||
* @param {string} content - 文件内容
|
||||
*/
|
||||
export async function createTestFile(filePath, content) {
|
||||
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
||||
await fs.writeFile(filePath, content);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理测试文件
|
||||
*
|
||||
* @param {string[]} files - 要清理的文件路径数组
|
||||
*/
|
||||
export async function cleanupTestFiles(files) {
|
||||
for (const file of files) {
|
||||
try {
|
||||
await fs.unlink(file);
|
||||
} catch (error) {
|
||||
// 忽略文件不存在的错误
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理测试目录
|
||||
*
|
||||
* @param {string[]} dirs - 要清理的目录路径数组
|
||||
*/
|
||||
export async function cleanupTestDirs(dirs) {
|
||||
for (const dir of dirs) {
|
||||
try {
|
||||
await fs.rmdir(dir, { recursive: true });
|
||||
} catch (error) {
|
||||
// 忽略目录不存在的错误
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user