Skip to content

Commit b52c793

Browse files
committed
Tests against many rollup versions >= 0.40.x
1 parent 4f9f437 commit b52c793

1 file changed

Lines changed: 89 additions & 68 deletions

File tree

test/index.js

Lines changed: 89 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,24 @@
33
// setup
44
import test from 'ava'
55
import { resolve, join } from 'path'
6-
import { rollup } from 'rollup'
7-
// import { rollup as rollup59 } from 'rollup59'
6+
import { rollup as rollupLatest } from 'rollup'
7+
import { rollup as rollup59 } from 'rollup59'
8+
import { rollup as rollup55 } from 'rollup55'
9+
import { rollup as rollup50 } from 'rollup50'
10+
import { rollup as rollup45 } from 'rollup45'
11+
import { rollup as rollup40 } from 'rollup40'
812
import analyzer, { init, formatted, analyze } from './../index'
913
const fixtures = resolve(__dirname, 'fixtures')
1014
const baseOpts = {
1115
input: join(fixtures, 'bundle.js'),
1216
output: {format: 'cjs'}
1317
}
18+
const oldOpts = {
19+
entry: join(fixtures, 'bundle.js'),
20+
format: 'cjs'
21+
}
1422

15-
// main
23+
// general API conformity tests
1624
test(`analyzer returns {init, formatted, analyze}`, (assert) => {
1725
assert.is(analyzer.init, init)
1826
assert.is(analyzer.formatted, formatted)
@@ -26,76 +34,89 @@ test(`analyzer() returns {init, formatted, analyze}`, (assert) => {
2634
assert.is(optedAnalyzer.analyze, analyze)
2735
})
2836

29-
test(`formatted returns string`, async (assert) => {
30-
let bundle = await rollup(baseOpts)
31-
let results = await formatted(bundle)
32-
assert.is(typeof results, 'string')
33-
})
37+
// test against many versions of rollup
38+
const rollers = [
39+
{rollup: rollupLatest, version: 'latest', opts: baseOpts},
40+
{rollup: rollup59, version: '0.59.x', opts: baseOpts},
41+
{rollup: rollup55, version: '0.55.x', opts: baseOpts},
42+
{rollup: rollup50, version: '0.50.x', opts: baseOpts},
43+
{rollup: rollup45, version: '0.45.x', opts: oldOpts},
44+
{rollup: rollup40, version: '0.40.x', opts: oldOpts}
45+
]
3446

35-
test(`analyze returns array`, async (assert) => {
36-
let bundle = await rollup(baseOpts)
37-
let results = await analyze(bundle)
38-
assert.true(Array.isArray(results))
39-
})
47+
// main
48+
rollers.forEach(({rollup, version, opts}) => {
49+
test(`${version}: formatted returns string`, async (assert) => {
50+
let bundle = await rollup(opts)
51+
let results = await formatted(bundle)
52+
assert.is(typeof results, 'string')
53+
})
4054

41-
test(`analysis child objects have expected properties`, async (assert) => {
42-
let bundle = await rollup(baseOpts)
43-
let result = (await analyze(bundle))[0]
44-
assert.true('id' in result)
45-
assert.true('size' in result)
46-
assert.true('dependents' in result)
47-
assert.true('percent' in result)
48-
})
55+
test(`${version}: analyze returns array`, async (assert) => {
56+
let bundle = await rollup(opts)
57+
let results = await analyze(bundle)
58+
assert.true(Array.isArray(results))
59+
})
4960

50-
test(`limit works and opts are set the same via init or analyzer`, async (assert) => {
51-
let bundle = await rollup(baseOpts)
52-
init({limit: 0})
53-
assert.is((await analyze(bundle)).length, 0)
54-
init({limit: 1})
55-
assert.is((await analyze(bundle)).length, 1)
56-
analyzer({limit: 0})
57-
assert.is((await analyze(bundle)).length, 0)
58-
analyzer({limit: 1})
59-
assert.is((await analyze(bundle)).length, 1)
60-
init({limit: undefined})
61-
})
61+
test(`${version}: analysis child objects have expected properties`, async (assert) => {
62+
let bundle = await rollup(opts)
63+
let result = (await analyze(bundle))[0]
64+
assert.true('id' in result)
65+
assert.true('size' in result)
66+
assert.true('dependents' in result)
67+
assert.true('percent' in result)
68+
})
6269

63-
test(`filter with array works`, async (assert) => {
64-
let bundle = await rollup(baseOpts)
65-
init({filter: ['jimmy', 'jerry']})
66-
assert.is((await analyze(bundle)).length, 0)
67-
init({filter: ['import-a', 'jessie']})
68-
assert.is((await analyze(bundle)).length, 1)
69-
init({filter: undefined})
70-
})
70+
test(`${version}: limit works and opts are set the same via init or analyzer`, async (assert) => {
71+
let bundle = await rollup(opts)
72+
init({limit: 0})
73+
assert.is((await analyze(bundle)).length, 0)
74+
init({limit: 1})
75+
assert.is((await analyze(bundle)).length, 1)
76+
analyzer({limit: 0})
77+
assert.is((await analyze(bundle)).length, 0)
78+
analyzer({limit: 1})
79+
assert.is((await analyze(bundle)).length, 1)
80+
init({limit: undefined})
81+
})
7182

72-
test(`filter with string works`, async (assert) => {
73-
let bundle = await rollup(baseOpts)
74-
init({filter: 'jimmy'})
75-
assert.is((await analyze(bundle)).length, 0)
76-
init({filter: 'import-b'})
77-
assert.is((await analyze(bundle)).length, 1)
78-
init({filter: undefined})
79-
})
83+
test(`${version}: filter with array works`, async (assert) => {
84+
let bundle = await rollup(opts)
85+
init({filter: ['jimmy', 'jerry']})
86+
assert.is((await analyze(bundle)).length, 0)
87+
init({filter: ['import-a', 'jessie']})
88+
assert.is((await analyze(bundle)).length, 1)
89+
init({filter: undefined})
90+
})
8091

81-
test(`root works as expected`, async (assert) => {
82-
let bundle = await rollup(baseOpts)
83-
init({root: 'fakepath'})
84-
assert.not(
85-
join(__dirname, (await analyze(bundle))[0].id),
86-
resolve(fixtures, 'import-a.js')
87-
)
88-
init({root: __dirname})
89-
assert.is(
90-
join(__dirname, (await analyze(bundle))[0].id),
91-
resolve(fixtures, 'import-a.js')
92-
)
93-
init({root: undefined})
94-
})
92+
test(`${version}: filter with string works`, async (assert) => {
93+
let bundle = await rollup(opts)
94+
init({filter: 'jimmy'})
95+
assert.is((await analyze(bundle)).length, 0)
96+
init({filter: 'import-b'})
97+
assert.is((await analyze(bundle)).length, 1)
98+
init({filter: undefined})
99+
})
100+
101+
test(`${version}: root works as expected`, async (assert) => {
102+
let bundle = await rollup(opts)
103+
init({root: 'fakepath'})
104+
assert.not(
105+
join(__dirname, (await analyze(bundle))[0].id),
106+
resolve(fixtures, 'import-a.js')
107+
)
108+
init({root: __dirname})
109+
assert.is(
110+
join(__dirname, (await analyze(bundle))[0].id),
111+
resolve(fixtures, 'import-a.js')
112+
)
113+
init({root: undefined})
114+
})
95115

96-
test.failing(`tree shaking is accounted for`, async (assert) => {
97-
let bundle = await rollup(baseOpts)
98-
let results = await analyze(bundle)
99-
let imported = results.find((r) => r.id.match('importme'))
100-
assert.is(imported.size, 4)
116+
test.failing(`${version}: tree shaking is accounted for`, async (assert) => {
117+
let bundle = await rollup(opts)
118+
let results = await analyze(bundle)
119+
let imported = results.find((r) => r.id.match('importme'))
120+
assert.is(imported.size, 4)
121+
})
101122
})

0 commit comments

Comments
 (0)