diff --git a/package.json b/package.json index 772e23b0..cff21f36 100644 --- a/package.json +++ b/package.json @@ -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" } diff --git a/test/integration/.eslintrc b/test/integration/.eslintrc new file mode 100644 index 00000000..bd14a19e --- /dev/null +++ b/test/integration/.eslintrc @@ -0,0 +1,5 @@ +{ + "parserOptions": { + "sourceType": "module" + } +} diff --git a/test/integration/bundle.js b/test/integration/bundle.js new file mode 100644 index 00000000..8259ab74 --- /dev/null +++ b/test/integration/bundle.js @@ -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); +} diff --git a/test/integration/it.spec.js b/test/integration/it.spec.js new file mode 100644 index 00000000..2df301bb --- /dev/null +++ b/test/integration/it.spec.js @@ -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(); + }); + }); + }); +});