Support samples w/o types.yaml and schema.json
parent
06a15e2d67
commit
a51d4bc5b3
20
tests/run.js
20
tests/run.js
|
@ -15,8 +15,8 @@ function run(title) {
|
||||||
// Run the collector only if the suite will be checked.
|
// Run the collector only if the suite will be checked.
|
||||||
before(() => {
|
before(() => {
|
||||||
actual = collect(title + '/source.js');
|
actual = collect(title + '/source.js');
|
||||||
expectedTypes = yaml.load(fs.readFileSync(title + '/types.yaml', 'utf8'));
|
expectedTypes = readFileAndPrepare(title + '/types.yaml', yaml.load);
|
||||||
expectedSchema = JSON.parse(fs.readFileSync(title + '/schema.json', 'utf8'));
|
expectedSchema = readFileAndPrepare(title + '/schema.json', JSON.parse);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not include cycles', () => {
|
it('should not include cycles', () => {
|
||||||
|
@ -40,6 +40,22 @@ function run(title) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function readFileAndPrepare<R>(path: string, prepare: string => R): R | void {
|
||||||
|
let data;
|
||||||
|
|
||||||
|
try {
|
||||||
|
data = fs.readFileSync(path, 'utf8');
|
||||||
|
} catch (ex) {
|
||||||
|
if (ex.code === 'ENOENT') {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
|
||||||
|
return prepare(data);
|
||||||
|
}
|
||||||
|
|
||||||
function detectCycles(obj: mixed, cycles: Set<mixed> = new Set, objs: Set<mixed> = new Set) {
|
function detectCycles(obj: mixed, cycles: Set<mixed> = new Set, objs: Set<mixed> = new Set) {
|
||||||
if (obj == null || typeof obj !== 'object') {
|
if (obj == null || typeof obj !== 'object') {
|
||||||
return cycles;
|
return cycles;
|
||||||
|
|
Loading…
Reference in New Issue