Skip to content
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

chore(tests): use separate envs for each tests #371

Merged
merged 12 commits into from
Feb 12, 2024
27 changes: 9 additions & 18 deletions tests/Disable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {runCli} from './_runCli';
const engine = new Engine();

beforeEach(async () => {
// `process.env` is reset after each tests in setupTests.js.
process.env.COREPACK_HOME = npath.fromPortablePath(await xfs.mktempPromise());
});

Expand All @@ -26,15 +27,10 @@ describe(`DisableCommand`, () => {
for (const variant of getBinaryNames(binName))
await makeBin(cwd, variant as Filename, {ignorePlatform: true});

const PATH = process.env.PATH;
try {
process.env.PATH = `${npath.fromPortablePath(cwd)}${delimiter}${PATH}`;
await expect(runCli(cwd, [`disable`])).resolves.toMatchObject({
exitCode: 0,
});
} finally {
process.env.PATH = PATH;
}
process.env.PATH = `${npath.fromPortablePath(cwd)}${delimiter}${process.env.PATH}`;
await expect(runCli(cwd, [`disable`])).resolves.toMatchObject({
exitCode: 0,
});

const sortedEntries = xfs.readdirPromise(cwd).then(entries => {
return entries.sort();
Expand Down Expand Up @@ -84,15 +80,10 @@ describe(`DisableCommand`, () => {
const dontRemoveBin = await makeBin(cwd, `dont-remove` as Filename);
binNames.add(ppath.basename(dontRemoveBin));

const PATH = process.env.PATH;
try {
process.env.PATH = `${npath.fromPortablePath(cwd)}${delimiter}${PATH}`;
await expect(runCli(cwd, [`disable`, `yarn`])).resolves.toMatchObject({
exitCode: 0,
});
} finally {
process.env.PATH = PATH;
}
process.env.PATH = `${npath.fromPortablePath(cwd)}${delimiter}${process.env.PATH}`;
await expect(runCli(cwd, [`disable`, `yarn`])).resolves.toMatchObject({
exitCode: 0,
});

for (const variant of getBinaryNames(`yarn`))
binNames.delete(variant);
Expand Down
35 changes: 13 additions & 22 deletions tests/Enable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {runCli} from './
const engine = new Engine();

beforeEach(async () => {
// `process.env` is reset after each tests in setupTests.js.
process.env.COREPACK_HOME = npath.fromPortablePath(await xfs.mktempPromise());
process.env.COREPACK_DEFAULT_TO_LATEST = `0`;
});
Expand All @@ -21,17 +22,12 @@ describe(`EnableCommand`, () => {
await xfs.mktempPromise(async cwd => {
const corepackBin = await makeBin(cwd, `corepack` as Filename);

const PATH = process.env.PATH;
try {
process.env.PATH = `${npath.fromPortablePath(cwd)}${delimiter}${PATH}`;
await expect(runCli(cwd, [`enable`])).resolves.toMatchObject({
stdout: ``,
stderr: ``,
exitCode: 0,
});
} finally {
process.env.PATH = PATH;
}
process.env.PATH = `${npath.fromPortablePath(cwd)}${delimiter}${process.env.PATH}`;
await expect(runCli(cwd, [`enable`])).resolves.toMatchObject({
stdout: ``,
stderr: ``,
exitCode: 0,
});

const sortedEntries = xfs.readdirPromise(cwd).then(entries => {
return entries.sort();
Expand Down Expand Up @@ -73,17 +69,12 @@ describe(`EnableCommand`, () => {
await xfs.mktempPromise(async cwd => {
const corepackBin = await makeBin(cwd, `corepack` as Filename);

const PATH = process.env.PATH;
try {
process.env.PATH = `${npath.fromPortablePath(cwd)}${delimiter}${PATH}`;
await expect(runCli(cwd, [`enable`, `yarn`])).resolves.toMatchObject({
stdout: ``,
stderr: ``,
exitCode: 0,
});
} finally {
process.env.PATH = PATH;
}
process.env.PATH = `${npath.fromPortablePath(cwd)}${delimiter}${process.env.PATH}`;
await expect(runCli(cwd, [`enable`, `yarn`])).resolves.toMatchObject({
stdout: ``,
stderr: ``,
exitCode: 0,
});

const sortedEntries = xfs.readdirPromise(cwd).then(entries => {
return entries.sort();
Expand Down
1 change: 1 addition & 0 deletions tests/Up.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import process from 'node:process';
import {runCli} from './_runCli';

beforeEach(async () => {
// `process.env` is reset after each tests in setupTests.js.
process.env.COREPACK_HOME = npath.fromPortablePath(await xfs.mktempPromise());
process.env.COREPACK_DEFAULT_TO_LATEST = `0`;
});
Expand Down
1 change: 1 addition & 0 deletions tests/Use.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import process from 'node:process';
import {runCli} from './_runCli';

beforeEach(async () => {
// `process.env` is reset after each tests in setupTests.js.
process.env.COREPACK_HOME = npath.fromPortablePath(await xfs.mktempPromise());
process.env.COREPACK_DEFAULT_TO_LATEST = `0`;
});
Expand Down
Loading