Skip to content

Commit

Permalink
Refactor for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Mindru authored and danmindru committed Feb 23, 2020
1 parent b3e0c77 commit f298f8b
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 6 deletions.
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -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"
]
}
}
6 changes: 6 additions & 0 deletions tasks/check-for-unused.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down
4 changes: 1 addition & 3 deletions tests/e2e/end-to-end.test.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
11 changes: 11 additions & 0 deletions tests/sample/configs/config-with-unused.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
"slogan": "LED Pylon. LED Wall. Digital Signage.",
"logoUrl": "/assets/dark.png",
"logoAlt": "dark logo",
"website": "http://dark.dk"
}
12 changes: 11 additions & 1 deletion tests/unit/check-for-unused.js
Original file line number Diff line number Diff line change
@@ -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 changes: 5 additions & 0 deletions tests/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const fs = require('fs');

module.exports = {
readFileSync: path => fs.readFileSync(('./', path), 'utf8')
}

0 comments on commit f298f8b

Please sign in to comment.