import * as fs from 'fs-extra-promise'; import * as path from 'path'; console.log(__dirname); async function run() { let source = path.join(__dirname, "../test/config.json"); let result = await fs.readJSONAsync(source) as any; let target = path.join(__dirname, "../a.txt"); let content = await fs.readFileAsync(target, "utf-8"); var index = content.indexOf("{"); content = content.substr(index, content.length); let valid = JSON.parse(content); console.log(222) try { testEqual(result, valid) } catch (e) { console.log(e) } console.log(222) console.log("success") } function testEqual(a, b) { for (let key in a) { if (!b[key]) { throw `1 ${key}`; } if (typeof a === "object") { testEqual(a[key], b[key]); } if (a[key] != b[key]) { throw `2 ${key}`; } } } run();