|
1 | 1 | import {
|
2 | 2 | afterAll,
|
3 |
| - afterEach, |
4 | 3 | beforeAll,
|
5 | 4 | beforeEach,
|
6 | 5 | describe,
|
|
9 | 8 | } from 'vitest';
|
10 | 9 | import { join } from 'path';
|
11 | 10 | import { reflinkFileSync, reflinkFile } from '../index.js';
|
12 |
| -import { mkdir, readFile, rm, writeFile } from 'fs/promises'; |
| 11 | +import { mkdir, rm, writeFile } from 'fs/promises'; |
13 | 12 | import { readFileSync } from 'fs';
|
14 | 13 | import { randomUUID } from 'crypto';
|
15 | 14 |
|
@@ -150,6 +149,50 @@ describe('reflink', () => {
|
150 | 149 | }).toThrow();
|
151 | 150 | });
|
152 | 151 |
|
| 152 | + it('should not fail with relative paths', async () => { |
| 153 | + const file = { |
| 154 | + path: "file.txt", |
| 155 | + content: "Hello World!", |
| 156 | + } |
| 157 | + |
| 158 | + const dest = "file-copy.txt"; |
| 159 | + |
| 160 | + await rm(dest, { force: true }); |
| 161 | + await writeFile(file.path, file.content); |
| 162 | + |
| 163 | + await reflinkFile(file.path, dest); |
| 164 | + |
| 165 | + const content = readFileSync(dest, 'utf-8'); |
| 166 | + |
| 167 | + expect(content).toBe(file.content); |
| 168 | + |
| 169 | + // clean both files |
| 170 | + await rm("file.txt"); |
| 171 | + await rm("file-copy.txt"); |
| 172 | + }); |
| 173 | + |
| 174 | + it('should not fail with nested relative paths', async () => { |
| 175 | + const file = { |
| 176 | + path: "nested/file.txt", |
| 177 | + content: "Hello World!", |
| 178 | + } |
| 179 | + |
| 180 | + const dest = "nested/file-copy.txt"; |
| 181 | + |
| 182 | + await rm(dest, { force: true }); |
| 183 | + await mkdir("nested", { recursive: true }); |
| 184 | + await writeFile(file.path, file.content); |
| 185 | + |
| 186 | + await reflinkFile(file.path, dest); |
| 187 | + |
| 188 | + const content = readFileSync(dest, 'utf-8'); |
| 189 | + |
| 190 | + expect(content).toBe(file.content); |
| 191 | + |
| 192 | + // clean both files |
| 193 | + await rm("nested", { recursive: true }); |
| 194 | + }); |
| 195 | + |
153 | 196 | it('should correctly clone 1000 files (sync)', async () => {
|
154 | 197 | const files = Array.from({ length: 1000 }, (_, i) => ({
|
155 | 198 | path: join(sandboxDir, `file${i}.txt`),
|
|
0 commit comments