UNPKG

json-parser-yaml-converter

Version:
61 lines (56 loc) 1.33 kB
/** * This module tests the parser module. * * @module parser.test */ 'use strict'; import { jsonLogger } from '../src/loggers.js'; import { readFileSync } from 'fs'; import { cleanString } from './utils.js' const TESTS = [ 'alone', 'arrayValues', 'complex', 'duplicates', 'duplicateLayers', 'emoji', 'empty', 'emptyContainers', 'expressions', 'extraComma', 'floatNumbers', 'fullEmpty', 'hugeBad', 'hugeGood', 'missingBracket', 'missRightKey', 'multiString', 'nestedArray', 'noFile', 'samplePackage', 'start', 'stringyKeys', 'undefined', 'values' ] describe('Parser', () => { const oldLog = console.log; const oldError = console.error; const oldWarn = console.warn; for (const TEST of TESTS) { test(TEST, () => { let expected = readFileSync(`test/parserTests/expected/${TEST}.txt`, 'utf8'); let actual = ''; console.log = console.error = console.warn = (msg) => { actual += msg + '\n'; }; jsonLogger(`test/parserTests/examples/${TEST}.json`); expected = cleanString(expected); actual = cleanString(actual); console.log = oldLog; console.error = oldError; console.warn = oldWarn; expect(actual).toBe(expected); }); } });