Skip to content
This repository has been archived by the owner on Oct 17, 2020. It is now read-only.

Reimplement skipped test. #39

Merged
merged 2 commits into from
Aug 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions packages/liferay-npm-bundler/src/__tests__/config.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
let cfg;

beforeAll(() => {
process.chdir('./packages/liferay-npm-bundler/src/__tests__');
cfg = require('../config');
const projectDir = process.cwd();
const cfg = require('../config');

beforeEach(() => {
process.chdir(
`${projectDir}/packages/liferay-npm-bundler/src/__tests__/config/` +
'default',
);
cfg.reloadConfig();
});

afterAll(() => {
process.chdir('../../../..');
afterEach(() => {
process.chdir(projectDir);
});

describe('getOutputDir()', () => {
Expand Down Expand Up @@ -38,7 +42,25 @@ describe('getExclusions()', () => {
expect(cfg.getExclusions(pkg)).toEqual(['**/*.js', '**/*.css']);
});

it('returns the default exclusions for unconfigured packages', () => {
const pkg = {
id: 'not-existent-package@1.0.0',
name: 'not-existent-package',
version: '1.0.0',
dir: '',
};

expect(cfg.getExclusions(pkg)).toEqual(['test/**/*']);
});

// Impossible to test once we test for default exclusions
it('returns an empty array for unconfigured packages', () => {
process.chdir(
`${projectDir}/packages/liferay-npm-bundler/src/__tests__/config/` +
'empty',
);
cfg.reloadConfig();

const pkg = {
id: 'not-existent-package@1.0.0',
name: 'not-existent-package',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"output": "output-dir",
"exclude": {
"*": [
"test/**/*"
],
"package-a": [
"*"
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"output": "output-dir"
}
21 changes: 19 additions & 2 deletions packages/liferay-npm-bundler/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ let config = loadConfig();
*/
function loadConfig() {
// Load base configuration
let config = readJsonSync('.npmbundlerrc');
let config = {};

try {
config = readJsonSync('.npmbundlerrc');
} catch (err) {
if (err.code !== 'ENOENT') {
throw err;
}
}

// Apply preset if necessary
if (config.preset) {
Expand Down Expand Up @@ -40,6 +48,14 @@ function configRequire(module) {
return require(pluginFile);
}

/**
* Force a config reload
* @return {void}
*/
export function reloadConfig() {
config = loadConfig();
}

/**
* Get the configured output directory
* @return {String} the directory path
Expand All @@ -57,7 +73,8 @@ export function getOutputDir() {
export function getExclusions(pkg) {
let exclusions = config.exclude || {};

exclusions = exclusions[pkg.id] || exclusions[pkg.name] || [];
exclusions =
exclusions[pkg.id] || exclusions[pkg.name] || exclusions['*'] || [];

return exclusions;
}
Expand Down