Skip to content

Commit 1e90ba3

Browse files
committed
Get all tests passing
1 parent c27070a commit 1e90ba3

File tree

5 files changed

+76
-75
lines changed

5 files changed

+76
-75
lines changed

src/editor.test.ts

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ describe('editor', () => {
2626
vitest
2727
.spyOn(envModule, 'getEnvironmentVariables')
2828
.mockReturnValue({ EDITOR: 'editor' });
29-
when(vitest.spyOn(miscUtils, 'resolveExecutable'))
30-
.calledWith('editor')
31-
.thenResolve(null);
32-
when(vitest.spyOn(miscUtils, 'resolveExecutable'))
29+
const resolveExecutableSpy = vitest.spyOn(miscUtils, 'resolveExecutable');
30+
when(resolveExecutableSpy).calledWith('editor').thenResolve(null);
31+
when(resolveExecutableSpy)
3332
.calledWith('code')
3433
.thenResolve('/path/to/code');
3534

@@ -43,12 +42,9 @@ describe('editor', () => {
4342
vitest
4443
.spyOn(envModule, 'getEnvironmentVariables')
4544
.mockReturnValue({ EDITOR: 'editor' });
46-
when(vitest.spyOn(miscUtils, 'resolveExecutable'))
47-
.calledWith('editor')
48-
.thenResolve(null);
49-
when(vitest.spyOn(miscUtils, 'resolveExecutable'))
50-
.calledWith('code')
51-
.thenResolve(null);
45+
const resolveExecutableSpy = vitest.spyOn(miscUtils, 'resolveExecutable');
46+
when(resolveExecutableSpy).calledWith('editor').thenResolve(null);
47+
when(resolveExecutableSpy).calledWith('code').thenResolve(null);
5248

5349
expect(await determineEditor()).toBeNull();
5450
});
@@ -57,10 +53,9 @@ describe('editor', () => {
5753
vitest
5854
.spyOn(envModule, 'getEnvironmentVariables')
5955
.mockReturnValue({ EDITOR: 'editor' });
60-
when(vitest.spyOn(miscUtils, 'resolveExecutable'))
61-
.calledWith('editor')
62-
.thenResolve(null);
63-
when(vitest.spyOn(miscUtils, 'resolveExecutable'))
56+
const resolveExecutableSpy = vitest.spyOn(miscUtils, 'resolveExecutable');
57+
when(resolveExecutableSpy).calledWith('editor').thenResolve(null);
58+
when(resolveExecutableSpy)
6459
.calledWith('code')
6560
.thenReject(new Error('some error'));
6661

@@ -71,12 +66,11 @@ describe('editor', () => {
7166
vitest
7267
.spyOn(envModule, 'getEnvironmentVariables')
7368
.mockReturnValue({ EDITOR: 'editor' });
74-
when(vitest.spyOn(miscUtils, 'resolveExecutable'))
69+
const resolveExecutableSpy = vitest.spyOn(miscUtils, 'resolveExecutable');
70+
when(resolveExecutableSpy)
7571
.calledWith('editor')
7672
.thenReject(new Error('some error'));
77-
when(vitest.spyOn(miscUtils, 'resolveExecutable'))
78-
.calledWith('code')
79-
.thenResolve(null);
73+
when(resolveExecutableSpy).calledWith('code').thenResolve(null);
8074

8175
expect(await determineEditor()).toBeNull();
8276
});
@@ -85,10 +79,11 @@ describe('editor', () => {
8579
vitest
8680
.spyOn(envModule, 'getEnvironmentVariables')
8781
.mockReturnValue({ EDITOR: 'editor' });
88-
when(vitest.spyOn(miscUtils, 'resolveExecutable'))
82+
const resolveExecutableSpy = vitest.spyOn(miscUtils, 'resolveExecutable');
83+
when(resolveExecutableSpy)
8984
.calledWith('editor')
9085
.thenReject(new Error('some error'));
91-
when(vitest.spyOn(miscUtils, 'resolveExecutable'))
86+
when(resolveExecutableSpy)
9287
.calledWith('code')
9388
.thenReject(new Error('some error'));
9489

src/fs.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,15 @@ describe('fs', () => {
202202

203203
await expect(
204204
fs.promises.readdir(path.join(sandbox.directoryPath, 'foo')),
205-
).toResolve();
205+
).toBeDefined();
206206
await expect(
207207
fs.promises.readdir(path.join(sandbox.directoryPath, 'foo', 'bar')),
208-
).toResolve();
208+
).toBeDefined();
209209
await expect(
210210
fs.promises.readdir(
211211
path.join(sandbox.directoryPath, 'foo', 'bar', 'baz'),
212212
),
213-
).toResolve();
213+
).toBeDefined();
214214
});
215215
});
216216

@@ -228,7 +228,7 @@ describe('fs', () => {
228228
path.join(sandbox.directoryPath, 'foo', 'bar', 'baz'),
229229
);
230230

231-
await expect(ensureDirectoryPathExists(directoryPath)).toResolve();
231+
await expect(ensureDirectoryPathExists(directoryPath)).toBeDefined();
232232
});
233233
});
234234

