From 513bd8bb44388b9d09c15f79f0b09b1ffdf1cfb6 Mon Sep 17 00:00:00 2001 From: Andrew Carpenter Date: Wed, 11 Jul 2018 00:12:18 -0400 Subject: [PATCH] Add test to ensure plugin isn't adding overhead --- test/test.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/test.js b/test/test.js index d9a07b8..071ca8e 100644 --- a/test/test.js +++ b/test/test.js @@ -199,4 +199,34 @@ rollers.forEach(({rollup, version, opts, noTreeshake}) => { assert.is(count, 1) }) } + + if (version === 'latest') { + test(`${version}: plugin shouldn't cause much overhead`, async (assert) => { + let start + let runs = 20 + let msDiffThreshold = 50 + + // bundle without plugin in use + start = Date.now() + for (let i = 0; i < runs; i++) { + let bundle = await rollup(opts) + await bundle.generate({format: 'cjs'}) + } + let noPlugin = (Date.now() - start) / runs + + // now with the plugin + let count = 0 + let writeTo = (r) => ++count + let rollOpts = Object.assign({plugins: [plugin({writeTo})]}, opts) + start = Date.now() + for (let i = 0; i < runs; i++) { + let bundle = await rollup(rollOpts) + await bundle.generate({format: 'cjs'}) + } + let withPlugin = (Date.now() - start) / runs + + assert.is(count, runs) + assert.true((withPlugin - noPlugin) < msDiffThreshold) + }) + } })