This commit is contained in:
@@ -151,6 +151,25 @@ async function applyFixture(root, fixture = {}) {
|
||||
const target = await safeSandboxWrite(root, entry.path, entry.content, 'fixture write');
|
||||
if (entry.mode !== undefined) await chmod(target, entry.mode);
|
||||
}
|
||||
for (const entry of fixture.replaceFiles ?? []) {
|
||||
const target = await sandboxPath(root, entry.path, 'fixture replace');
|
||||
if ((await lstat(target)).isSymbolicLink()) {
|
||||
throw new Error(`fixture replace: target is a symbolic link (${entry.path})`);
|
||||
}
|
||||
const source = await readFile(target, 'utf8');
|
||||
const occurrences = source.split(entry.find).length - 1;
|
||||
if (occurrences !== 1) {
|
||||
throw new Error(
|
||||
`fixture replace: stale or ambiguous match for ${entry.path} (${occurrences} matches)`,
|
||||
);
|
||||
}
|
||||
await safeSandboxWrite(
|
||||
root,
|
||||
entry.path,
|
||||
source.replace(entry.find, entry.replace),
|
||||
'fixture replace',
|
||||
);
|
||||
}
|
||||
for (const relativePath of fixture.removePaths ?? []) {
|
||||
await rm(await sandboxPath(root, relativePath, 'fixture remove'), {
|
||||
recursive: true,
|
||||
|
||||
Reference in New Issue
Block a user