|
1 | | -/* global context, describe, it, beforeEach */ |
| 1 | +/* global context, describe, it, beforeEach, afterEach */ |
2 | 2 |
|
3 | 3 | var expect = require('chai').expect |
4 | 4 | var fs = require('fs') |
5 | 5 | var path = require('path') |
6 | 6 | var checkOutput = require('./helpers/utils').checkOutput |
7 | | -var yargs = require('../') |
| 7 | +var yargs |
| 8 | +var YError = require('../lib/yerror') |
8 | 9 |
|
9 | 10 | require('chai').should() |
10 | 11 |
|
11 | 12 | describe('yargs dsl tests', function () { |
12 | 13 | beforeEach(function () { |
13 | | - yargs.reset() |
| 14 | + yargs = require('../') |
| 15 | + }) |
| 16 | + |
| 17 | + afterEach(function () { |
| 18 | + delete require.cache[require.resolve('../')] |
14 | 19 | }) |
15 | 20 |
|
16 | 21 | it('should use bin name for $0, eliminating path', function () { |
@@ -1163,6 +1168,42 @@ describe('yargs dsl tests', function () { |
1163 | 1168 | argv.foo.should.equal(1) |
1164 | 1169 | argv.bar.should.equal(2) |
1165 | 1170 | }) |
| 1171 | + |
| 1172 | + describe('extends', function () { |
| 1173 | + it('applies default configurations when given config object', function () { |
| 1174 | + var argv = yargs |
| 1175 | + .config({ |
| 1176 | + extends: './test/fixtures/extends/config_1.json', |
| 1177 | + a: 1 |
| 1178 | + }) |
| 1179 | + .argv |
| 1180 | + |
| 1181 | + argv.a.should.equal(1) |
| 1182 | + argv.b.should.equal(22) |
| 1183 | + argv.z.should.equal(15) |
| 1184 | + }) |
| 1185 | + |
| 1186 | + it('protects against circular extended configurations', function () { |
| 1187 | + expect(function () { |
| 1188 | + yargs.config({extends: './test/fixtures/extends/circular_1.json'}) |
| 1189 | + }).to.throw(YError) |
| 1190 | + }) |
| 1191 | + |
| 1192 | + it('handles aboslute paths', function () { |
| 1193 | + var absolutePath = path.join(process.cwd(), 'test', 'fixtures', 'extends', 'config_1.json') |
| 1194 | + |
| 1195 | + var argv = yargs |
| 1196 | + .config({ |
| 1197 | + a: 2, |
| 1198 | + extends: absolutePath |
| 1199 | + }) |
| 1200 | + .argv |
| 1201 | + |
| 1202 | + argv.a.should.equal(2) |
| 1203 | + argv.b.should.equal(22) |
| 1204 | + argv.z.should.equal(15) |
| 1205 | + }) |
| 1206 | + }) |
1166 | 1207 | }) |
1167 | 1208 |
|
1168 | 1209 | describe('normalize', function () { |
@@ -1419,6 +1460,20 @@ describe('yargs dsl tests', function () { |
1419 | 1460 |
|
1420 | 1461 | argv.foo.should.equal('a') |
1421 | 1462 | }) |
| 1463 | + |
| 1464 | + it('should apply default configurations from extended packages', function () { |
| 1465 | + var argv = yargs().pkgConf('foo', 'test/fixtures/extends/packageA').argv |
| 1466 | + |
| 1467 | + argv.a.should.equal(80) |
| 1468 | + argv.b.should.equals('riffiwobbles') |
| 1469 | + }) |
| 1470 | + |
| 1471 | + it('should apply extended configurations from cwd when no path is given', function () { |
| 1472 | + var argv = yargs('', 'test/fixtures/extends/packageA').pkgConf('foo').argv |
| 1473 | + |
| 1474 | + argv.a.should.equal(80) |
| 1475 | + argv.b.should.equals('riffiwobbles') |
| 1476 | + }) |
1422 | 1477 | }) |
1423 | 1478 |
|
1424 | 1479 | describe('skipValidation', function () { |
|
0 commit comments