From b6efa7f9037a75d9b7afe041ebd73b12db245bbe Mon Sep 17 00:00:00 2001
From: Sayak Mukhopadhyay <mukhopadhyaysayak@gmail.com>
Date: Mon, 26 Dec 2022 19:21:01 +0530
Subject: [PATCH] tests: add test to check for corepack enable call

---
 __tests__/installer.test.ts | 38 +++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts
index 2a74f78f..a2ef6cfb 100644
--- a/__tests__/installer.test.ts
+++ b/__tests__/installer.test.ts
@@ -1253,6 +1253,44 @@ describe('setup-node', () => {
       }
     );
   });
+
+  describe('corepack flag', () => {
+    it('use corepack if specified', async () => {
+      inputs['corepack'] = 'true';
+      await main.run();
+      expect(getExecOutputSpy).toHaveBeenCalledWith(
+        'corepack',
+        ['enable'],
+        expect.anything()
+      );
+    });
+
+    it('use corepack with given package manager', async () => {
+      inputs['corepack'] = 'npm';
+      await main.run();
+      expect(getExecOutputSpy).toHaveBeenCalledWith(
+        'corepack',
+        ['enable', 'npm'],
+        expect.anything()
+      );
+    });
+
+    it('use corepack with multiple package managers', async () => {
+      inputs['corepack'] = 'npm yarn';
+      await main.run();
+      expect(getExecOutputSpy).toHaveBeenCalledWith(
+        'corepack',
+        ['enable', 'npm', 'yarn'],
+        expect.anything()
+      );
+    });
+
+    it('fails to use corepack with an invalid package manager', async () => {
+      await expect(im.enableCorepack('npm turbo')).rejects.toThrowError(
+        `One or more of the specified package managers [ npm turbo ] are not supported by corepack`
+      );
+    });
+  });
 });
 
 describe('helper methods', () => {