Skip to content

Commit 4f9f437

Browse files
committed
Bundle with each test
1 parent 2767bfc commit 4f9f437

1 file changed

Lines changed: 19 additions & 16 deletions

File tree

test/index.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,15 @@
22

33
// setup
44
import test from 'ava'
5+
import { resolve, join } from 'path'
56
import { rollup } from 'rollup'
67
// import { rollup as rollup59 } from 'rollup59'
78
import analyzer, { init, formatted, analyze } from './../index'
9+
const fixtures = resolve(__dirname, 'fixtures')
810
const baseOpts = {
9-
input: 'module.js',
11+
input: join(fixtures, 'bundle.js'),
1012
output: {format: 'cjs'}
1113
}
12-
let bundle, bundleToo
13-
14-
// create the bundle
15-
test.before(async () => {
16-
bundle = await rollup(baseOpts)
17-
bundleToo = await rollup({input: 'test/fixtures/bundle.js', output: {format: 'cjs'}})
18-
})
1914

2015
// main
2116
test(`analyzer returns {init, formatted, analyze}`, (assert) => {
@@ -32,16 +27,19 @@ test(`analyzer() returns {init, formatted, analyze}`, (assert) => {
3227
})
3328

3429
test(`formatted returns string`, async (assert) => {
30+
let bundle = await rollup(baseOpts)
3531
let results = await formatted(bundle)
3632
assert.is(typeof results, 'string')
3733
})
3834

3935
test(`analyze returns array`, async (assert) => {
36+
let bundle = await rollup(baseOpts)
4037
let results = await analyze(bundle)
4138
assert.true(Array.isArray(results))
4239
})
4340

4441
test(`analysis child objects have expected properties`, async (assert) => {
42+
let bundle = await rollup(baseOpts)
4543
let result = (await analyze(bundle))[0]
4644
assert.true('id' in result)
4745
assert.true('size' in result)
@@ -50,6 +48,7 @@ test(`analysis child objects have expected properties`, async (assert) => {
5048
})
5149

5250
test(`limit works and opts are set the same via init or analyzer`, async (assert) => {
51+
let bundle = await rollup(baseOpts)
5352
init({limit: 0})
5453
assert.is((await analyze(bundle)).length, 0)
5554
init({limit: 1})
@@ -62,37 +61,41 @@ test(`limit works and opts are set the same via init or analyzer`, async (assert
6261
})
6362

6463
test(`filter with array works`, async (assert) => {
64+
let bundle = await rollup(baseOpts)
6565
init({filter: ['jimmy', 'jerry']})
6666
assert.is((await analyze(bundle)).length, 0)
67-
init({filter: ['module', 'jessie']})
67+
init({filter: ['import-a', 'jessie']})
6868
assert.is((await analyze(bundle)).length, 1)
6969
init({filter: undefined})
7070
})
7171

7272
test(`filter with string works`, async (assert) => {
73+
let bundle = await rollup(baseOpts)
7374
init({filter: 'jimmy'})
7475
assert.is((await analyze(bundle)).length, 0)
75-
init({filter: 'module'})
76+
init({filter: 'import-b'})
7677
assert.is((await analyze(bundle)).length, 1)
7778
init({filter: undefined})
7879
})
7980

8081
test(`root works as expected`, async (assert) => {
82+
let bundle = await rollup(baseOpts)
8183
init({root: 'fakepath'})
8284
assert.not(
83-
(await analyze(bundle))[0].id.replace(/\\|\//g, ''),
84-
'module.js'
85+
join(__dirname, (await analyze(bundle))[0].id),
86+
resolve(fixtures, 'import-a.js')
8587
)
86-
init({root: process.cwd()})
88+
init({root: __dirname})
8789
assert.is(
88-
(await analyze(bundle))[0].id.replace(/\\|\//g, ''),
89-
'module.js'
90+
join(__dirname, (await analyze(bundle))[0].id),
91+
resolve(fixtures, 'import-a.js')
9092
)
9193
init({root: undefined})
9294
})
9395

9496
test.failing(`tree shaking is accounted for`, async (assert) => {
95-
let results = await analyze(bundleToo)
97+
let bundle = await rollup(baseOpts)
98+
let results = await analyze(bundle)
9699
let imported = results.find((r) => r.id.match('importme'))
97100
assert.is(imported.size, 4)
98101
})

0 commit comments

Comments
 (0)