ADD unit tests
This commit is contained in:
parent
013bd3d897
commit
f778465728
@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -29,5 +29,4 @@ const ResumeToPdf = {
|
||||
await Server.kill();
|
||||
}
|
||||
};
|
||||
|
||||
ResumeToPdf.convert();
|
||||
module.exports = ResumeToPdf;
|
||||
|
||||
@ -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();
|
||||
});
|
||||
|
||||
2
src/generatePdfs.js
Normal file
2
src/generatePdfs.js
Normal file
@ -0,0 +1,2 @@
|
||||
const ResumeToPdf = require('./ResumeToPdf');
|
||||
ResumeToPdf.convert();
|
||||
18
test/ResumeToPdf.js
Normal file
18
test/ResumeToPdf.js
Normal file
@ -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
|
||||
});
|
||||
});
|
||||
});
|
||||
0
test/Server.js
Normal file
0
test/Server.js
Normal file
64
test/StyleCompiler.js
Normal file
64
test/StyleCompiler.js
Normal file
@ -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()
|
||||
});
|
||||
86
test/Util.js
86
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));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -1 +1 @@
|
||||
alskldjaksldjaklsjdla0.4894462079149253
|
||||
alskldjaksldjaklsjdla0.6817729887314716
|
||||
Loading…
x
Reference in New Issue
Block a user