Skip to content

Commit ec8f026

Browse files
committed
Fix: rename if path is Array and includes just one element (closes #19) (#27)
1 parent d05ba8b commit ec8f026

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

lib/process/process.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ const rcsProcess = (pathString, opts, cb) => {
2929
`options.type must be one of the following: ${availableTypes}`,
3030
);
3131

32-
if (Object.prototype.toString.call(pathString) === '[object Array]') {
33-
globString = `{${pathString.join(',')}}`;
32+
if (Array.isArray(pathString)) {
33+
globString = pathString.length > 1
34+
? `{${pathString.join(',')}}`
35+
: pathString[0];
3436
}
3537

3638
glob(globString, {

test/integration.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import test from 'ava';
2+
import path from 'path';
3+
import fs from 'fs-extra';
4+
import rcsCore from 'rcs-core';
5+
6+
import rcs from '../';
7+
8+
const testCwd = 'test/files/testCache';
9+
const fixturesCwd = 'test/files/fixtures';
10+
11+
test.beforeEach(() => {
12+
rcsCore.nameGenerator.setAlphabet('#abcdefghijklmnopqrstuvwxyz');
13+
rcsCore.nameGenerator.reset();
14+
rcsCore.selectorLibrary.reset();
15+
rcsCore.keyframesLibrary.reset();
16+
});
17+
18+
test.afterEach.always(() => {
19+
fs.removeSync(testCwd);
20+
});
21+
22+
test.cb('issue #19 | detect one file as array', (t) => {
23+
rcs.process.css('**/style.css', {
24+
newPath: testCwd,
25+
cwd: fixturesCwd,
26+
}, () => {
27+
rcs.process.html(['html/index.html'], {
28+
newPath: testCwd,
29+
cwd: fixturesCwd,
30+
}, (err) => {
31+
t.falsy(err);
32+
t.true(fs.existsSync(path.join(testCwd, '/html/index.html')));
33+
t.true(fs.existsSync(path.join(testCwd, '/css/style.css')));
34+
t.true(fs.existsSync(path.join(testCwd, '/css/subdirectory/style.css')));
35+
t.end();
36+
});
37+
});
38+
});
39+
40+
test.cb('issue #19 | detect one file', (t) => {
41+
rcs.process.css('**/style.css', {
42+
newPath: testCwd,
43+
cwd: fixturesCwd,
44+
}, () => {
45+
rcs.process.html('html/index.html', {
46+
newPath: testCwd,
47+
cwd: fixturesCwd,
48+
}, (err) => {
49+
t.falsy(err);
50+
t.true(fs.existsSync(path.join(testCwd, '/html/index.html')));
51+
t.true(fs.existsSync(path.join(testCwd, '/css/style.css')));
52+
t.true(fs.existsSync(path.join(testCwd, '/css/subdirectory/style.css')));
53+
t.end();
54+
});
55+
});
56+
});

0 commit comments

Comments
 (0)