Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
fix(utils): globb error is not handled silently
Browse files Browse the repository at this point in the history
closes #9
  • Loading branch information
Ron Netzer committed Mar 1, 2022
1 parent e874871 commit e5535c4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
16 changes: 12 additions & 4 deletions packages/utils/src/lib/artifact.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ jest.mock('./logger');

describe('artifact', () => {
beforeEach(() => {
(glob.create as jest.Mock).mockResolvedValue({ glob: jest.fn().mockResolvedValue(['dis/test1', 'dist/test2']) });
(glob.create as jest.Mock).mockResolvedValue({ glob: jest.fn().mockResolvedValue(['dist/test1', 'dist/test2']) });
});

it('should not upload if no paths', async () => {
await expect(uploadArtifact(glob, 'test', [])).resolves.toBeUndefined();
});

it('should not upload if not found files', async () => {
(glob.create as jest.Mock).mockResolvedValue({ glob: jest.fn().mockResolvedValue([]) });
(glob.create as jest.Mock).mockResolvedValueOnce({ glob: jest.fn().mockResolvedValue([]) });
await expect(uploadArtifact(glob, 'test', ['dist'])).resolves.toBeUndefined();
});

Expand All @@ -38,13 +38,21 @@ describe('artifact', () => {
logger().debugMode = false;
});

it('should fail globbing silently', async () => {
(glob.create as jest.Mock).mockRejectedValueOnce('error');

await uploadArtifact(glob, 'test', ['dist']);

expect(warning).toHaveBeenCalledWith('error');
});

it('should fail uploading silently', async () => {
(aCreate as jest.Mock).mockImplementationOnce(() => ({
uploadArtifact: jest.fn().mockRejectedValue('test'),
uploadArtifact: jest.fn().mockRejectedValue('error'),
}));

await uploadArtifact(glob, 'test', ['dist']);

expect(warning).toHaveBeenCalled();
expect(warning).toHaveBeenCalledWith('error');
});
});
24 changes: 12 additions & 12 deletions packages/utils/src/lib/artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ export async function uploadArtifact(glob: typeof Glob, name: string, paths: str
const globPaths = paths.map((path) => `${path}/*`).join('\n');
debug(`Upload paths: ${globPaths}`);

const files = await glob.create(globPaths).then((glob) => glob.glob());
try {
const files = await glob.create(globPaths).then((glob) => glob.glob());

if (!files.length) {
info(`Couldn't find files to upload in ${paths.join(', ')}`);
return;
}
if (!files.length) {
info(`Couldn't find files to upload in ${paths.join(', ')}`);
return;
}

debug(`Found ${files.length} files to upload`);
debug(`Found ${files.length} files to upload`);

if (logger().debugMode) {
debug(`Debug mode is on, skipping uploading artifacts`);
return;
}
if (logger().debugMode) {
debug(`Debug mode is on, skipping uploading artifacts`);
return;
}

try {
const { failedItems, artifactName, size } = await artifactClient().uploadArtifact(name, files, process.cwd());
debug(`name: ${artifactName}, size: ${size}, failedItems: ${failedItems.join(', ')}`);

debug(`name: ${artifactName}, size: ${size}, failedItems: ${failedItems.join(', ')}`);
success(`Successfully uploaded ${artifactName}`);
return artifactName;
} catch (e) {
Expand Down

0 comments on commit e5535c4

Please sign in to comment.