Skip to content

Commit e3070d3

Browse files
authored
Merge pull request #338 from bem/i336
Add asArray method to request promise with an array of bemfiles
2 parents e978370 + 93d5e6b commit e3070d3

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

.eslintrc.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
module.exports = {
44
root: true,
55
parserOptions: {
6-
ecmaVersion: 7,
7-
"ecmaFeatures": {
8-
"experimentalObjectRestSpread": true,
9-
},
6+
ecmaVersion: 9
107
},
118
env: {
129
node: true,

packages/walk/lib/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,18 @@ function realpathOrError(path) {
118118
return e;
119119
}
120120
}
121+
122+
/**
123+
* Inline version of stream to array
124+
*
125+
* @returns {Promise<BemFile[]>}
126+
*/
127+
module.exports.asArray = function(...args) {
128+
return new Promise((resolve, reject) => {
129+
const files = [];
130+
module.exports(...args)
131+
.on('data', file => files.push(file))
132+
.on('error', reject)
133+
.on('end', () => resolve(files));
134+
});
135+
};

packages/walk/test/index.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
const { describe, it } = require('mocha');
4+
const { expect, use } = require('chai');
5+
use(require('chai-as-promised'));
6+
7+
const { asArray } = require('..');
8+
9+
describe('asArray', () => {
10+
it('should return an empty array', async () => {
11+
expect(await asArray(['.'])).to.eql([]);
12+
});
13+
14+
it('should throw on incorrect', async () => {
15+
expect(asArray(['unknown-direction'])).to.be.rejectedWith(/ENOENT/);
16+
});
17+
});

0 commit comments

Comments
 (0)