diff --git a/.gitignore b/.gitignore index 5587103..e2c45c2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /multiline-bc7665a.tar.gz +/multiline-1.0.2.tgz diff --git a/nodejs-multiline.spec b/nodejs-multiline.spec index 475ce34..4c36bbe 100644 --- a/nodejs-multiline.spec +++ b/nodejs-multiline.spec @@ -1,17 +1,15 @@ %global enable_tests 1 %global srcname multiline -%global commit0 bc7665a7f7e6a0c17956bbda532912d09ddb8be1 -%global gittag0 v1.0.2 -%global shortcommit0 %(c=%{commit0}; echo ${c:0:7}) - Name: nodejs-%{srcname} Version: 1.0.2 -Release: 2%{?dist} +Release: 3%{?dist} Summary: Multiline strings in JavaScript License: MIT URL: https://github.com/sindresorhus/multiline -Source0: https://github.com/sindresorhus/%{srcname}/archive/%{commit0}.tar.gz#/%{srcname}-%{shortcommit0}.tar.gz +Source0: https://registry.npmjs.com/%{srcname}/-/%{srcname}-%{version}.tgz +# tests not in tarball +Source1: https://raw.githubusercontent.com/sindresorhus/multiline/v%{version}/test.js BuildArch: noarch ExclusiveArch: %{nodejs_arches} noarch @@ -28,9 +26,11 @@ BuildRequires: npm(uglify-js) %{summary}. %prep -%setup -qn %{srcname}-%{commit0} +%setup -q -n package +cp -p %{SOURCE1} . rm -rf node_modules %nodejs_fixdep --dev uglify-js +%nodejs_fixdep strip-indent %build #nothing to do @@ -42,10 +42,13 @@ cp -pr package.json index.js \ %nodejs_symlink_deps -%if 0%{?enable_tests} %check %nodejs_symlink_deps --check -mocha +%{__nodejs} -e 'require("./")' +%if 0%{?enable_tests} +%{_bindir}/mocha -R spec +%else +%{_bindir}/echo -e "\e[101m -=#=- Tests disabled -=#=- \e[0m" %endif %files @@ -54,6 +57,10 @@ mocha %{nodejs_sitelib}/%{srcname} %changelog +* Sat Jul 16 2016 Jared Smith - 1.0.2-3 +- Relax version of npm(strip-indent) +- Add tests and run them during check phase + * Thu Feb 04 2016 Fedora Release Engineering - 1.0.2-2 - Rebuilt for https://fedoraproject.org/wiki/Fedora_24_Mass_Rebuild diff --git a/sources b/sources index 21479ce..b343449 100644 --- a/sources +++ b/sources @@ -1 +1 @@ -7053b2e7cd52c86fc9039c1c599910ec multiline-bc7665a.tar.gz +fffd27fdcb1149fd10dd41a066a3fd78 multiline-1.0.2.tgz diff --git a/test.js b/test.js new file mode 100644 index 0000000..831746c --- /dev/null +++ b/test.js @@ -0,0 +1,120 @@ +'use strict'; +var assert = require('assert'); +var ml = require('./'); + +it('should support multiline comments', function () { + var actual = ml(function(){/* + + + +

Hello world!

+ + + */}); + var expected = '\n\n\t\n\t\t

Hello world!

\n\t\n'; + assert.equal(actual, expected); +}); + +it('should match when comment starts with `/*!`', function () { + var actual = ml(function(){/*! +foo + */}); + var expected = 'foo'; + assert.equal(actual, expected); +}); + +it('should match when comment starts with `/*@preserve`', function () { + var actual = ml(function(){/*@preserve +foo + */}); + var expected = 'foo'; + assert.equal(actual, expected); +}); + +it('should match when comment starts with `/*!@preserve`', function () { + var actual = ml(function(){/*!@preserve +foo + */}); + var expected = 'foo'; + assert.equal(actual, expected); +}); + +it('should preserve leading empty lines', function () { + var actual = ml(function(){/* + + +foo + */}); + var expected = '\n\nfoo'; + assert.equal(actual, expected); +}); + +it('should preserve trailing empty lines', function () { + var actual = ml(function(){/* +foo + + + */}); + var expected = 'foo\n\n'; + assert.equal(actual, expected); +}); + +it('should throw if it can\'t match comment contents', function () { + assert.throws(function () { + ml(function(){}); + }); + + assert.throws(function () { + ml(function(){/**/}); + }); +}); + +it('should be preserved when using Uglify', function () { + var uglify = require('uglify-js'); + var fixture = 'var str=multiline(function(){/*!@preserve\n\n*/\nconsole.log});'; + + var actual = uglify.minify(fixture, { + fromString: true, + output: { + comments: true + } + }).code; + + assert.equal(actual, fixture); +}); + +describe('multiline.stripIndent()', function () { + it('should strip redundant leading whitespace', function () { + var actual = ml.stripIndent(function(){/* + + + + +

Hello world!

+ + + */}); + var expected = '\n\n\n\t\n\t\t

Hello world!

\n\t\n'; + assert.equal(actual, expected); + }); + + it('should preserve leading empty lines', function () { + var actual = ml.stripIndent(function(){/* + + + foo + */}); + var expected = '\n\nfoo'; + assert.equal(actual, expected); + }); + + it('should preserve trailing empty lines', function () { + var actual = ml.stripIndent(function(){/* + foo + + + */}); + var expected = 'foo\n\n'; + assert.equal(actual, expected); + }); +});