Skip to content

Commit 7b193d8

Browse files
chore(tests): fix string matching expectations (#648)
Vitest does not support matching a regex with a string, it would fail to report unmatched output.
1 parent 91ea527 commit 7b193d8

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

tests/main.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ it(`should refuse to download a package manager if the hash doesn't match`, asyn
2424

2525
await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
2626
exitCode: 1,
27-
stderr: /Mismatch hashes/,
27+
stderr: expect.stringContaining(`Mismatch hashes`),
2828
stdout: ``,
2929
});
3030
});
@@ -35,7 +35,7 @@ it(`should refuse to download a known package manager from a URL`, async () => {
3535
// Package managers known by Corepack cannot be loaded from a URL.
3636
await expect(runCli(cwd, [`yarn@https://registry.npmjs.com/yarn/-/yarn-1.22.21.tgz`, `--version`])).resolves.toMatchObject({
3737
exitCode: 1,
38-
stderr: /Illegal use of URL for known package manager/,
38+
stderr: expect.stringContaining(`Illegal use of URL for known package manager`),
3939
stdout: ``,
4040
});
4141

@@ -57,7 +57,7 @@ it.fails(`should refuse to download a known package manager from a URL in packag
5757

5858
await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
5959
exitCode: 1,
60-
stderr: /Illegal use of URL for known package manager/,
60+
stderr: expect.stringContaining(`Illegal use of URL for known package manager`),
6161
stdout: ``,
6262
});
6363

@@ -82,7 +82,7 @@ it(`should require a version to be specified`, async () => {
8282

8383
await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
8484
exitCode: 1,
85-
stderr: /expected a semver version/,
85+
stderr: `No version specified for yarn in "packageManager" of package.json\n`,
8686
stdout: ``,
8787
});
8888

@@ -92,7 +92,7 @@ it(`should require a version to be specified`, async () => {
9292

9393
await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
9494
exitCode: 1,
95-
stderr: /expected a semver version/,
95+
stderr: expect.stringContaining(`expected a semver version`),
9696
stdout: ``,
9797
});
9898

@@ -102,7 +102,7 @@ it(`should require a version to be specified`, async () => {
102102

103103
await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
104104
exitCode: 1,
105-
stderr: /expected a semver version/,
105+
stderr: expect.stringContaining(`expected a semver version`),
106106
stdout: ``,
107107
});
108108
});
@@ -272,7 +272,7 @@ it(`shouldn't allow using regular Yarn commands on npm-configured projects`, asy
272272

273273
await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
274274
exitCode: 1,
275-
stderr: /This project is configured to use npm/,
275+
stderr: expect.stringContaining(`This project is configured to use npm`),
276276
});
277277
});
278278
});
@@ -473,7 +473,7 @@ it(`should support disabling the network accesses from the environment`, async (
473473

474474
await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
475475
stdout: ``,
476-
stderr: /Network access disabled by the environment/,
476+
stderr: expect.stringContaining(`Network access disabled by the environment`),
477477
exitCode: 1,
478478
});
479479
});
@@ -845,8 +845,8 @@ it(`should download yarn classic from custom registry`, async () => {
845845
process.env.COREPACK_ENABLE_DOWNLOAD_PROMPT = `1`;
846846
await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
847847
exitCode: 0,
848-
stdout: /^1\.\d+\.\d+\r?\n$/,
849-
stderr: /^! Corepack is about to download https:\/\/registry\.npmmirror\.com\/yarn\/-\/yarn-1\.\d+\.\d+\.tgz\r?\n$/,
848+
stdout: expect.stringMatching(/^1\.\d+\.\d+\r?\n$/),
849+
stderr: expect.stringMatching(/^! Corepack is about to download https:\/\/registry\.npmmirror\.com\/yarn\/-\/yarn-1\.\d+\.\d+\.tgz\r?\n$/),
850850
});
851851

852852
// Should keep working with cache
@@ -894,7 +894,7 @@ it(`should download latest pnpm from custom registry`, async () => {
894894
await expect(runCli(cwd, [`pnpm`, `--version`], true)).resolves.toMatchObject({
895895
exitCode: 0,
896896
stdout: `pnpm: Hello from custom registry\n`,
897-
stderr: /^! The local project doesn't define a 'packageManager' field\. Corepack will now add one referencing pnpm@1\.9998\.9999@sha1\./,
897+
stderr: expect.stringContaining(`! The local project doesn't define a 'packageManager' field. Corepack will now add one referencing pnpm@1.9998.9999+sha1.`),
898898
});
899899

900900
// Should keep working with cache
@@ -1027,12 +1027,12 @@ describe(`handle integrity checks`, () => {
10271027
await xfs.mktempPromise(async cwd => {
10281028
await expect(runCli(cwd, [`pnpm@1.x`, `--version`], true)).resolves.toMatchObject({
10291029
exitCode: 1,
1030-
stderr: /Signature does not match/,
1030+
stderr: expect.stringContaining(`Signature does not match`),
10311031
stdout: ``,
10321032
});
1033-
await expect(runCli(cwd, [`yarn@stable`, `--version`], true)).resolves.toMatchObject({
1033+
await expect(runCli(cwd, [`pnpm@latest`, `--version`], true)).resolves.toMatchObject({
10341034
exitCode: 1,
1035-
stderr: /Signature does not match/,
1035+
stderr: expect.stringContaining(`Signature does not match`),
10361036
stdout: ``,
10371037
});
10381038
});

0 commit comments

Comments
 (0)