版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

33 lines
661 B

  1. import fs from "node:fs";
  2. import { resolve, dirname } from "node:path";
  3. import { fileURLToPath } from "node:url";
  4. const __dirname = dirname(fileURLToPath(import.meta.url));
  5. export const getFileHelper = () => {
  6. let cleanupFile = null;
  7. afterEach(() => {
  8. if (!cleanupFile) return;
  9. try {
  10. fs.unlinkSync(cleanupFile);
  11. } catch (e) {}
  12. cleanupFile = null;
  13. });
  14. const getFilePath = async (path) => {
  15. const expectedFilePath = resolve(__dirname, path);
  16. cleanupFile = expectedFilePath;
  17. try {
  18. await fs.promises.unlink(cleanupFile);
  19. } catch (e) {}
  20. return expectedFilePath;
  21. };
  22. return {
  23. getFilePath,
  24. };
  25. };