json-parser-yaml-converter
Version:
Enhanced JSON Parser with verbose error messages and JSON to YAML conversion
61 lines (56 loc) • 1.33 kB
JavaScript
/**
* This module tests the parser module.
*
* @module parser.test
*/
;
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);
});
}
});