From 742340509a3832a2484389da0347a4e4035ce5c9 Mon Sep 17 00:00:00 2001 From: Innpaul Zhang Date: Fri, 23 Feb 2024 13:57:58 +0000 Subject: [PATCH] chore: add test cases --- tests/main.test.ts | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/main.test.ts b/tests/main.test.ts index 9bd409c09..e006131f3 100644 --- a/tests/main.test.ts +++ b/tests/main.test.ts @@ -758,3 +758,46 @@ it(`should be able to show the latest version`, async () => { }); }); }); + +it(`should download yarn classic from custom registry`, async () => { + await xfs.mktempPromise(async cwd => { + process.env.COREPACK_NPM_REGISTRY = `https://registry.npmmirror.com`; + process.env.COREPACK_ENABLE_DOWNLOAD_PROMPT = `1`; + await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({ + exitCode: 0, + stdout: /^1\.\d+\.\d+\r?\n$/, + stderr: /^Corepack is about to download https:\/\/registry\.npmmirror\.com\/yarn\/-\/yarn-1\.\d+\.\d+\.tgz\r?\n$/, + }); + + // Should keep working with cache + await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({ + exitCode: 0, + stdout: /^1\.\d+\.\d+\r?\n$/, + stderr: ``, + }); + }); +}); + +it(`should download yarn berry from custom registry`, async () => { + await xfs.mktempPromise(async cwd => { + process.env.COREPACK_NPM_REGISTRY = `https://registry.npmmirror.com`; + process.env.COREPACK_ENABLE_DOWNLOAD_PROMPT = `1`; + + await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as Filename), { + packageManager: `yarn@3.0.0`, + }); + + await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({ + exitCode: 0, + stdout: `3.0.0\n`, + stderr: `Corepack is about to download https://registry.npmmirror.com/@yarnpkg/cli-dist/-/cli-dist-3.0.0.tgz\n`, + }); + + // Should keep working with cache + await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({ + exitCode: 0, + stdout: `3.0.0\n`, + stderr: ``, + }); + }); +});