Skip to content

Commit

Permalink
Fix scripts tests
Browse files Browse the repository at this point in the history
Snapshot indentation issues until vitest-dev/vitest#4663 is released
  • Loading branch information
IanVS committed Dec 5, 2023
1 parent 0845820 commit 56c0710
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 134 deletions.
1 change: 0 additions & 1 deletion scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@
"util": "^0.12.4",
"uuid": "^9.0.0",
"vitest": "^1.0.1",
"vitest-mock-extended": "^1.2.1",
"wait-on": "^7.0.1",
"window-size": "^1.1.1",
"yaml": "^2.3.1",
Expand Down
3 changes: 1 addition & 2 deletions scripts/release/__tests__/cancel-preparation-runs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ describe('Cancel preparation runs', () => {
it('should fail early when no GH_TOKEN is set', async () => {
delete process.env.GH_TOKEN;
await expect(cancelPreparationWorkflows()).rejects.toThrowErrorMatchingInlineSnapshot(
`"GH_TOKEN environment variable must be set, exiting."`
);
`[Error: GH_TOKEN environment variable must be set, exiting.]`);
});

it('should cancel all running preparation workflows in GitHub', async () => {
Expand Down
54 changes: 23 additions & 31 deletions scripts/release/__tests__/ensure-next-ahead.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,16 @@
/* eslint-disable no-underscore-dangle */
import path from 'path';
import { vi, describe, it, expect, beforeEach } from 'vitest';
import { mockDeep } from 'vitest-mock-extended';
import { run as ensureNextAhead } from '../ensure-next-ahead';
import * as gitClient_ from '../utils/git-client';
import * as bumpVersion_ from '../version';
import * as fsExtraOriginal from 'fs-extra';

vi.mock('../utils/git-client', async () => {
const y = await import('../utils/git-client');
return mockDeep(y);
});
vi.mock('../version', async () => {
const y = await import('../version');
return mockDeep(y);
});

// eslint-disable-next-line jest/no-mocks-import
vi.mock('fs-extra', () => require('../../../code/__mocks__/fs-extra'));
vi.mock('../utils/git-client');
vi.mock('../version');
vi.mock('fs-extra', async() => await import('../../../code/__mocks__/fs-extra'));

const fsExtra = require('fs-extra');
const fsExtra = vi.mocked<typeof import('../../../code/__mocks__/fs-extra')>(fsExtraOriginal as any);

const bumpVersion = vi.mocked(bumpVersion_, true);
const gitClient = vi.mocked(gitClient_, true);
Expand All @@ -41,30 +33,30 @@ describe('Ensure next ahead', () => {

it('should throw when main-version is missing', async () => {
await expect(ensureNextAhead({})).rejects.toThrowErrorMatchingInlineSnapshot(`
"[
{
"code": "invalid_type",
"expected": "string",
"received": "undefined",
"path": [
"mainVersion"
],
"message": "Required"
}
]"
[ZodError: [
{
"code": "invalid_type",
"expected": "string",
"received": "undefined",
"path": [
"mainVersion"
],
"message": "Required"
}
]]
`);
});

it('should throw when main-version is not a semver string', async () => {
await expect(ensureNextAhead({ mainVersion: '200' })).rejects
.toThrowErrorMatchingInlineSnapshot(`
"[
{
"code": "custom",
"message": "main-version must be a valid semver version string like '7.4.2'.",
"path": []
}
]"
[ZodError: [
{
"code": "custom",
"message": "main-version must be a valid semver version string like '7.4.2'.",
"path": []
}
]]
`);
});

Expand Down
13 changes: 3 additions & 10 deletions scripts/release/__tests__/label-patches.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import { beforeEach, expect, vi, test } from 'vitest';
import type { LogResult } from 'simple-git';
import ansiRegex from 'ansi-regex';
import { mockDeep } from 'vitest-mock-extended';
import { run } from '../label-patches';
import * as gitClient_ from '../utils/git-client';
import * as githubInfo_ from '../utils/get-github-info';
import * as github_ from '../utils/github-client';

vi.mock('uuid');
vi.mock('simple-git');
vi.mock('../utils/get-github-info');
vi.mock('../utils/github-client');
vi.mock('../utils/git-client', async () => {
const y = await import('../utils/git-client');
return mockDeep(y);
});
vi.mock('../utils/git-client');

const gitClient = vi.mocked(gitClient_, true);
const github = vi.mocked(github_, true);
Expand Down Expand Up @@ -99,12 +94,10 @@ beforeEach(() => {

test('it should fail early when no GH_TOKEN is set', async () => {
delete process.env.GH_TOKEN;
await expect(run({})).rejects.toThrowErrorMatchingInlineSnapshot(
`"GH_TOKEN environment variable must be set, exiting."`
);
await expect(run({})).rejects.toThrowErrorMatchingInlineSnapshot(`[Error: GH_TOKEN environment variable must be set, exiting.]`);
});

test.only('it should label the PR associated with cherry picks in the current branch', async () => {
test('it should label the PR associated with cherry picks in the current branch', async () => {
process.env.GH_TOKEN = 'MY_SECRET';

const writeStderr = vi.spyOn(process.stderr, 'write').mockImplementation((() => {}) as any);
Expand Down
129 changes: 64 additions & 65 deletions scripts/release/__tests__/version.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,25 @@ describe('Version', () => {
});

await expect(version({ releaseType: 'invalid' })).rejects.toThrowErrorMatchingInlineSnapshot(`
"[
{
"received": "invalid",
"code": "invalid_enum_value",
"options": [
"major",
"minor",
"patch",
"prerelease",
"premajor",
"preminor",
"prepatch"
],
"path": [
"releaseType"
],
"message": "Invalid enum value. Expected 'major' | 'minor' | 'patch' | 'prerelease' | 'premajor' | 'preminor' | 'prepatch', received 'invalid'"
}
]"
[ZodError: [
{
"received": "invalid",
"code": "invalid_enum_value",
"options": [
"major",
"minor",
"patch",
"prerelease",
"premajor",
"preminor",
"prepatch"
],
"path": [
"releaseType"
],
"message": "Invalid enum value. Expected 'major' | 'minor' | 'patch' | 'prerelease' | 'premajor' | 'preminor' | 'prepatch', received 'invalid'"
}
]]
`);
});

Expand All @@ -84,13 +84,13 @@ describe('Version', () => {

await expect(version({ releaseType: 'major', preId: 'alpha' })).rejects
.toThrowErrorMatchingInlineSnapshot(`
"[
{
"code": "custom",
"message": "Using prerelease identifier requires one of release types: premajor, preminor, prepatch, prerelease",
"path": []
}
]"
[ZodError: [
{
"code": "custom",
"message": "Using prerelease identifier requires one of release types: premajor, preminor, prepatch, prerelease",
"path": []
}
]]
`);
});

Expand All @@ -103,13 +103,13 @@ describe('Version', () => {

await expect(version({ releaseType: 'major', exact: '1.0.0' })).rejects
.toThrowErrorMatchingInlineSnapshot(`
"[
{
"code": "custom",
"message": "Combining --exact with --release-type is invalid, but having one of them is required",
"path": []
}
]"
[ZodError: [
{
"code": "custom",
"message": "Combining --exact with --release-type is invalid, but having one of them is required",
"path": []
}
]]
`);
});

Expand All @@ -121,15 +121,15 @@ describe('Version', () => {
});

await expect(version({ exact: 'not-semver' })).rejects.toThrowErrorMatchingInlineSnapshot(`
"[
{
"code": "custom",
"message": "--exact version has to be a valid semver string",
"path": [
"exact"
]
}
]"
[ZodError: [
{
"code": "custom",
"message": "--exact version has to be a valid semver string",
"path": [
"exact"
]
}
]]
`);
});

Expand All @@ -142,13 +142,13 @@ describe('Version', () => {

await expect(version({ apply: true, releaseType: 'prerelease' })).rejects
.toThrowErrorMatchingInlineSnapshot(`
"[
{
"code": "custom",
"message": "--apply cannot be combined with --exact or --release-type, as it will always read from code/package.json#deferredNextVersion",
"path": []
}
]"
[ZodError: [
{
"code": "custom",
"message": "--apply cannot be combined with --exact or --release-type, as it will always read from code/package.json#deferredNextVersion",
"path": []
}
]]
`);
});

Expand All @@ -161,13 +161,13 @@ describe('Version', () => {

await expect(version({ apply: true, exact: '1.0.0' })).rejects
.toThrowErrorMatchingInlineSnapshot(`
"[
{
"code": "custom",
"message": "--apply cannot be combined with --exact or --release-type, as it will always read from code/package.json#deferredNextVersion",
"path": []
}
]"
[ZodError: [
{
"code": "custom",
"message": "--apply cannot be combined with --exact or --release-type, as it will always read from code/package.json#deferredNextVersion",
"path": []
}
]]
`);
});

Expand All @@ -180,13 +180,13 @@ describe('Version', () => {

await expect(version({ apply: true, deferred: true })).rejects
.toThrowErrorMatchingInlineSnapshot(`
"[
{
"code": "custom",
"message": "--deferred cannot be combined with --apply",
"path": []
}
]"
[ZodError: [
{
"code": "custom",
"message": "--deferred cannot be combined with --apply",
"path": []
}
]]
`);
});

Expand All @@ -196,8 +196,7 @@ describe('Version', () => {
});

await expect(version({ apply: true })).rejects.toThrowErrorMatchingInlineSnapshot(
`"The 'deferredNextVersion' property in code/package.json is unset. This is necessary to apply a deferred version bump"`
);
`[Error: The 'deferredNextVersion' property in code/package.json is unset. This is necessary to apply a deferred version bump]`);

expect(fsExtra.writeJson).not.toHaveBeenCalled();
expect(fsExtra.writeFile).not.toHaveBeenCalled();
Expand Down
25 changes: 0 additions & 25 deletions scripts/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3186,7 +3186,6 @@ __metadata:
verdaccio: "npm:^5.19.1"
verdaccio-auth-memory: "npm:^10.2.0"
vitest: "npm:^1.0.1"
vitest-mock-extended: "npm:^1.2.1"
wait-on: "npm:^7.0.1"
window-size: "npm:^1.1.1"
yaml: "npm:^2.3.1"
Expand Down Expand Up @@ -16127,18 +16126,6 @@ __metadata:
languageName: node
linkType: hard

"ts-essentials@npm:^9.3.2":
version: 9.4.1
resolution: "ts-essentials@npm:9.4.1"
peerDependencies:
typescript: ">=4.1.0"
peerDependenciesMeta:
typescript:
optional: true
checksum: 03f195f1f8935c5e72615e05d5ca160aeb987ba23e1f7ffad2dc4ac47604a6931621bf120279c3325513894a2040cee01070f4df95c1e3bac6435c25339eb519
languageName: node
linkType: hard

"ts-interface-checker@npm:^0.1.9":
version: 0.1.13
resolution: "ts-interface-checker@npm:0.1.13"
Expand Down Expand Up @@ -17333,18 +17320,6 @@ __metadata:
languageName: node
linkType: hard

"vitest-mock-extended@npm:^1.2.1":
version: 1.3.1
resolution: "vitest-mock-extended@npm:1.3.1"
dependencies:
ts-essentials: "npm:^9.3.2"
peerDependencies:
typescript: 3.x || 4.x || 5.x
vitest: ">=0.31.1"
checksum: 0d3b5f1b4f53d326b636931573801811a6fe5566ea8ea06a2b9e1037845b3049d045156a33b0916b3ef40b83b9076499142ac4a24490a96bbecf74b9770a780f
languageName: node
linkType: hard

"vitest@npm:^1.0.1":
version: 1.0.1
resolution: "vitest@npm:1.0.1"
Expand Down

0 comments on commit 56c0710

Please sign in to comment.