-
-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Itai Steinherz <itaisteinherz@gmail.com>
- Loading branch information
1 parent
eab7bbd
commit d9848db
Showing
6 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import path from 'path'; | ||
import test from 'ava'; | ||
import sinon from 'sinon'; | ||
import proxyquire from 'proxyquire'; | ||
|
||
const fixtureBasePath = path.resolve('test', 'fixtures', 'config'); | ||
|
||
const getConfigsWhenGlobalBinaryIsUsed = async homedirStub => { | ||
const pathsPkgDir = [path.resolve(fixtureBasePath, 'pkg-dir'), | ||
path.resolve(fixtureBasePath, 'local1'), | ||
path.resolve(fixtureBasePath, 'local2')]; | ||
|
||
const promises = []; | ||
pathsPkgDir.forEach(pathPkgDir => { | ||
promises.push(proxyquire('../source/config', { | ||
'is-installed-globally': true, | ||
'pkg-dir': async () => { | ||
return pathPkgDir; | ||
}, | ||
os: { | ||
homedir: homedirStub | ||
} | ||
})()); | ||
}); | ||
return Promise.all(promises); | ||
}; | ||
|
||
const getConfigsWhenLocalBinaryIsUsed = async pathPkgDir => { | ||
const homedirs = [path.resolve(fixtureBasePath, 'homedir1'), | ||
path.resolve(fixtureBasePath, 'homedir2')]; | ||
|
||
const promises = []; | ||
homedirs.forEach(homedir => { | ||
promises.push(proxyquire('../source/config', { | ||
'is-installed-globally': false, | ||
'pkg-dir': async () => { | ||
return pathPkgDir; | ||
}, | ||
os: { | ||
homedir: () => { | ||
return homedir; | ||
} | ||
} | ||
})()); | ||
}); | ||
return Promise.all(promises); | ||
}; | ||
|
||
test('returns config from home directory when global binary is used and `.np-config-json` exists in home directory', async t => { | ||
const homedirStub = sinon.stub(); | ||
homedirStub.returns(path.resolve(fixtureBasePath, 'homedir1')); | ||
const configs = await getConfigsWhenGlobalBinaryIsUsed(homedirStub); | ||
configs.forEach(config => t.deepEqual(config, {source: 'homedir/.np-config.json'})); | ||
}); | ||
|
||
test('returns config from home directory when global binary is used and `.np-config.js` exists in home directory', async t => { | ||
const homedirStub = sinon.stub(); | ||
homedirStub.returns(path.resolve(fixtureBasePath, 'homedir2')); | ||
const configs = await getConfigsWhenGlobalBinaryIsUsed(homedirStub); | ||
configs.forEach(config => t.deepEqual(config, {source: 'homedir/.np-config.js'})); | ||
}); | ||
|
||
test('returns config from package directory when local binary is used and `package.json` exists in package directory', async t => { | ||
const configs = await getConfigsWhenLocalBinaryIsUsed(path.resolve(fixtureBasePath, 'pkg-dir')); | ||
configs.forEach(config => t.deepEqual(config, {source: 'package.json'})); | ||
}); | ||
|
||
test('returns config from package directory when local binary is used and `.np-config.json` exists in package directory', async t => { | ||
const configs = await getConfigsWhenLocalBinaryIsUsed(path.resolve(fixtureBasePath, 'local1')); | ||
configs.forEach(config => t.deepEqual(config, {source: 'packagedir/.np-config.json'})); | ||
}); | ||
|
||
test('returns config from package directory when local binary is used and `.np-config.js` exists in package directory', async t => { | ||
const configs = await getConfigsWhenLocalBinaryIsUsed(path.resolve(fixtureBasePath, 'local2')); | ||
configs.forEach(config => t.deepEqual(config, {source: 'packagedir/.np-config.js'})); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"source": "homedir/.np-config.json" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
source: 'homedir/.np-config.js' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"source": "packagedir/.np-config.json" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
source: 'packagedir/.np-config.js' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "test-fixtures", | ||
"np": { | ||
"source": "package.json" | ||
} | ||
} |