From 00a0dc476f427e71c0c29b534b4c91ebc943d2ff Mon Sep 17 00:00:00 2001 From: merceyz Date: Sun, 8 Oct 2023 16:28:02 +0200 Subject: [PATCH] test: check that a semver version is required --- tests/main.test.ts | 34 ++++++++++++++++++++++++ tests/nock/xMfDvY4klJ8hOhDDO0NK5A-1.dat | Bin 0 -> 7 bytes tests/nock/xMfDvY4klJ8hOhDDO0NK5A-2.dat | Bin 0 -> 7 bytes tests/nock/xMfDvY4klJ8hOhDDO0NK5A-3.dat | Bin 0 -> 7 bytes 4 files changed, 34 insertions(+) create mode 100644 tests/nock/xMfDvY4klJ8hOhDDO0NK5A-1.dat create mode 100644 tests/nock/xMfDvY4klJ8hOhDDO0NK5A-2.dat create mode 100644 tests/nock/xMfDvY4klJ8hOhDDO0NK5A-3.dat diff --git a/tests/main.test.ts b/tests/main.test.ts index f72a97fb6..3538ff3dd 100644 --- a/tests/main.test.ts +++ b/tests/main.test.ts @@ -29,6 +29,40 @@ it(`should refuse to download a package manager if the hash doesn't match`, asyn }); }); +it(`should require a version to be specified`, async () => { + await xfs.mktempPromise(async cwd => { + await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as Filename), { + packageManager: `yarn`, + }); + + await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({ + exitCode: 1, + stderr: ``, + stdout: /expected a semver version/, + }); + + await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as Filename), { + packageManager: `yarn@stable`, + }); + + await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({ + exitCode: 1, + stderr: ``, + stdout: /expected a semver version/, + }); + + await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as Filename), { + packageManager: `yarn@^1.0.0`, + }); + + await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({ + exitCode: 1, + stderr: ``, + stdout: /expected a semver version/, + }); + }); +}); + const testedPackageManagers: Array<[string, string]> = [ [`yarn`, `1.22.4`], [`yarn`, `1.22.4+sha1.01c1197ca5b27f21edc8bc472cd4c8ce0e5a470e`], diff --git a/tests/nock/xMfDvY4klJ8hOhDDO0NK5A-1.dat b/tests/nock/xMfDvY4klJ8hOhDDO0NK5A-1.dat new file mode 100644 index 0000000000000000000000000000000000000000..b03652e61c40452494e185715af92d4f9a618540 GIT binary patch literal 7 Ocmey*@5rFSzyJUV3juTh literal 0 HcmV?d00001 diff --git a/tests/nock/xMfDvY4klJ8hOhDDO0NK5A-2.dat b/tests/nock/xMfDvY4klJ8hOhDDO0NK5A-2.dat new file mode 100644 index 0000000000000000000000000000000000000000..b03652e61c40452494e185715af92d4f9a618540 GIT binary patch literal 7 Ocmey*@5rFSzyJUV3juTh literal 0 HcmV?d00001 diff --git a/tests/nock/xMfDvY4klJ8hOhDDO0NK5A-3.dat b/tests/nock/xMfDvY4klJ8hOhDDO0NK5A-3.dat new file mode 100644 index 0000000000000000000000000000000000000000..b03652e61c40452494e185715af92d4f9a618540 GIT binary patch literal 7 Ocmey*@5rFSzyJUV3juTh literal 0 HcmV?d00001