fix(cli): fix broken --album on Windows. (#10626)

Extract folder names via system function to avoid the difference between / and \ on Windows.
This commit is contained in:
Feng Kaiyu
2024-06-27 00:12:30 +08:00
committed by GitHub
parent 7f5a3e5adb
commit a3c3619811
2 changed files with 25 additions and 5 deletions

View File

@@ -0,0 +1,19 @@
import { platform } from 'node:os';
import { UploadOptionsDto, getAlbumName } from 'src/commands/asset';
import { describe, expect, it } from 'vitest';
describe('Unit function tests', () => {
it('should return a non-undefined value', () => {
if (platform() === 'win32') {
// This is meaningless for Unix systems.
expect(getAlbumName(String.raw`D:\test\Filename.txt`, {} as UploadOptionsDto)).toBe('test');
}
expect(getAlbumName('D:/parentfolder/test/Filename.txt', {} as UploadOptionsDto)).toBe('test');
});
it('has higher priority to return `albumName` in `options`', () => {
expect(getAlbumName('/parentfolder/test/Filename.txt', { albumName: 'example' } as UploadOptionsDto)).toBe(
'example',
);
});
});