Skip to content

Commit

Permalink
Remove unnecessary compareReflections
Browse files Browse the repository at this point in the history
It did nothing more than Assert.deepStrictEqual, since if the objects weren't exactly the same deepEqual would throw.
  • Loading branch information
Gerrit0 committed Oct 13, 2019
1 parent 66ddd00 commit f5b5837
Showing 1 changed file with 5 additions and 59 deletions.
64 changes: 5 additions & 59 deletions src/test/converter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,6 @@ import * as FS from 'fs';
import * as Path from 'path';
import Assert = require('assert');

function compareReflections(fixture, spec, path?: string) {
path = (path ? path + '/' : '') + spec.name;
Assert.deepEqual(fixture, spec);

for (let key in spec) {
if (!spec.hasOwnProperty(key)) {
continue;
}
Assert(fixture.hasOwnProperty(key), path + ': Missing property "' + key + '"');
}

for (let key in fixture) {
if (!fixture.hasOwnProperty(key) || typeof fixture[key] === 'undefined') {
continue;
}
Assert(spec.hasOwnProperty(key), path + ': Unknown property "' + key + '"');

const a = fixture[key];
const b = spec[key];
Assert(a instanceof Object === b instanceof Object, path + ': Property "' + key + '" type mismatch');

if (a instanceof Object) {
switch (key) {
case 'signatures':
case 'typeParameters':
case 'children':
compareChildren(a, b, path);
break;
case 'indexSignature':
case 'getSignature':
case 'setSignature':
compareReflections(a, b, path);
break;
default:
Assert.deepEqual(a, b, path + ': Property "' + key + '" value mismatch');
}
} else {
Assert(a === b, path + ': Property "' + key + '" value mismatch');
}
}
}

function compareChildren(fixture, spec, path) {
const a = fixture.map(function(child) { return child.id; });
const b = spec.map(function(child) { return child.id; });

Assert(a.length === b.length, path + ': Number of children differs');
Assert(a.every(function(u, i) { return u === b[i]; }), path + ': Children are different');

fixture.forEach(function(a, index) {
compareReflections(a, spec[index], path);
});
}

describe('Converter', function() {
const base = Path.join(__dirname, 'converter');
let app: Application;
Expand Down Expand Up @@ -93,7 +39,7 @@ describe('Converter', function() {
let data = JSON.stringify(app.serializer.projectToObject(result!), null, ' ');
data = data.split(normalizePath(base)).join('%BASE%');

compareReflections(JSON.parse(data), specs);
Assert.deepStrictEqual(JSON.parse(data), specs);
});
});
});
Expand Down Expand Up @@ -131,7 +77,7 @@ describe('Converter with categorizeByGroup=false', function() {
let data = JSON.stringify(app.serializer.projectToObject(result!), null, ' ');
data = data.split(normalizePath(base)).join('%BASE%');

compareReflections(JSON.parse(data), specs);
Assert.deepStrictEqual(JSON.parse(data), specs);
});
});

Expand All @@ -148,7 +94,7 @@ describe('Converter with categorizeByGroup=false', function() {
let data = JSON.stringify(app.serializer.projectToObject(result!), null, ' ');
data = data.split(normalizePath(base)).join('%BASE%');

compareReflections(JSON.parse(data), specs);
Assert.deepStrictEqual(JSON.parse(data), specs);
});
});
});
Expand Down Expand Up @@ -185,7 +131,7 @@ describe('Converter with excludeNotExported=true', function() {
let data = JSON.stringify(app.serializer.projectToObject(result!), null, ' ');
data = data.split(normalizePath(base)).join('%BASE%');

compareReflections(JSON.parse(data), specs);
Assert.deepStrictEqual(JSON.parse(data), specs);
});
});

Expand All @@ -201,7 +147,7 @@ describe('Converter with excludeNotExported=true', function() {
let data = JSON.stringify(app.serializer.projectToObject(result!), null, ' ');
data = data.split(normalizePath(base)).join('%BASE%');

compareReflections(JSON.parse(data), specs);
Assert.deepStrictEqual(JSON.parse(data), specs);
});
});

Expand Down

0 comments on commit f5b5837

Please sign in to comment.