Skip to content

Commit

Permalink
Don't try to upload assets if no session is available (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
FriggaHel authored Nov 10, 2020
1 parent 305711d commit ff373ba
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/sauce-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ SauceReporter.sauceReporter = async (buildName, browserName, assets, failures) =
console.warn('Failed to prepare test', e);
}

if (undefined === sessionId || 0 === sessionId) {
console.error('Unable to retrieve test entry. Assets won\'t be uploaded.');
return 'unable to retrieve test';
}

// upload assets
await Promise.all([
api.uploadJobAssets(
Expand Down Expand Up @@ -162,7 +167,6 @@ SauceReporter.sauceReporter = async (buildName, browserName, assets, failures) =
}

console.log(`\nOpen job details page: https://app.${domain}/tests/${sessionId}\n`);

};

SauceReporter.mergeVideos = async (videos, target) => {
Expand Down
15 changes: 14 additions & 1 deletion tests/unit/src/sauce-reporter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,24 @@ describe('SauceReporter', function () {
it('should output err when upload failed', async function () {
let consoleErrorSpy = jest.spyOn(global.console, 'error');
prepareAssetsSpy.mockReturnValue(['asset/one', 'asset/two']);
await SauceReporter.sauceReporter('build', 'browser', ['asset/one', 'asset/two']);
expect(await SauceReporter.sauceReporter('build', 'browser', ['asset/one', 'asset/two'], 0)).toBeUndefined();
expect(uploadJobAssetsSpy.mock.calls).toEqual([
['a', {'files': ['asset/one', 'asset/two']}]
]);
expect(consoleErrorSpy.mock.calls).toEqual([['some fake error']]);
});
it('should not push assets when no sessionId from SauceLabs API', async function () {
SauceLabs.default.mockImplementation(function () {
// eslint-disable-next-line require-await
this.listJobs = async () => ({
jobs: []
});
this.uploadJobAssets = uploadJobAssetsSpy;
this.updateJob = async () => {};
});

prepareAssetsSpy.mockReturnValue(['asset/one', 'asset/two']);
expect(await SauceReporter.sauceReporter('build', 'browser', ['asset/one', 'asset/two'], 0)).toBeDefined();
});
});
});

0 comments on commit ff373ba

Please sign in to comment.