Skip to content
This repository has been archived by the owner on Sep 20, 2022. It is now read-only.

reuse-loader: use report archive with files (not report dir itself) #109

Merged
merged 1 commit into from
Mar 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions lib/reuse-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@ const downloadReport = (reuseUrl) => {
return new LargeDownload({link: reuseUrl, destination: archivePath, retries: 3})
.load()
.then(() => extract(archivePath, tempDir))
// tempDir at this moment contains only report archive and unpacked report in some directory
.then(() => {
const reportDirName = fs.readdirSync(tempDir)
.filter((f) => fs.statSync(path.resolve(tempDir, f)).isDirectory())[0];

return path.resolve(tempDir, reportDirName);
});
.then(() => tempDir);
};

const prepareReport = (urlOrPath) => {
Expand Down
11 changes: 5 additions & 6 deletions test/reuse-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ describe('lib/reuse-loader', () => {

return proxyquire('../lib/reuse-loader', {
'large-download': opts.largeDownload || mkLargeDownload(),
'temp': {
track: () => ({mkdirSync: sinon.stub().returns('/tmp')})
},
'./utils': {
decompress: opts.decompress || sinon.stub().returns(Promise.resolve()),
Error: utils.Error
Expand Down Expand Up @@ -116,18 +119,14 @@ describe('lib/reuse-loader', () => {
);
});

it('should choose folder from temp dir for reuse', () => {
it('should use temp dir for reuse', () => {
const loadReuseData = requireReuseDataFunc();
stubModules();
temp.mkdirSync.returns('/tempdir');
fs.readdirSync.returns(['r-archive', 'r-dir']);
path.resolve.withArgs('/tempdir', 'r-dir').returns('/temp/r-dir');
fs.statSync.withArgs('/temp/r-dir').returns({isDirectory: () => true});

return loadReuseData('url')
.then((reuseData) => {
assert.isDefined(reuseData);
assert.equal(reuseData.report, '/temp/r-dir');
assert.equal(reuseData.report, '/tmp');
});
});
});