|
| 1 | +import { execSync } from 'child_process'; |
| 2 | + |
1 | 3 | import headlessConfig from './release-headless.config'; |
2 | 4 | import toolsConfig from './release-tools.config'; |
3 | 5 | import v8Config from './release-v8.config'; |
4 | 6 | import vNextConfig from './release-vNext.config'; |
5 | 7 | import webComponentsConfig from './release-web-components.config'; |
6 | 8 | import { config as sharedConfig } from './shared.config'; |
7 | 9 |
|
| 10 | +jest.mock('child_process', () => ({ |
| 11 | + ...jest.requireActual<typeof import('child_process')>('child_process'), |
| 12 | + execSync: jest.fn(), |
| 13 | +})); |
| 14 | + |
8 | 15 | describe(`beachball configs`, () => { |
9 | 16 | const excludedPackagesFromReleaseProcess = ['!packages/fluentui/*']; |
| 17 | + const execSyncMock = jest.mocked(execSync); |
| 18 | + const precommit = sharedConfig.hooks.precommit; |
| 19 | + |
| 20 | + if (!precommit) { |
| 21 | + throw new Error('Expected the shared Beachball config to define a precommit hook'); |
| 22 | + } |
| 23 | + |
| 24 | + beforeEach(() => { |
| 25 | + execSyncMock.mockReset(); |
| 26 | + execSyncMock.mockReturnValue(Buffer.from('')); |
| 27 | + }); |
10 | 28 |
|
11 | 29 | it(`should generate shared config`, () => { |
12 | 30 | expect(sharedConfig).toEqual({ |
@@ -48,6 +66,30 @@ describe(`beachball configs`, () => { |
48 | 66 | }); |
49 | 67 | }); |
50 | 68 |
|
| 69 | + it(`should normalize package dependencies and update the lockfile before committing`, () => { |
| 70 | + precommit(process.cwd()); |
| 71 | + |
| 72 | + expect(execSyncMock.mock.calls).toEqual([ |
| 73 | + ['yarn nx g @fluentui/workspace-plugin:dependency-mismatch'], |
| 74 | + ['yarn nx g @fluentui/workspace-plugin:normalize-package-dependencies'], |
| 75 | + ['yarn install --mode=update-lockfile'], |
| 76 | + ]); |
| 77 | + }); |
| 78 | + |
| 79 | + it(`should log precommit finalization failures`, () => { |
| 80 | + const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(); |
| 81 | + const error = new Error('dependency normalization failed'); |
| 82 | + execSyncMock.mockImplementationOnce(() => { |
| 83 | + throw error; |
| 84 | + }); |
| 85 | + |
| 86 | + expect(() => precommit(process.cwd())).not.toThrow(); |
| 87 | + expect(consoleErrorSpy).toHaveBeenCalledWith(error); |
| 88 | + expect(execSyncMock).toHaveBeenCalledTimes(1); |
| 89 | + |
| 90 | + consoleErrorSpy.mockRestore(); |
| 91 | + }); |
| 92 | + |
51 | 93 | it(`should generate v8 release config`, () => { |
52 | 94 | expect(v8Config.scope).toEqual( |
53 | 95 | expect.arrayContaining([ |
|
0 commit comments