Skip to content

Commit

Permalink
fixed tests and package files
Browse files Browse the repository at this point in the history
  • Loading branch information
Rune Bjerke committed Mar 8, 2015
1 parent ef438de commit 1046a29
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"package.json"
],
"repository": {
"url": "git://github.com/sp00x/json-optimize.git",
"url": "https://github.com/sp00x/json-optimize.git",
"type": "git"
}
}
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
"license": "MIT",
"repository": {
"type": "git",
"url": "git://github.com/sp00x/json-optimize.git"
"url": "https://github.com/sp00x/json-optimize.git"
},
"homepage": "https://github.com/sp00x/json-optimize",
"bugs": {
"url" : "https://github.com/sp00x/json-optimize/issues"
},
"scripts": {
"test": "node tests/test.js",
Expand Down
32 changes: 21 additions & 11 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,19 @@ var deep2 = [
{ t: 'Object of nonequality stuff', v: { foo: base2Bare, bar: [ base2Bare ] }, assert: false }
];

var tests = [].concat(base, deep, deep2);
var tests = [].concat(base, base2, deep, deep2);

if (typeof require === 'function')
if (isScript)
{
var fs = require('fs');
if (fs.existsSync('test.json'))
tests.push({ t: 'Big JSON sample', v: JSON.parse(fs.readFileSync("test.json")) });
var fn = "tests/test-mtg-data.json";
var fs = require('fs');
if (fs.existsSync(fn))
{
console.log("reading " + fn + " ..")
tests.push({ t: 'Big JSON sample', v: JSON.parse(fs.readFileSync(fn)) });
}
else
console.warn(fn + " not found, run 'npm run-script test-size' to download");
}

function len(o) { return o ? o.length : NaN; }
Expand All @@ -59,6 +65,8 @@ function test(test, i)
{
try
{
console.info("\n" + test.t + "..");

var before = test.v;

var jsonIn = JSON.stringify(before);
Expand All @@ -67,30 +75,32 @@ function test(test, i)
var after = jo.unpack(frozen);
var jsonOut = JSON.stringify(after);

console.info(test.t); // + ": " + len(jsonIn) + " -> " + len(jsonTemp) + " (" + Math.round(100 * len(jsonTemp) / len(jsonIn)) + "%)");
//console.info(test.t + ": " + len(jsonIn) + " -> " + len(jsonTemp) + " (" + Math.round(100 * len(jsonTemp) / len(jsonIn)) + "%)");

var assertError = false;

if (test.assert && assert)
{
assert.deepEqual(before, after, 'MISMATCH!');
assert.deepEqual('MISMATCH!');
}

if (jsonIn != jsonOut)
{
throw new Error("MISMATCH!");
}

console.info(" OK");
}
catch (e)
{
console.error(e, e.stackTrace);
console.error(' ' + e, e.stackTrace);

if (isScript)
{
var fs = require('fs');
fs.writeFileSync('error-before-' + i + '.json', JSON.stringify(before, null, ' '));
fs.writeFileSync('error-json-optimize-' + i + '.json', JSON.stringify(frozen, null, ' '));
fs.writeFileSync('error-after-' + i + '.json', JSON.stringify(after, null, ' '));
fs.writeFileSync('tests/error-before-' + i + '.json', JSON.stringify(before, null, ' '));
fs.writeFileSync('tests/error-json-optimize-' + i + '.json', JSON.stringify(frozen, null, ' '));
fs.writeFileSync('tests/error-after-' + i + '.json', JSON.stringify(after, null, ' '));
}

console.dir(before);
Expand Down

0 comments on commit 1046a29

Please sign in to comment.