diff --git a/tests/run.js b/tests/run.js index 735993a..b0f7179 100644 --- a/tests/run.js +++ b/tests/run.js @@ -15,8 +15,8 @@ function run(title) { // Run the collector only if the suite will be checked. before(() => { actual = collect(title + '/source.js'); - expectedTypes = yaml.load(fs.readFileSync(title + '/types.yaml', 'utf8')); - expectedSchema = JSON.parse(fs.readFileSync(title + '/schema.json', 'utf8')); + expectedTypes = readFileAndPrepare(title + '/types.yaml', yaml.load); + expectedSchema = readFileAndPrepare(title + '/schema.json', JSON.parse); }); it('should not include cycles', () => { @@ -40,6 +40,22 @@ function run(title) { }); } +function readFileAndPrepare(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 = new Set, objs: Set = new Set) { if (obj == null || typeof obj !== 'object') { return cycles;