diff --git a/.gitignore b/.gitignore index e69de29..b9e0c1d 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +/arr-union-3.1.0.tgz diff --git a/nodejs-arr-union.spec b/nodejs-arr-union.spec new file mode 100644 index 0000000..e4e96b4 --- /dev/null +++ b/nodejs-arr-union.spec @@ -0,0 +1,71 @@ +%{?nodejs_find_provides_and_requires} + +%global packagename arr-union +%global enable_tests 1 + +Name: nodejs-arr-union +Version: 3.1.0 +Release: 1%{?dist} +Summary: Combines a list of arrays, returning a single array with unique values + +License: MIT +URL: https://github.com/jonschlinkert/arr-union +Source0: https://registry.npmjs.org/%{packagename}/-/%{packagename}-%{version}.tgz +# The test files are not included in the npm tarball. +# Release not tagged in Github, so pull tests from master branch +Source1: https://raw.githubusercontent.com/jonschlinkert/arr-union/master/test.js + + +BuildArch: noarch +%if 0%{?fedora} >= 19 +ExclusiveArch: %{nodejs_arches} noarch +%else +ExclusiveArch: %{ix86} x86_64 %{arm} noarch +%endif + +BuildRequires: nodejs-packaging + +%if 0%{?enable_tests} +BuildRequires: mocha +BuildRequires: npm(should) +%endif + +%description +Combines a list of arrays, returning a single array with unique values, using +strict equality for comparisons. + + +%prep +%autosetup -n package +# setup the tests +cp -p %{SOURCE1} . + + +%build +# nothing to do + +%install +mkdir -p %{buildroot}%{nodejs_sitelib}/%{packagename} +cp -pr package.json index.js \ + %{buildroot}%{nodejs_sitelib}/%{packagename} + +%nodejs_symlink_deps + +%check +%nodejs_symlink_deps --check +%{__nodejs} -e 'require("./")' +%if 0%{?enable_tests} +NODE_ENV=test %{_bindir}/mocha -R spec +%else +%{_bindir}/echo -e "\e[101m -=#=- Tests disabled -=#=- \e[0m" +%endif + +%files +%{!?_licensedir:%global license %doc} +%doc *.md +%license LICENSE +%{nodejs_sitelib}/%{packagename} + +%changelog +* Fri Jul 29 2016 Jared Smith - 3.1.0-1 +- Initial packaging diff --git a/sources b/sources index e69de29..c2acf6d 100644 --- a/sources +++ b/sources @@ -0,0 +1 @@ +f3cf2ebd1f4051917051f0c2b9287954 arr-union-3.1.0.tgz diff --git a/test.js b/test.js new file mode 100644 index 0000000..827f506 --- /dev/null +++ b/test.js @@ -0,0 +1,45 @@ +/*! + * arr-union + * + * Copyright (c) 2014-2015, Jon Schlinkert. + * Licensed under the MIT License. + */ + +'use strict'; + +/* deps:mocha */ +var path = require('path'); +var argv = require('minimist')(process.argv.slice(2)); +var should = require('should'); +var union = require('./'); + +if (argv._.length) { + union = require(path.resolve('benchmark/code/' + argv.code + '.js')); +} + +describe('union', function() { + it('should add elements to the original array:', function() { + var arr = ['a']; + union(arr, ['b', 'c'], ['a'], ['b', 'c'], ['d', 'e', 'f']).sort() + arr.should.eql(['a', 'b', 'c', 'd', 'e', 'f'].sort()); + }); + + it('should union all elements in the given arrays:', function() { + union(['a'], ['b', 'c'], ['d', 'e', 'f']).sort().should.eql(['a', 'b', 'c', 'd', 'e', 'f'].sort()); + }); + + it('should ignore falsey values', function() { + union(['a'], undefined, ['d', 'e', 'f']).sort().should.eql(['a', 'd', 'e', 'f'].sort()); + }); + + it('should arrayify non-array values', function() { + union(['a'], 'cde', ['d', 'e', 'f']).sort().should.eql(['a', 'cde', 'd', 'e', 'f'].sort()); + }); + + it('should uniquify elements from additional arrays:', function() { + var arr = ['a', 'b', 'c']; + var res = union(arr, ['b', 'c'], ['a'], ['b', 'c'], ['d', 'e', 'f']).sort() + res.should.eql(['a', 'b', 'c', 'd', 'e', 'f'].sort()); + }); +}); +