Skip to content

Commit

Permalink
test add corepack check
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-zimerman committed Dec 10, 2024
1 parent 429dbbd commit d4c885d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
1 change: 0 additions & 1 deletion test/scripts/check-siblings.npm10.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ describe('NPM 10 tests', () => {

ClearE2ETestFolder(testPath);
CreateE2EPackage(testPath);
InstallSDK('corepack',['prepare', '--activate'], testPath);

expect(GetPackageManagerVersion('npm', testPath)).toBe("10.9.0");

Expand Down
13 changes: 4 additions & 9 deletions test/scripts/check-siblings.yarnv3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ describe('Yarn V3 tests', () => {
ClearE2ETestFolder(testPath);
CreateE2EPackage(testPath);
SetupYarnRC(testPath);
// InstallSDK('corepack',['prepare', '--activate'], testPath);
// expect(GetPackageManagerVersion('yarn', testPath)).toBe("3.8.6");
expect(GetPackageManagerVersion('yarn', testPath)).toBe("3.8.6");

const expectedPackageJson = {
...GetInitialE2EPackage(testPath),
Expand All @@ -46,7 +45,6 @@ describe('Yarn V3 tests', () => {
expect(result.status).toBe(0);
expect(packageJson).toEqual(expectedPackageJson);
expect(e2eLogs).toContain('E2E_TEST: OK');
expect(GetPackageManagerVersion('yarn', testPath)).toBe("3.8.6");
});

test('warns when incorrect sibling is installed', async () => {
Expand All @@ -59,8 +57,7 @@ describe('Yarn V3 tests', () => {
ClearE2ETestFolder(testPath);
CreateE2EPackage(testPath);
SetupYarnRC(testPath);
// InstallSDK('corepack',['prepare', '--activate'], testPath);
// expect(GetPackageManagerVersion('yarn',testPath)).toBe("3.8.6");
expect(GetPackageManagerVersion('yarn',testPath)).toBe("3.8.6");

const expectedPackageJson = {
...GetInitialE2EPackage(testPath),
Expand Down Expand Up @@ -104,8 +101,7 @@ describe('Yarn V3 tests', () => {
CreateE2EStartPackage(testPath, dependenciesJson);
CreateE2EPackage(testPath);
SetupYarnRC(testPath);
// InstallSDK('corepack',['prepare', '--activate'], testPath);
// expect(GetPackageManagerVersion('yarn',testPath)).toBe("3.8.6");
expect(GetPackageManagerVersion('yarn',testPath)).toBe("3.8.6");

const expectedPackageJson = {
...GetInitialE2EPackage(testPath),
Expand Down Expand Up @@ -141,8 +137,7 @@ describe('Yarn V3 tests', () => {
CreateE2EStartPackage(testPath, dependenciesJson);
CreateE2EPackage(testPath);
SetupYarnRC(testPath);
// InstallSDK('corepack',['prepare', '--activate'], testPath);
// expect(GetPackageManagerVersion('yarn',testPath)).toBe("3.8.6");
expect(GetPackageManagerVersion('yarn',testPath)).toBe("3.8.6");

const expectedPackageJson = {
...GetInitialE2EPackage(testPath),
Expand Down
17 changes: 17 additions & 0 deletions test/scripts/check-siblingsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,23 @@ export function InstallSDK(pkgMnger: string, args: ReadonlyArray<string>, rootPa
}

export function GetPackageManagerVersion(pkgMnger: string, testPath: string): string {
const result2 = spawnSync('corepack', ['--version'], {
cwd: testPath,
stdio: ['pipe'], // Ensure output is in readable string format
// Clear env to avoid contamination with root folder.
env: {
INIT_CWD: testPath
}
});

if (result2.error) {
throw new Error(`On PATH ${testPath}, Expected corepack to return the version, but got:\nMessage: ${result2.error.message}\nStack: ${result2.error.stack}`);
}
expect(result2.status).toBe(0);
expect(result2.stderr?.toString()).toBeEmpty();
expect(result2.stdout.toString().trim()).not.toBeEmpty();


const result = spawnSync(pkgMnger, ['--version'], {
cwd: testPath,
stdio: ['pipe'], // Ensure output is in readable string format
Expand Down

0 comments on commit d4c885d

Please sign in to comment.