-
Notifications
You must be signed in to change notification settings - Fork 7
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
10 changed files
with
94 additions
and
4 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 |
---|---|---|
@@ -1,8 +1,36 @@ | ||
'use strict' | ||
|
||
const joi = require('joi') | ||
const path = require('path') | ||
|
||
exports.validate = ({ config }) => { | ||
const contents = require(path.join(process.cwd(), '.wiby.json')) | ||
console.log(contents) | ||
const dependentSchema = joi.object({ | ||
repository: joi.string().uri({ | ||
scheme: [ | ||
'https', | ||
'git', | ||
'git+https' | ||
] | ||
}) | ||
}).unknown(false) | ||
|
||
exports.schema = joi.object({ | ||
dependents: joi.array().items(dependentSchema) | ||
}).unknown(false) | ||
|
||
exports.validate = ({ config: configFilePath }) => { | ||
if (!configFilePath) { | ||
configFilePath = path.join(process.cwd(), '.wiby.json') | ||
} | ||
|
||
configFilePath = path.resolve(configFilePath) | ||
|
||
const contents = require(configFilePath) | ||
|
||
const result = exports.schema.validate(contents) | ||
|
||
if (result.error) { | ||
throw result.error | ||
} | ||
|
||
console.log(`✅ ${configFilePath}`) | ||
} |
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,9 +1,43 @@ | ||
'use strict' | ||
|
||
const path = require('path') | ||
const tap = require('tap') | ||
const wiby = require('..') | ||
|
||
tap.test('Exists', (tap) => { | ||
const invalidConfigs = { | ||
'fail-bad-json.json': 'Unexpected end of JSON input', | ||
'fail-unknown-root-key.json': '"not-allowed" is not allowed', | ||
'fail-unknown-dependent-key.json': '"dependents[0].sub-key-not-allowed" is not allowed', | ||
'fail-dependent-not-url.json': '"dependents[0].repository" must be a valid uri' | ||
} | ||
|
||
const validConfigs = [ | ||
'pass-empty.json', | ||
'pass-empty-dependents.json', | ||
'pass-wiby.js' | ||
] | ||
|
||
tap.test('should pass with the .wiby.json of the wiby itself', (tap) => { | ||
wiby.validate({}) | ||
tap.end() | ||
}) | ||
|
||
tap.test('Invalid configs', async (tap) => { | ||
for (const [file, expectedError] of Object.entries(invalidConfigs)) { | ||
tap.test(file, (tap) => { | ||
tap.throws(() => { | ||
wiby.validate({ config: path.join(__dirname, 'fixtures', 'config', file) }) | ||
}, { message: expectedError }) | ||
tap.end() | ||
}) | ||
} | ||
}) | ||
|
||
tap.test('Valid configs', async (tap) => { | ||
for (const file of validConfigs) { | ||
tap.test(file, (tap) => { | ||
wiby.validate({ config: path.join(__dirname, 'fixtures', 'config', file) }) | ||
tap.end() | ||
}) | ||
} | ||
}) |
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 @@ | ||
{"deliberately broken" |
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,7 @@ | ||
{ | ||
"dependents": [ | ||
{ | ||
"repository": "not-a-url" | ||
} | ||
] | ||
} |
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,7 @@ | ||
{ | ||
"dependents": [ | ||
{ | ||
"sub-key-not-allowed": true | ||
} | ||
] | ||
} |
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 @@ | ||
{ | ||
"not-allowed": true | ||
} |
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 @@ | ||
{ | ||
"dependents": [] | ||
} |
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 @@ | ||
{} |
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 @@ | ||
module.exports = require('../../../.wiby.json') |