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
12 changed files
with
224 additions
and
48 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
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
bad | ||
"port": 8080 | ||
} |
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,5 @@ | ||
var config = { | ||
port: 99999 | ||
}; | ||
|
||
module.exports = config; |
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 @@ | ||
{ | ||
"port": 8080 | ||
} |
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,5 @@ | ||
var config = { | ||
port: 8080 | ||
}; | ||
|
||
module.exports = config; |
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,13 @@ | ||
{ | ||
bad | ||
"properties": { | ||
"port": { | ||
"description": "The web server port number.", | ||
"type": "integer", | ||
"required": true, | ||
"minimum": 1, | ||
"maximum": 65535, | ||
"default": 80 | ||
} | ||
} | ||
} |
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,12 @@ | ||
{ | ||
"properties": { | ||
"port": { | ||
"description": "The web server port number.", | ||
"type": "integer", | ||
"required": true, | ||
"minimum": 1, | ||
"maximum": 65535, | ||
"default": 80 | ||
} | ||
} | ||
} |
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,14 @@ | ||
var schema = { | ||
properties: { | ||
port: { | ||
description: 'The web server port number.', | ||
type: 'integer', | ||
required: true, | ||
minimum: 1, | ||
maximum: 65535, | ||
default: 80 | ||
} | ||
} | ||
}; | ||
|
||
module.exports = schema; |
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 @@ | ||
{ | ||
"name": "pkgconfig-test" | ||
} |
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,87 @@ | ||
var assert = require('assert'); | ||
var pkgconfig = require('../pkgconfig.js'); | ||
|
||
// Test normal defaults. | ||
var config = pkgconfig(); | ||
assert.deepEqual(config, { port: 8080 }); | ||
|
||
// Test good JSON options object. | ||
pkgconfig({ | ||
schema: 'config/schema-json.json', | ||
config: 'config/config-json.json' | ||
}); | ||
|
||
// Test bad JSON schema. | ||
assert.throws(function () { | ||
pkgconfig({ | ||
schema: 'config/schema-fail.json', | ||
config: 'config/config-json.json' | ||
}); | ||
}, SyntaxError); | ||
|
||
// Test bad JSON config. | ||
assert.throws(function () { | ||
pkgconfig({ | ||
schema: 'config/schema-json.json', | ||
config: 'config/config-fail.json' | ||
}); | ||
}, SyntaxError); | ||
|
||
// Test invalid range. | ||
assert.throws(function () { | ||
pkgconfig('config/config-invalid'); | ||
}, /ValidationError/); | ||
|
||
// Test invalid options. | ||
assert.throws(function () { | ||
pkgconfig(5); | ||
}, TypeError); | ||
|
||
// Test valid config file string option. | ||
pkgconfig('config/config'); | ||
|
||
// Test invalid config file string option. | ||
assert.throws(function () { | ||
pkgconfig('not/found'); | ||
}, Error); | ||
|
||
// Test valid inline options. | ||
pkgconfig({ | ||
schema: { | ||
properties: { | ||
port: { | ||
description: 'The web server port number.', | ||
type: 'integer', | ||
required: true, | ||
minimum: 1, | ||
maximum: 65535, | ||
default: 80 | ||
} | ||
} | ||
}, | ||
config: { | ||
port: 8080 | ||
} | ||
}); | ||
|
||
// Test invalid inline options. | ||
assert.throws(function () { | ||
pkgconfig({ | ||
schema: { | ||
properties: { | ||
port: { | ||
description: 'The web server port number.', | ||
type: 'integer', | ||
required: true, | ||
minimum: 1, | ||
maximum: 65535 | ||
} | ||
} | ||
}, | ||
config: { | ||
badport: 8080 | ||
} | ||
}); | ||
}, /ValidationError/); | ||
|
||
console.log('All tests passed successfully.'); |