Skip to content

Commit

Permalink
test: add rollup integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
mjeanroy committed May 16, 2017
1 parent cee6c38 commit 07a30e7
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 0 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
"gulp-jasmine": "2.4.2",
"gulp-util": "3.0.8",
"jasmine-core": "2.6.1",
"rollup": "0.41.6",
"rollup-plugin-commonjs": "8.0.2",
"rollup-plugin-node-resolve": "3.0.0",
"run-sequence": "1.2.2",
"tmp": "0.0.31"
}
Expand Down
5 changes: 5 additions & 0 deletions test/integration/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"parserOptions": {
"sourceType": "module"
}
}
30 changes: 30 additions & 0 deletions test/integration/bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2016 Mickael Jeanroy
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

import _ from 'lodash';

// eslint-disable-next-line require-jsdoc
export function sum(array) {
return _.reduce(array, (acc, x) => acc + x, 0);
}
121 changes: 121 additions & 0 deletions test/integration/it.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2016 Mickael Jeanroy
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

'use strict';

const path = require('path');
const tmp = require('tmp');
const fs = require('fs');
const rollup = require('rollup');
const nodeResolve = require('rollup-plugin-node-resolve');
const commonjs = require('rollup-plugin-commonjs');
const licensePlugin = require('../../dist/index.js');

describe('Dependency', () => {
let tmpDir;

beforeEach(() => {
tmpDir = tmp.dirSync({
unsafeCleanup: true,
});
});

afterEach(() => {
tmpDir.removeCallback();
});

it('should generate bundle with dependency output', (done) => {
const bundleOutput = path.join(tmpDir.name, 'bundle.js');
const thirdPartyOutput = path.join(tmpDir.name, 'dependencies.txt');

const rollupConfig = {
entry: path.join(__dirname, 'bundle.js'),
dest: bundleOutput,
format: 'es',
plugins: [
nodeResolve(),
commonjs(),

licensePlugin({
thirdParty: {
output: thirdPartyOutput,
},
}),
],
};

rollup.rollup(rollupConfig)
.then((bundle) => bundle.write(rollupConfig))
.then(() => {
fs.readFile(thirdPartyOutput, 'utf8', (err, data) => {
if (err) {
done.fail(err);
}

const content = data.toString();
expect(content).toContain('lodash');
done();
});
});
});

it('should generate bundle with license header', (done) => {
const bundleOutput = path.join(tmpDir.name, 'bundle.js');
const banner = 'test banner';
const EOL = '\n';

const rollupConfig = {
entry: path.join(__dirname, 'bundle.js'),
dest: bundleOutput,
format: 'es',
plugins: [
nodeResolve(),
commonjs(),

licensePlugin({
banner,
}),
],
};

rollup.rollup(rollupConfig)
.then((bundle) => bundle.write(rollupConfig))
.then(() => {
fs.readFile(bundleOutput, 'utf8', (err, data) => {
if (err) {
done.fail(err);
}

const content = data.toString();
const expectedBanner =
`/**${EOL}` +
` * ${banner}${EOL}` +
` */${EOL}`;

expect(content).toContain(expectedBanner);
done();
});
});
});
});

0 comments on commit 07a30e7

Please sign in to comment.