-
-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
115 additions
and
74 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
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 |
---|---|---|
@@ -1,85 +1,114 @@ | ||
import path from 'path'; | ||
import os from 'os'; | ||
import test from 'ava'; | ||
import sinon from 'sinon'; | ||
import proxyquire from 'proxyquire'; | ||
|
||
const homedirStub = sinon.stub(os, 'homedir'); | ||
const fixtureBasePath = path.resolve('test', 'fixtures', 'config'); | ||
|
||
test('should return config from `.np-config.json` in home-directory when global binary used', async t => { | ||
test('should return config only from home-directory when global binary used and `.np-config-json` in home-directory exists', async t => { | ||
const homedirStub = sinon.stub(); | ||
homedirStub.returns(path.resolve(fixtureBasePath, 'homedir1')); | ||
const config = proxyquire('../source/config', { | ||
'is-installed-globally': true, | ||
'pkg-dir': async () => { | ||
return path.resolve(fixtureBasePath, 'pkg-dir'); | ||
} | ||
}); | ||
t.deepEqual(await config(), {yarn: false}); | ||
const pkgDirStub = sinon.stub(); | ||
pkgDirStub.onFirstCall().returns(path.resolve(fixtureBasePath, 'pkg-dir')); | ||
pkgDirStub.onSecondCall().returns(path.resolve(fixtureBasePath, 'local1')); | ||
pkgDirStub.onThirdCall().returns(path.resolve(fixtureBasePath, 'local2')); | ||
|
||
let i = 0; | ||
while (i < 3) { | ||
const config = proxyquire('../source/config', { | ||
'is-installed-globally': true, | ||
'pkg-dir': async () => { | ||
return pkgDirStub(); | ||
}, | ||
os: { | ||
homedir: homedirStub | ||
} | ||
}); | ||
t.deepEqual(await config(), {source: 'homedir/.np-config.json'}); | ||
i++; | ||
} | ||
}); | ||
|
||
test('should return config from `.np-config.js` in home-directory when global binary used', async t => { | ||
test('should return config only from home-directory when global binary used and `.np-config.js` in home-directory exists', async t => { | ||
const homedirStub = sinon.stub(); | ||
homedirStub.returns(path.resolve(fixtureBasePath, 'homedir2')); | ||
const config = proxyquire('../source/config', { | ||
'is-installed-globally': true, | ||
'pkg-dir': async () => { | ||
return path.resolve(fixtureBasePath, 'pkg-dir'); | ||
} | ||
}); | ||
t.deepEqual(await config(), {yarn: true, contents: 'dist'}); | ||
}); | ||
const pkgDirStub = sinon.stub(); | ||
pkgDirStub.onFirstCall().returns(path.resolve(fixtureBasePath, 'pkg-dir')); | ||
pkgDirStub.onSecondCall().returns(path.resolve(fixtureBasePath, 'local1')); | ||
pkgDirStub.onThirdCall().returns(path.resolve(fixtureBasePath, 'local2')); | ||
|
||
test('should return config from `package.json` when local binary used', async t => { | ||
const config = proxyquire('../source/config', { | ||
'is-installed-globally': false, | ||
'pkg-dir': async () => { | ||
return path.resolve(fixtureBasePath, 'pkg-dir'); | ||
} | ||
}); | ||
t.deepEqual(await config(), {yarn: true}); | ||
let i = 0; | ||
while (i < 3) { | ||
const config = proxyquire('../source/config', { | ||
'is-installed-globally': true, | ||
'pkg-dir': async () => { | ||
return pkgDirStub(); | ||
}, | ||
os: { | ||
homedir: homedirStub | ||
} | ||
}); | ||
t.deepEqual(await config(), {source: 'homedir/.np-config.js'}); | ||
i++; | ||
} | ||
}); | ||
|
||
test('should only return config from home-directory when global binary used', async t => { | ||
homedirStub.returns(path.resolve(fixtureBasePath, 'homedir1')); | ||
const globalConfig = proxyquire('../source/config', { | ||
'is-installed-globally': true, | ||
'pkg-dir': async () => { | ||
throw new Error('access local config'); | ||
} | ||
}); | ||
const localConfig = proxyquire('../source/config', { | ||
'is-installed-globally': false, | ||
'pkg-dir': async () => { | ||
throw new Error('expected'); | ||
} | ||
}); | ||
t.deepEqual(await globalConfig(), {yarn: false}); | ||
await t.throwsAsync(localConfig()); | ||
test('should return config only from package-directory when local binary used and `package.json` in package-directory exists', async t => { | ||
const homedirStub = sinon.stub(); | ||
homedirStub.onFirstCall().returns(path.resolve(fixtureBasePath, 'homedir1')); | ||
homedirStub.onSecondCall().returns(path.resolve(fixtureBasePath, 'homedir2')); | ||
let i = 0; | ||
while (i < 2) { | ||
const config = proxyquire('../source/config', { | ||
'is-installed-globally': false, | ||
'pkg-dir': async () => { | ||
return path.resolve(fixtureBasePath, 'pkg-dir'); | ||
}, | ||
os: { | ||
homedir: homedirStub | ||
} | ||
}); | ||
t.deepEqual(await config(), {source: 'package.json'}); | ||
i++; | ||
} | ||
}); | ||
|
||
test('should only return config from local package when local binary used', async t => { | ||
const globalConfig = proxyquire('../source/config', { | ||
'is-installed-globally': true, | ||
'pkg-dir': async () => { | ||
return path.resolve(fixtureBasePath, 'local'); | ||
}, | ||
os: { | ||
homedir: () => { | ||
throw new Error('expected'); | ||
test('should return config only from package-directory when local binary used and `.np-config.json` in package-directory exists', async t => { | ||
const homedirStub = sinon.stub(); | ||
homedirStub.onFirstCall().returns(path.resolve(fixtureBasePath, 'homedir1')); | ||
homedirStub.onSecondCall().returns(path.resolve(fixtureBasePath, 'homedir2')); | ||
let i = 0; | ||
while (i < 2) { | ||
const config = proxyquire('../source/config', { | ||
'is-installed-globally': false, | ||
'pkg-dir': async () => { | ||
return path.resolve(fixtureBasePath, 'local1'); | ||
}, | ||
os: { | ||
homedir: homedirStub | ||
} | ||
} | ||
}); | ||
const localConfig = proxyquire('../source/config', { | ||
'is-installed-globally': false, | ||
'pkg-dir': async () => { | ||
return path.resolve(fixtureBasePath, 'local'); | ||
}, | ||
os: { | ||
homedir: () => { | ||
throw new Error('access global config in home-directory'); | ||
}); | ||
t.deepEqual(await config(), {source: 'packagedir/.np-config.json'}); | ||
i++; | ||
} | ||
}); | ||
|
||
test('should return config only from package-directory when local binary used and `.np-config.js` in package-directory exists', async t => { | ||
const homedirStub = sinon.stub(); | ||
homedirStub.onFirstCall().returns(path.resolve(fixtureBasePath, 'homedir1')); | ||
homedirStub.onSecondCall().returns(path.resolve(fixtureBasePath, 'homedir2')); | ||
let i = 0; | ||
while (i < 2) { | ||
const config = proxyquire('../source/config', { | ||
'is-installed-globally': false, | ||
'pkg-dir': async () => { | ||
return path.resolve(fixtureBasePath, 'local2'); | ||
}, | ||
os: { | ||
homedir: homedirStub | ||
} | ||
} | ||
}); | ||
await t.throwsAsync(globalConfig()); | ||
t.deepEqual(await localConfig(), {local: true}); | ||
}); | ||
t.deepEqual(await config(), {source: 'packagedir/.np-config.js'}); | ||
i++; | ||
} | ||
}); |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"yarn": false | ||
"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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
module.exports = { | ||
yarn: true, | ||
contents: 'dist' | ||
} | ||
source: 'homedir/.np-config.js' | ||
}; |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "test-fixtures", | ||
"np": { | ||
"yarn": true | ||
"source": "package.json" | ||
} | ||
} |