Skip to content

Commit ec1693b

Browse files
committed
test(util): update tests
1 parent 7efa837 commit ec1693b

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/__tests__/if-merge/util/helpers.test.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ jest.mock('../../../if-run/builtins/export-yaml', () => ({
3939
if (process.env.CONTEXT !== 'default-name-description') {
4040
expectedContext.name = 'mock name';
4141
expectedContext.description = 'mock description';
42-
expect(outputPath).toBe('mock-dir/mock-name.yaml');
42+
expect(outputPath).toBe('mock-outputPath');
4343
} else {
44-
expect(outputPath).toBe('mock-dir/merged-manifest.yaml');
44+
expect(outputPath).toBe('mock-outputPath');
4545
}
4646

4747
expect(context).toEqual(expectedContext);
@@ -50,9 +50,16 @@ jest.mock('../../../if-run/builtins/export-yaml', () => ({
5050
}));
5151

5252
describe('if-merge/util/helpers: ', () => {
53+
const consopleSpy = jest.spyOn(global.console, 'log');
54+
55+
beforeEach(() => {
56+
consopleSpy.mockReset();
57+
});
58+
5359
describe('mergeManifests(): ', () => {
5460
const mockCommandArgs = {
5561
manifests: ['manifest1.yaml', 'manifest2.yaml'],
62+
output: 'mock-outputPath',
5663
name: 'mock name',
5764
description: 'mock description',
5865
};
@@ -128,9 +135,27 @@ describe('if-merge/util/helpers: ', () => {
128135
expect(load).toHaveBeenCalledTimes(2);
129136
});
130137

138+
it('successfully prints merged manifests when the `output` is not provided.', async () => {
139+
(getFileName as jest.Mock).mockImplementation(file =>
140+
file.replace('.yaml', '')
141+
);
142+
(load as jest.Mock).mockResolvedValue({rawManifest: mockRawManifest});
143+
144+
const mockCommandArgs = {
145+
manifests: ['manifest1.yaml', 'manifest2.yaml'],
146+
name: 'mock name',
147+
description: 'mock description',
148+
};
149+
await mergeManifests(mockCommandArgs);
150+
151+
expect.assertions(1);
152+
expect(consopleSpy).toHaveBeenCalledTimes(1);
153+
});
154+
131155
it('gets YAML files when there is only one manifest.', async () => {
132156
const singleManifestArgs = {
133157
manifests: ['mock-dir'],
158+
output: 'mock-outputPath',
134159
name: 'mock name',
135160
description: 'mock description',
136161
};
@@ -153,7 +178,10 @@ describe('if-merge/util/helpers: ', () => {
153178
it('uses default values for name and description if not provided.', async () => {
154179
process.env.CONTEXT = 'default-name-description';
155180

156-
const defaultArgs = {manifests: ['manifest1.yaml', 'manifest2.yaml']};
181+
const defaultArgs = {
182+
manifests: ['manifest1.yaml', 'manifest2.yaml'],
183+
output: 'mock-outputPath',
184+
};
157185

158186
(getFileName as jest.Mock).mockImplementation(file =>
159187
file.replace('.yaml', '')

0 commit comments

Comments
 (0)