Skip to content
This repository has been archived by the owner on Aug 5, 2021. It is now read-only.

Commit

Permalink
chore(tests): make tests 1.0 compatible
Browse files Browse the repository at this point in the history
This will make the tests compatible with version 1.0. Note that this
there is still a change needed in rollup to properly sanitize chunk ids
  • Loading branch information
lukastaegert committed Dec 10, 2018
1 parent 86c1f3c commit a30239d
Showing 1 changed file with 44 additions and 62 deletions.
106 changes: 44 additions & 62 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import multiEntry from '../';
import { ok } from 'assert';
import { rollup } from 'rollup';
import multiEntry from '../';

function includes(string, substring) {
if (string.indexOf(substring) === -1) {
Expand All @@ -24,79 +24,61 @@ function doesNotInclude(string, substring) {
}
}

function makeBundle(entries) {
return rollup({ input: entries, plugins: [multiEntry()] });
function getCodeFromBundle(entries) {
return rollup({ input: entries, plugins: [multiEntry()] })
.then(bundle => bundle.generate({ format: 'cjs' }))
.then(generated =>
generated.output ? generated.output[0].code : generated.code
);
}

describe('rollup-plugin-multi-entry', () => {
it('takes a single file as input', () => {
return makeBundle('test/fixtures/0.js').then(bundle => {
return bundle.generate({ format: 'cjs' }).then(({ code }) => {
includes(code, 'exports.zero = zero;');
});
});
});
it('takes a single file as input', () =>
getCodeFromBundle('test/fixtures/0.js').then(code =>
includes(code, 'exports.zero = zero;')
));

it('takes an array of files as input', () => {
return makeBundle(['test/fixtures/0.js', 'test/fixtures/1.js']).then(
bundle => {
return bundle.generate({ format: 'cjs' }).then(({ code }) => {
includes(code, 'exports.zero = zero;');
includes(code, 'exports.one = one;');
});
it('takes an array of files as input', () =>
getCodeFromBundle(['test/fixtures/0.js', 'test/fixtures/1.js']).then(
code => {
includes(code, 'exports.zero = zero;');
includes(code, 'exports.one = one;');
}
);
});
));

it('allows an empty array as input', () => {
return makeBundle([]).then(bundle => {
return bundle.generate({ format: 'cjs' }).then(({ code }) => {
doesNotInclude(code, 'exports');
});
});
});
it('allows an empty array as input', () =>
getCodeFromBundle([]).then(code => doesNotInclude(code, 'exports')));

it('takes a glob as input', () => {
return makeBundle('test/fixtures/{0,1}.js').then(bundle => {
return bundle.generate({ format: 'cjs' }).then(({ code }) => {
it('takes a glob as input', () =>
getCodeFromBundle('test/fixtures/{0,1}.js').then(code => {
includes(code, 'exports.zero = zero;');
includes(code, 'exports.one = one;');
}));

it('takes an array of globs as input', () =>
getCodeFromBundle(['test/fixtures/{0,}.js', 'test/fixtures/{1,}.js']).then(
code => {
includes(code, 'exports.zero = zero;');
includes(code, 'exports.one = one;');
});
});
});

it('takes an array of globs as input', () => {
return makeBundle(['test/fixtures/{0,}.js', 'test/fixtures/{1,}.js']).then(
bundle => {
return bundle.generate({ format: 'cjs' }).then(({ code }) => {
includes(code, 'exports.zero = zero;');
includes(code, 'exports.one = one;');
});
}
);
});
));

it('takes an {include,exclude} object as input', () => {
return makeBundle({
it('takes an {include,exclude} object as input', () =>
getCodeFromBundle({
include: ['test/fixtures/*.js'],
exclude: ['test/fixtures/1.js']
}).then(bundle => {
return bundle.generate({ format: 'cjs' }).then(({ code }) => {
includes(code, 'exports.zero = zero;');
doesNotInclude(code, 'exports.one = one;');
});
});
});
}).then(code => {
includes(code, 'exports.zero = zero;');
doesNotInclude(code, 'exports.one = one;');
}));

it('allows to prevent exporting', () => {
return makeBundle({ include: ['test/fixtures/*.js'], exports: false }).then(
bundle => {
return bundle.generate({ format: 'cjs' }).then(({ code }) => {
includes(code, `console.log('Hello, 2');`);
doesNotInclude(code, 'zero');
doesNotInclude(code, 'one');
});
}
);
});
it('allows to prevent exporting', () =>
getCodeFromBundle({
include: ['test/fixtures/*.js'],
exports: false
}).then(code => {
includes(code, `console.log('Hello, 2');`);
doesNotInclude(code, 'zero');
doesNotInclude(code, 'one');
}));
});

0 comments on commit a30239d

Please sign in to comment.