Skip to content
This repository was archived by the owner on Sep 21, 2022. It is now read-only.
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: gemini-testing/gemini
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 8e6bf550b7b03e644d65a9f97f8c1a7c01eee5de
Choose a base ref
..
head repository: gemini-testing/gemini
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a4fd607a6f5cf4603b02bb77d5985fa7227ad388
Choose a head ref
Showing with 32 additions and 2 deletions.
  1. +10 βˆ’2 lib/config/index.js
  2. +22 βˆ’0 test/unit/config-options/config-options.test.js
12 changes: 10 additions & 2 deletions lib/config/index.js
Original file line number Diff line number Diff line change
@@ -53,6 +53,14 @@ Config.prototype.isCoverageEnabled = function() {
return this.system.coverage.enabled;
};

Config.isRelativePath = function(file) {
return file.indexOf('./') === 0 || file.indexOf('/') !== 0;
};

Config.getAbsPath = function(file) {
return process.cwd() + '/' + file;
};

function readConfig(filePath) {
filePath = filePath || getDefaultConfig();

@@ -81,8 +89,8 @@ function getDefaultConfig() {

function requireModule(file) {
try {
if (file.indexOf('./') === 0 || file.indexOf('/') !== 0) {
return require(process.cwd() + '/' + file);
if (Config.isRelativePath(file)) {
return require(Config.getAbsPath(file));
} else {
return require(file);
}
22 changes: 22 additions & 0 deletions test/unit/config-options/config-options.test.js
Original file line number Diff line number Diff line change
@@ -866,4 +866,26 @@ describe('config', function() {
});
});
});

describe('util functions', function() {
it('should return true if path is relative', function() {
assert.strictEqual(Config.isRelativePath('./foo/bar'), true);
assert.strictEqual(Config.isRelativePath('foo/bar'), true);
});

it('should return false if path is absolute', function() {
assert.strictEqual(Config.isRelativePath('/foo/bar'), false);
});

it('should return absolute path by pass relative', function() {
var relativePath = 'foo/bar/gemini.config';
var relativePathWithLeadedDot = './foo/bar/gemini.config';
assert.strictEqual(
Config.getAbsPath(relativePath),
process.cwd() + '/' + relativePath);
assert.strictEqual(
Config.getAbsPath(relativePathWithLeadedDot),
process.cwd() + '/' + relativePathWithLeadedDot);
});
});
});