UNPKG

my-own-words

Version:

A small tool that I have created to keep safe all those words/expressions that I come across when I'm learning a new language

67 lines (49 loc) 1.79 kB
const fs = require('fs'); const os = require('os'); const rimraf = require('rimraf'); const { assert } = require('chai'); const { dirExists, listExists, getAndParseWords } = require('../src/fs-helpers'); const { newList } = require('../src/new'); const { addWord } = require('../src/add'); const { print } = require('../src/print'); const home = os.homedir(); const route = `${home}\\.my-own-words`; describe('Before #print', () => { before(() => { rimraf.sync(route); }); it('should delete the directory', () => { assert.isFalse(dirExists()); }); it('should create a clear directory with an empty list', () => { const listName = 'italian'; newList(listName); assert.isTrue(dirExists()); assert.isTrue(listExists(listName)); }); it('list should have a word with two definitions', () => { const listName = 'italian'; const word = 'Ciao'; addWord(listName, word, 'Hi'); addWord(listName, word, 'Goodbye'); assert.property(getAndParseWords(listName), word); assert.include(getAndParseWords(listName)[word], 'Hi'); assert.include(getAndParseWords(listName)[word], 'Goodbye'); }); }); describe('#print', () => { it('should return a message if the list not exists', () => { const listName = 'spanish'; assert.strictEqual(print(listName), `${listName} list doesn't exists!`); }); it('should create a markdown document if the list exists', () => { const listName = 'italian'; print(listName); assert.isTrue(fs.existsSync(`${route}\\${listName}.md`)); }); it('document should be written with markdown', () => { const listName = 'italian'; const text = fs.readFileSync(`${route}\\${listName}.md`).toString(); assert.strictEqual(text, '**Ciao**: Goodbye, Hi. \n'); }); });