2017-06-10 06:56:03 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2017-06-10 06:56:03 +00:00
|
|
|
*
|
|
|
|
* @format
|
2017-11-02 13:14:11 +00:00
|
|
|
* @emails oncall+javascript_foundation
|
2017-06-10 06:56:03 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2017-10-11 21:51:58 +00:00
|
|
|
jest.mock('fs');
|
|
|
|
|
2017-06-10 06:56:03 +00:00
|
|
|
const findAssets = require('../findAssets');
|
2016-07-30 15:59:16 +00:00
|
|
|
const dependencies = require('../__fixtures__/dependencies');
|
2017-10-11 21:51:58 +00:00
|
|
|
const fs = require('fs');
|
2016-05-20 11:52:08 +00:00
|
|
|
|
|
|
|
describe('findAssets', () => {
|
2017-06-10 06:56:03 +00:00
|
|
|
beforeEach(() => {
|
2017-10-11 21:51:58 +00:00
|
|
|
fs.__setMockFilesystem({testDir: dependencies.withAssets});
|
2017-06-10 06:56:03 +00:00
|
|
|
});
|
2016-05-20 11:52:08 +00:00
|
|
|
|
2017-06-10 06:56:03 +00:00
|
|
|
it('returns an array of all files in given folders', () => {
|
2017-10-11 21:51:58 +00:00
|
|
|
const assets = findAssets('/testDir', ['fonts', 'images']);
|
2016-05-20 11:52:08 +00:00
|
|
|
|
2017-06-10 06:56:03 +00:00
|
|
|
expect(Array.isArray(assets)).toBeTruthy();
|
|
|
|
expect(assets).toHaveLength(3);
|
2016-05-20 11:52:08 +00:00
|
|
|
});
|
|
|
|
|
2017-06-10 06:56:03 +00:00
|
|
|
it('prepends assets paths with the folder path', () => {
|
2017-10-11 21:51:58 +00:00
|
|
|
const assets = findAssets('/testDir', ['fonts', 'images']);
|
2016-05-20 11:52:08 +00:00
|
|
|
|
2017-06-10 06:56:03 +00:00
|
|
|
assets.forEach(assetPath => {
|
|
|
|
expect(assetPath).toContain('testDir');
|
|
|
|
});
|
2016-05-20 11:52:08 +00:00
|
|
|
});
|
|
|
|
|
2017-06-10 06:56:03 +00:00
|
|
|
it('returns an empty array if given assets are null', () => {
|
2017-10-11 21:51:58 +00:00
|
|
|
expect(findAssets('/testDir', null)).toHaveLength(0);
|
2017-06-10 06:56:03 +00:00
|
|
|
});
|
2016-05-20 11:52:08 +00:00
|
|
|
});
|