Skip to content

Commit b0608d1

Browse files
chore(tests): remove temporary directories in test teardown (#662)
1 parent 351d86c commit b0608d1

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

tests/main.test.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
1-
import {Filename, ppath, xfs, npath, PortablePath} from '@yarnpkg/fslib';
2-
import os from 'node:os';
3-
import process from 'node:process';
4-
import {beforeEach, describe, expect, it} from 'vitest';
1+
import {Filename, ppath, xfs, npath, PortablePath} from '@yarnpkg/fslib';
2+
import os from 'node:os';
3+
import process from 'node:process';
4+
import {afterEach, beforeEach, describe, expect, it} from 'vitest';
55

6-
import config from '../config.json';
7-
import * as folderUtils from '../sources/folderUtils';
8-
import {SupportedPackageManagerSet} from '../sources/types';
6+
import config from '../config.json';
7+
import * as folderUtils from '../sources/folderUtils';
8+
import {SupportedPackageManagerSet} from '../sources/types';
99

10-
import {runCli} from './_runCli';
10+
import {runCli} from './_runCli';
1111

1212

1313
beforeEach(async () => {
14+
const home = await xfs.mktempPromise();
15+
1416
// `process.env` is reset after each tests in setupTests.js.
15-
process.env.COREPACK_HOME = npath.fromPortablePath(await xfs.mktempPromise());
17+
process.env.COREPACK_HOME = npath.fromPortablePath(home);
1618
process.env.COREPACK_DEFAULT_TO_LATEST = `0`;
19+
20+
return async () => {
21+
await xfs.removePromise(home, {recursive: true});
22+
};
1723
});
1824

1925
it(`should refuse to download a package manager if the hash doesn't match`, async () => {
@@ -480,6 +486,12 @@ it(`should support disabling the network accesses from the environment`, async (
480486
});
481487

482488
describe(`read-only and offline environment`, () => {
489+
afterEach(async () => {
490+
const home = npath.toPortablePath(process.env.COREPACK_HOME!);
491+
await xfs.chmodPromise(ppath.join(home, `lastKnownGood.json`), 0o644);
492+
await xfs.chmodPromise(home, 0o755);
493+
});
494+
483495
it(`should support running in project scope`, async () => {
484496
await xfs.mktempPromise(async cwd => {
485497
// Reset to default

0 commit comments

Comments
 (0)