Refactor for tests

This commit is contained in:
Dan Mindru 2019-09-12 19:26:06 +02:00 committed by Dan Mindru
parent b3e0c77988
commit f298f8bd85
6 changed files with 42 additions and 6 deletions

View File

@ -26,7 +26,8 @@
"start": "node ./node_modules/.bin/gulp",
"once": "node ./node_modules/.bin/gulp run-pipeline",
"deploy": "npm run test && cp -r dist demo && git push origin `git subtree split --prefix demo develop`:gh-pages --force",
"e2e-test": "npm run once && node ./node_modules/.bin/ava",
"test": "npm run once && node ./node_modules/.bin/ava",
"test:watch": "npm run once && node ./node_modules/.bin/ava --watch",
"format": "prettier {tasks,tests}/**/*.js gulpfile.js .eslintrc.js --write",
"lint": "eslint ./**/*.js gulpfile.js"
},
@ -73,8 +74,13 @@
],
"husky": {
"hooks": {
"pre-push": "npm run e2e-test",
"pre-push": "npm run test",
"pre-commit": "npm run lint && ./node_modules/.bin/pretty-quick --staged --pattern ./**/*.js"
}
},
"ava": {
"helpers": [
"**/util.js"
]
}
}

View File

@ -33,6 +33,12 @@ const outputWarningsForUnusedItems = (unusedItems, configs) => {
});
};
/**
* In a directory, checks for unused configs.
*
* @param { string } rootDir
* @param { Array } configs Array of configs.
*/
const checkForUnusedItemsInConfigs = (rootDir, configs) => {
return Promise.all(
configs.map(async ({ dir, confItems }) => {

View File

@ -1,8 +1,6 @@
const test = require('ava');
const fs = require('fs');
const path = require('path');
const readFileSync = path => fs.readFileSync(('../', path), 'utf8');
const { readFileSync } = require('../util');
test('dark signature output', async t => {
const expected = readFileSync('tests/sample/dark/signature-dark.html');

View File

@ -0,0 +1,11 @@
{
"id": "dark",
"signature": "Best regards,",
"name": "The dark mail team",
"contactMain": "Call <a href='tel:004580100100'><span>(45) 80100100</span></a> or email us at",
"contactMail": "info@dark.dk",
"slogan": "LED Pylon. LED Wall. Digital Signage.",
"logoUrl": "/assets/dark.png",
"logoAlt": "dark logo",
"website": "http://dark.dk"
}

View File

@ -1,3 +1,13 @@
const test = require('ava');
const { checkForUnusedItemsInConfigs } = require('../../tasks/check-for-unused.js');
const { readFileSync } = require('../util');
test('noop', async t => { t.deepEqual('', ''); });
test('getting templates from filelist', async t => {
const configs = [
{ confItems: [readFileSync('tests/sample/configs/config-with-unused.json')], dir: 'dark' }
];
const expect = [[[[]]]];
const result = [await checkForUnusedItemsInConfigs('tests/sample', configs)];
t.deepEqual(result, expect);
});

5
tests/util.js Normal file
View File

@ -0,0 +1,5 @@
const fs = require('fs');
module.exports = {
readFileSync: path => fs.readFileSync(('./', path), 'utf8')
}