thesaurus-synonyms-index-data
Version: 
INDEX - Words synonyms data scraped with spiders from thesaurus.com
61 lines (47 loc) • 1.96 kB
JavaScript
var should = require('should');
var dictionary = require('./index.js');
var verbose = !!(process.argv.indexOf('--verbose') !== -1 || process.argv.indexOf('-v') !== -1);
var letter = 'index';
var version = '1.0.0';
// exported functions
function test_exported(){
  dictionary.should.have.property('load').which.is.a.Function();
  dictionary.should.have.property('loadSync').which.is.a.Function();
  dictionary.should.have.property('version').which.is.a.String();
  should(dictionary.letter).be.exactly(letter);
  should(dictionary.version).be.exactly(version);
}
function _test_the_data(data) {
  if(verbose) process.stdout.write('length: '+data.length+'\r\n');
  data[0].should.have.property('letter').which.is.a.String().with.lengthOf(1);
  should(data.length).be.exactly(dictionary.length);
  data.should.be.instanceof(Array);
  for (var j = 0; j < /*data.length*/1; j++) {
    if (verbose) process.stdout.write('>>> index: '+j+'\r\n');
    data[j].should.be.an.instanceOf(Object);
    data[j].should.have.property('letter').which.is.a.String().with.lengthOf(1);
    if (verbose) process.stdout.write('letter: '+data[j].letter+'\r\n');
    data[j].should.have.property('url').which.is.a.String();
    if (verbose) process.stdout.write('url: '+data[j].url+'\r\n');
    data[j].should.have.property('text').which.is.a.String();
    if (verbose) process.stdout.write('text: '+data[j].key+'\r\n');
  }
}
// LOAD ASYNC
function test_load() {
  process.stdout.write('>>> '+dictionary.letter+'\r\n');
  dictionary.load(function(err, data) {
    if (err) throw err;
    _test_the_data(data);
  });
}
// LOAD SYNC
function test_loadSync() {
  process.stdout.write('>>> '+dictionary.letter+'\r\n');
  _test_the_data(dictionary.loadSync());
}
test_exported();
// test_load(); // fix this test to finish before 'All tests passed!' without adding dependencies
test_loadSync();
process.stdout.write('All tests passed! 👍 <<<\r\n');