Skip to content

Remove temporary home directories in test teardown #662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import {Filename, ppath, xfs, npath, PortablePath} from '@yarnpkg/fslib';
import os from 'node:os';
import process from 'node:process';
import {beforeEach, describe, expect, it} from 'vitest';
import {Filename, ppath, xfs, npath, PortablePath} from '@yarnpkg/fslib';
import os from 'node:os';
import process from 'node:process';
import {afterEach, beforeEach, describe, expect, it} from 'vitest';

import config from '../config.json';
import * as folderUtils from '../sources/folderUtils';
import {SupportedPackageManagerSet} from '../sources/types';
import config from '../config.json';
import * as folderUtils from '../sources/folderUtils';
import {SupportedPackageManagerSet} from '../sources/types';

import {runCli} from './_runCli';
import {runCli} from './_runCli';


beforeEach(async () => {
const home = await xfs.mktempPromise();

// `process.env` is reset after each tests in setupTests.js.
process.env.COREPACK_HOME = npath.fromPortablePath(await xfs.mktempPromise());
process.env.COREPACK_HOME = npath.fromPortablePath(home);
process.env.COREPACK_DEFAULT_TO_LATEST = `0`;

return async () => {
await xfs.removePromise(home, {recursive: true});
};
});

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

describe(`read-only and offline environment`, () => {
afterEach(async () => {
const home = npath.toPortablePath(process.env.COREPACK_HOME!);
await xfs.chmodPromise(ppath.join(home, `lastKnownGood.json`), 0o644);
await xfs.chmodPromise(home, 0o755);
});

it(`should support running in project scope`, async () => {
await xfs.mktempPromise(async cwd => {
// Reset to default
Expand Down