22
33// setup
44import test from 'ava'
5+ import { resolve , join } from 'path'
56import { rollup } from 'rollup'
67// import { rollup as rollup59 } from 'rollup59'
78import analyzer , { init , formatted , analyze } from './../index'
9+ const fixtures = resolve ( __dirname , 'fixtures' )
810const 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
2116test ( `analyzer returns {init, formatted, analyze}` , ( assert ) => {
@@ -32,16 +27,19 @@ test(`analyzer() returns {init, formatted, analyze}`, (assert) => {
3227} )
3328
3429test ( `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
3935test ( `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
4441test ( `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
5250test ( `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
6463test ( `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
7272test ( `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
8081test ( `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
9496test . 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