diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a9c3678..39f4295f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ #Changelog +###1.0.8 +- Only copy external assets if they do not already exist [mochawesome #76](https://github.com/adamgruber/mochawesome/issues/76) + ###1.0.7 - Fix an issue where test context could not be viewed if `enableCode` option was `false`. [mochawesome #132](https://github.com/adamgruber/mochawesome/issues/132) - Add an icon to indicate when a test has context diff --git a/lib/main.js b/lib/main.js index afe534ad..28399560 100644 --- a/lib/main.js +++ b/lib/main.js @@ -94,9 +94,11 @@ function getAssets() { */ function copyAssets(opts) { - // Copy the assets to the report location + // Copy the assets to the report location if they don't exist var assetsDir = path.join(opts.reportDir, 'assets'); - fs.copySync(externalAssetsDir, assetsDir); + if (!fs.existsSync(assetsDir)) { + fs.copySync(externalAssetsDir, assetsDir); + } } /** diff --git a/lib/src/main.js b/lib/src/main.js index 6126f732..7d22507c 100644 --- a/lib/src/main.js +++ b/lib/src/main.js @@ -90,9 +90,11 @@ function getAssets() { */ function copyAssets(opts) { - // Copy the assets to the report location + // Copy the assets to the report location if they don't exist const assetsDir = path.join(opts.reportDir, 'assets'); - fs.copySync(externalAssetsDir, assetsDir); + if (!fs.existsSync(assetsDir)) { + fs.copySync(externalAssetsDir, assetsDir); + } } /** diff --git a/package.json b/package.json index 15635936..bc9d4e34 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mochawesome-report-generator", - "version": "1.0.7", + "version": "1.0.8", "description": "Generates gorgeous HTML reports from mochawesome reporter.", "scripts": { "lint": "eslint bin lib src/js src/components/**/*.js src/components/**/*.jsx test/**/*.js test/**/*.jsx", diff --git a/test/spec/lib/main.test.js b/test/spec/lib/main.test.js index b8e43768..9c6ab088 100644 --- a/test/spec/lib/main.test.js +++ b/test/spec/lib/main.test.js @@ -14,12 +14,14 @@ const outputFileSyncStub = sinon.stub(); const copySyncStub = sinon.stub(); const readFileSyncStub = sinon.stub(); const openerStub = sinon.stub(); +const existsSyncStub = sinon.stub(); const mareport = proxyquire('../../../lib/src/main', { 'fs-extra': { outputFile: outputFileStub, outputFileSync: outputFileSyncStub, copySync: copySyncStub, - readFileSync: readFileSyncStub + readFileSync: readFileSyncStub, + existsSync: existsSyncStub }, opener: openerStub }); @@ -98,6 +100,12 @@ describe('lib/main', () => { expect(copySyncStub.called).to.equal(true); }); + it('doesn\'t copy assets if assetsDir already exists', () => { + existsSyncStub.returns(true); + mareport.createSync(testData, { inlineAssets: false }); + expect(copySyncStub.called).to.equal(false); + }); + it('inlines assets', () => { mareport.createSync(testData, { inlineAssets: true }); expect(readFileSyncStub.called).to.equal(true);