Skip to content

Commit

Permalink
fix: Avoid corrupting HTML report's arrow png during copy (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeapage authored and coreyfarrell committed Apr 2, 2019
1 parent c81b051 commit ce664c7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/istanbul-lib-report/lib/file-writer.js
Expand Up @@ -165,7 +165,13 @@ FileWriter.prototype.copyFile = function(source, dest, header) {
}
dest = path.resolve(this.baseDir, dest);
mkdirp.sync(path.dirname(dest));
fs.writeFileSync(dest, (header || '') + fs.readFileSync(source));
let contents;
if (header) {
contents = header + fs.readFileSync(source, 'utf8');
} else {
contents = fs.readFileSync(source);
}
fs.writeFileSync(dest, contents);
};
/**
* returns a content writer for writing content to the supplied file.
Expand Down
13 changes: 13 additions & 0 deletions packages/istanbul-lib-report/test/file-writer.test.js
Expand Up @@ -47,6 +47,19 @@ describe('file-writer', () => {
);
});

it('copies binary files', () => {
const testBuffer = Buffer.from([195, 40]);
fs.writeFileSync(path.resolve(dataDir, 'in.bin'), testBuffer);
writer.copyFile(path.resolve(dataDir, 'in.bin'), 'out.bin');
assert.equal(
Buffer.compare(
fs.readFileSync(path.resolve(dataDir, 'out.bin')),
testBuffer
),
0
);
});

it('copies files while adding headers', () => {
const header =
'/* This is some header text, like a copyright or directive. */\n';
Expand Down

0 comments on commit ce664c7

Please sign in to comment.