diff --git a/asdasdasd b/asdasdasd new file mode 100644 index 0000000..fed97c9 --- /dev/null +++ b/asdasdasd @@ -0,0 +1 @@ +any content \ No newline at end of file diff --git a/package.json b/package.json index a4c32f6..006ce1c 100755 --- a/package.json +++ b/package.json @@ -25,9 +25,10 @@ "readme": "node --harmony-async-await src/RenderReadMe.js", "start": "npm run babel && npm run less && npm run server", "dev": "watch 'npm start' src/ resumes/ less/", - "pdf": "npm run babel && npm run less && node --harmony-async-await src/ResumeToPdf.js", + "pdf": "npm run babel && npm run less && node --harmony-async-await src/generatePdfs.js", "lint": "eslint src/", - "test": "mocha" + "test": "mocha --harmony-async-await \"test/*.js\"", + "istanbul": "istanbul cover node_modules/.bin/_mocha -- -- -u exports test/**/* --harmony-async-await" }, "dependencies": { "@typopro/web-montserrat": "3.4.9", @@ -67,6 +68,7 @@ }, "devDependencies": { "eslint": "3.15.0", + "istanbul": "^0.4.5", "mocha": "3.2.0" } } diff --git a/pdf/resume-grey-boxes.pdf b/pdf/resume-grey-boxes.pdf index 9295c82..625e413 100755 Binary files a/pdf/resume-grey-boxes.pdf and b/pdf/resume-grey-boxes.pdf differ diff --git a/pdf/resume-left-right.pdf b/pdf/resume-left-right.pdf index aa8f27a..897ba71 100755 Binary files a/pdf/resume-left-right.pdf and b/pdf/resume-left-right.pdf differ diff --git a/pdf/resume-oblique.pdf b/pdf/resume-oblique.pdf index 4d3221c..a1add1b 100755 Binary files a/pdf/resume-oblique.pdf and b/pdf/resume-oblique.pdf differ diff --git a/pdf/resume-side-bar.pdf b/pdf/resume-side-bar.pdf index 77c10b4..618fb83 100755 Binary files a/pdf/resume-side-bar.pdf and b/pdf/resume-side-bar.pdf differ diff --git a/pdf/resume-spotify.pdf b/pdf/resume-spotify.pdf index 29c3132..8805823 100755 Binary files a/pdf/resume-spotify.pdf and b/pdf/resume-spotify.pdf differ diff --git a/pdf/resume-wanted.pdf b/pdf/resume-wanted.pdf index b3e601f..f4b7b9f 100755 Binary files a/pdf/resume-wanted.pdf and b/pdf/resume-wanted.pdf differ diff --git a/src/ResumeToPdf.js b/src/ResumeToPdf.js index 3e0cdb0..6e16a64 100755 --- a/src/ResumeToPdf.js +++ b/src/ResumeToPdf.js @@ -29,5 +29,4 @@ const ResumeToPdf = { await Server.kill(); } }; - -ResumeToPdf.convert(); +module.exports = ResumeToPdf; diff --git a/src/Util.js b/src/Util.js index 7c8453d..783c9fb 100755 --- a/src/Util.js +++ b/src/Util.js @@ -56,9 +56,9 @@ const Util = { * @param {string} content content of file * @return {Promise} */ - writeFile: function(dir, content) { + writeFile: async function(dir, content) { return new Promise((res, rej) => { - writeFile(dir, content, err => { + writeFile(dir, content, (err) => { if (err) rej(err); res(); }); diff --git a/src/generatePdfs.js b/src/generatePdfs.js new file mode 100644 index 0000000..36b0c59 --- /dev/null +++ b/src/generatePdfs.js @@ -0,0 +1,2 @@ +const ResumeToPdf = require('./ResumeToPdf'); +ResumeToPdf.convert(); diff --git a/test/ResumeToPdf.js b/test/ResumeToPdf.js new file mode 100644 index 0000000..52c6768 --- /dev/null +++ b/test/ResumeToPdf.js @@ -0,0 +1,18 @@ +/* global it, describe */ +const assert = require('assert'); +const ResumeToPdf = require('../src/ResumeToPdf'); +describe('ResumeToPdf', () => { + describe('#electroshotScript()', () => { + it('should return a string to execute', () => { + const resume = 'resume-any'; + const exec = ResumeToPdf.electroshotScript(resume); + assert(exec != null); + assert(exec.includes(resume)); + }); + }); + describe('#convert()', () => { + it('should return a string to execute', () => { + // TODO write test with spy + }); + }); +}); diff --git a/test/Server.js b/test/Server.js new file mode 100644 index 0000000..e69de29 diff --git a/test/StyleCompiler.js b/test/StyleCompiler.js new file mode 100644 index 0000000..6d951ab --- /dev/null +++ b/test/StyleCompiler.js @@ -0,0 +1,64 @@ +/* global it, describe */ +const assert = require('assert'); +const StyleCompiler = require('../src/StyleCompiler'); + +describe('StyleCompiler', () => { + describe('#compile()', () => { + it('should return a promise', () => { + const less = '@color: blue; h1{ color: @color; }'; + const promise = StyleCompiler.compile(less); + assert(promise instanceof Promise); + }); + describe('positive', () => { + it('should compile less to css', async() => { + const less = '@color: blue; h1{ color: @color; }'; + const expected = 'h1 {\n color: blue;\n}\n'; + const css = await StyleCompiler.compile(less); + assert.equal(css, expected); + + }); + it('should not throw an error when compiling to css', () => { + const less = '@color: blue; h1{ color: @color; }'; + StyleCompiler.compile(less) + .catch(err => assert(err == null)); + }); + }); + describe('negative', () => { + it('should throw an error if less is not correct', () => { + const less = '@color: blue; h1#asd+yx[]{ color: @color; }'; + StyleCompiler.compile(less) + .then(css => assert(css == null)) + .catch(err => assert(err != null)); + }); + }); + }); + describe('#minify()', () => { + it('should return a promise', () => { + const less = '@color: blue; h1{ color: @color; }'; + const promise = StyleCompiler.compile(less); + assert(promise instanceof Promise); + }); + describe('positive', () => { + it('should minify css', async() => { + const css = 'h1 {\n color: blue;\n}\n'; + const expected = 'h1{color:#00f}'; + const minified = await StyleCompiler.minify(css); + assert.equal(minified.styles, expected); + }); + it('should not throw an error when minifying css', () => { + const css = 'h1 {\n color: blue;\n}\n'; + StyleCompiler.compile(css) + .catch(err => assert(err == null)); + }); + }); + describe('negative', () => { + it('should throw an error if css is not correct', () => { + const css = 'h1 {\n color: #yxcöklljasd+blue;\n}\n'; + StyleCompiler.compile(css) + .then(minified => assert(minified == null)) + .catch(err => assert(err != null)); + }); + }); + }); + // TODO test for .run() +}); diff --git a/test/Util.js b/test/Util.js index 5f24482..bc7fb62 100644 --- a/test/Util.js +++ b/test/Util.js @@ -23,6 +23,10 @@ describe('Util', () => { }); }); describe('#setTimeout', () => { + it('should return a promise', () => { + const promise = Util.setTimeout(200); + assert(promise instanceof Promise); + }); it('should resolve promise after given amount of time', () => { const ms = 100; let resolved = false; @@ -39,37 +43,77 @@ describe('Util', () => { .catch(err => assert(err === null)); }); }); - describe('#readFileContent', () => { - it('should resolve promise and return file content', () => { + describe('#readFileContent', async() => { + it('should return a promise', () => { const p = path.join(__dirname, './files/readFile.txt'); - Util.readFileContent(p) - .then(content => assert(content.includes('any content to be read'))); + const promise = Util.readFileContent(p); + assert(promise instanceof Promise); }); - it('should reject promise and return error', () => { - const p = 'asdasdasd'; - Util.readFileContent(p) - .then(content => assert(content === null)) - .catch(err => assert(err != null)); + describe('positive', () => { + it('should return file content if file exists', async() => { + const p = path.join(__dirname, './files/readFile.txt'); + const content = await Util.readFileContent(p); + assert(content.includes('any content to be read')); + }); + it('should not return any error if file exists', async() => { + const p = path.join(__dirname, './files/readFile.txt'); + Util.readFileContent(p) + .catch(err => assert(err == null)); + }); + }); + describe('negative', () => { + it('should reject promise and return error if file does not exist', () => { + const p = 'asdasdasd'; + Util.readFileContent(p) + .then(content => assert(content === null)) + .catch(err => assert(err != null)); + }); }); }); describe('#writeFile', () => { - it('should resolve promise and write file content', () => { + it('should return a promise', () => { const p = path.join(__dirname, './files/writeFile.txt'); - const content = 'alskldjaksldjaklsjdla' + Math.random(); - Util.writeFile(p, content) - .then(() => { - Util.readFileContent(p).then(c => { + const promise = Util.writeFile(p, 'any content'); + assert(promise instanceof Promise); + }); + describe('positive', () => { + it('should write file content if file exists and not throw any error', () => { + const p = path.join(__dirname, './files/writeFile.txt'); + const content = 'alskldjaksldjaklsjdla' + Math.random(); + Util.writeFile(p, content) + .then(async() => { + const c = await Util.readFileContent(p); assert.equal(c, content); - }); - }) - .catch(err => assert(err === null)); + }) + .catch(err => assert(err === null)); + }); + }); + describe('negative', () => { + it('should reject promise and return error if file does not exist', () => { + const p = 'asdasdasd'; + Util.writeFile(p, 'any content') + .then() + .catch(err => assert(err != null)); + }); }); }); describe('#execBash', () => { - it('should execute bash script and resolve promise', () => { - Util.execBash('echo "Hello world"') - .then() - .catch(err => assert(err === null)); + it('should return a promise', () => { + const promise = Util.execBash('echo "Hello World"'); + assert(promise instanceof Promise); + }); + describe('positive', () => { + it('should execute bash script and resolve promise', () => { + Util.execBash('echo "Hello world"') + .then() + .catch(err => assert(err === null)); + }); + }); + describe('negative', () => { + it('should try to execute false bash script and reject promise', () => { + Util.execBash('asdlkajsd!+##') + .catch(err => assert(err != null)); + }); }); }); }); diff --git a/test/files/writeFile.txt b/test/files/writeFile.txt index 062cbe9..3bb775a 100644 --- a/test/files/writeFile.txt +++ b/test/files/writeFile.txt @@ -1 +1 @@ -alskldjaksldjaklsjdla0.4894462079149253 \ No newline at end of file +alskldjaksldjaklsjdla0.6817729887314716 \ No newline at end of file