mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-10-21 05:01:26 -07:00
test: cut low-value tests, rewrite the rest around behavior, parallelize lanes (#285)
This commit is contained in:
1 parent
4b6842d034
commit
b48083ddd8
368 files changed
+18045
-60331
No files matched your search
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Runs `run` with the given process env values (`undefined` deletes a key) and restores the
|
||||
* originals afterwards, even if `run` throws or rejects.
|
||||
*/
|
||||
export async function withEnv<T>(
|
||||
overrides: Record<string, string | undefined>,
|
||||
run: () => T | Promise<T>,
|
||||
): Promise<T> {
|
||||
const originals = Object.fromEntries(
|
||||
Object.keys(overrides).map((key) => [key, process.env[key]]),
|
||||
);
|
||||
const apply = (values: Record<string, string | undefined>): void => {
|
||||
for (const [key, value] of Object.entries(values)) {
|
||||
if (value === undefined) delete process.env[key];
|
||||
else process.env[key] = value;
|
||||
}
|
||||
};
|
||||
|
||||
apply(overrides);
|
||||
try {
|
||||
return await run();
|
||||
} finally {
|
||||
apply(originals);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user