src/project.test.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ describe('project', () => {
7575
vitest
7676
.spyOn(actionUtils, 'getWorkspaceLocations')
7777
.mockResolvedValue(['packages/a', 'packages/subpackages/b']);
78-
when(vitest.spyOn(packageModule, 'readMonorepoWorkspacePackage'))
78+
const readMonorepoWorkspacePackageSpy = vitest.spyOn(
79+
packageModule,
80+
'readMonorepoWorkspacePackage',
81+
);
82+
when(readMonorepoWorkspacePackageSpy)
7983
.calledWith({
8084
packageDirectoryPath: path.join(
8185
projectDirectoryPath,
@@ -89,7 +93,7 @@ describe('project', () => {
8993
stderr,
9094
})
9195
.thenResolve(workspacePackages.a);
92-
when(vitest.spyOn(packageModule, 'readMonorepoWorkspacePackage'))
96+
when(readMonorepoWorkspacePackageSpy)
9397
.calledWith({
9498
packageDirectoryPath: path.join(
9599
projectDirectoryPath,
@@ -127,6 +131,7 @@ describe('project', () => {
127131
});
128132
});
129133
});
134+
130135
describe('restoreChangelogsForSkippedPackages', () => {
131136
it('should reset changelog for packages with changes not included in release', async () => {
132137
const project = buildMockProject({
@@ -146,11 +151,13 @@ describe('project', () => {
146151

147152
const restoreFilesSpy = vitest.spyOn(repoModule, 'restoreFiles');
148153

149-
when(vitest.spyOn(fs, 'fileExists'))
154+
const fileExistsSpy = vitest.spyOn(fs, 'fileExists');
155+
156+
when(fileExistsSpy)
150157
.calledWith(project.workspacePackages.b.changelogPath)
151158
.thenResolve(true);
152159

153-
when(vitest.spyOn(fs, 'fileExists'))
160+
when(fileExistsSpy)
154161
.calledWith(project.workspacePackages.c.changelogPath)
155162
.thenResolve(true);
156163

src/repo.test.ts

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -40,43 +40,29 @@ describe('repo', () => {
4040
);
4141
});
4242

43-
it('throws if the URL of the "origin" remote is in an invalid format', async () => {
44-
const repositoryDirectoryPath = '/path/to/project';
45-
when(vitest.spyOn(miscUtils, 'getStdoutFromCommand'))
46-
.calledWith('git', ['config', '--get', 'remote.origin.url'], {
47-
cwd: repositoryDirectoryPath,
48-
})
49-
// TODO: `vitest-when` doesn't have a `thenResolveOnce` method.
50-
.mockResolvedValueOnce('foo')
51-
.mockResolvedValueOnce('http://github.com/Foo/Bar')
52-
.mockResolvedValueOnce('https://gitbar.foo/Foo/Bar')
53-
.mockResolvedValueOnce('[email protected]:Foo/Bar.git')
54-
.mockResolvedValueOnce('[email protected]:Foo/Bar.foo');
55-
56-
await expect(
57-
getRepositoryHttpsUrl(repositoryDirectoryPath),
58-
).rejects.toThrow('Unrecognized URL for git remote "origin": foo');
59-
await expect(
60-
getRepositoryHttpsUrl(repositoryDirectoryPath),
61-
).rejects.toThrow(
62-
'Unrecognized URL for git remote "origin": http://github.com/Foo/Bar',
63-
);
64-
await expect(
65-
getRepositoryHttpsUrl(repositoryDirectoryPath),
66-
).rejects.toThrow(
67-
'Unrecognized URL for git remote "origin": https://gitbar.foo/Foo/Bar',
68-
);
69-
await expect(
70-
getRepositoryHttpsUrl(repositoryDirectoryPath),
71-
).rejects.toThrow(
72-
'Unrecognized URL for git remote "origin": [email protected]:Foo/Bar.git',
73-
);
74-
await expect(
75-
getRepositoryHttpsUrl(repositoryDirectoryPath),
76-
).rejects.toThrow(
77-
'Unrecognized URL for git remote "origin": [email protected]:Foo/Bar.foo',
78-
);
79-
});
43+
it.each([
44+
'foo',
45+
'http://github.com/Foo/Bar',
46+
'https://gitbar.foo/Foo/Bar',
47+
'[email protected]:Foo/Bar.git',
48+
'[email protected]:Foo/Bar.foo',
49+
])(
50+
'throws if the URL of the "origin" remote is in the invalid format "%s"',
51+
async (originUrl) => {
52+
const repositoryDirectoryPath = '/path/to/project';
53+
when(vitest.spyOn(miscUtils, 'getStdoutFromCommand'))
54+
.calledWith('git', ['config', '--get', 'remote.origin.url'], {
55+
cwd: repositoryDirectoryPath,
56+
})
57+
.thenResolve(originUrl);
58+
59+
await expect(
60+
getRepositoryHttpsUrl(repositoryDirectoryPath),
61+
).rejects.toThrow(
62+
`Unrecognized URL for git remote "origin": ${originUrl}`,
63+
);
64+
},
65+
);
8066
});
8167

8268
describe('commitAllChanges', () => {

vitest.config.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,19 @@ import { defineConfig } from 'vitest/config';
22

33
export default defineConfig({
44
test: {
5-
watch: false,
6-
7-
// Vitest doesn't inject the globals by default. We enable this option to
8-
// inject the globals like `describe`, `it`, `expect`, etc.
9-
globals: true,
10-
115
coverage: {
126
enabled: true,
137

14-
// Configure the coverage provider. We use `istanbul` here, because it
15-
// is more stable than `v8`.
16-
provider: 'istanbul',
17-
188
// Only include source files in the `src` directory.
199
include: ['src/**/*.test.ts'],
2010

2111
// Exclude certain files from the coverage.
2212
exclude: ['node_modules/', 'src/cli.ts', 'src/command-line-arguments.ts'],
2313

14+
// Configure the coverage provider. We use `istanbul` here, because it
15+
// is more stable than `v8`.
16+
provider: 'istanbul',
17+
2418
// Hide files with 100% coverage.
2519
skipFull: true,
2620

@@ -30,11 +24,30 @@ export default defineConfig({
3024
// Auto-update the coverage thresholds.
3125
autoUpdate: true,
3226

27+
// These should be set to 100 at all times.
3328
branches: 100,
3429
functions: 100,
3530
lines: 100,
3631
statements: 100,
3732
},
3833
},
34+
35+
// Vitest doesn't inject the globals by default. We enable this option to
36+
// inject the globals like `describe`, `it`, `expect`, etc.
37+
globals: true,
38+
39+
// Calls .mockReset on all spies before each test.
40+
mockReset: true,
41+
42+
// Calls .mockRestore on all spies before each test.
43+
restoreMocks: true,
44+
45+
// Calls vi.unstubAllEnvs before each test.
46+
unstubEnvs: true,
47+
48+
// Calls vi.unstubGlobals before each test.
49+
unstubGlobals: true,
50+
51+
watch: false,
3952
},
4053
});

0 commit comments

Comments
 (0)