diff --git a/package.json b/package.json index 53f5f0e..303db1c 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,8 @@ "start": "gulp", "once": "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" + ] } } diff --git a/tasks/check-for-unused.js b/tasks/check-for-unused.js index 0308434..4d02711 100644 --- a/tasks/check-for-unused.js +++ b/tasks/check-for-unused.js @@ -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 }) => { diff --git a/tests/e2e/end-to-end.test.js b/tests/e2e/end-to-end.test.js index 5d5dcf2..0c22c72 100644 --- a/tests/e2e/end-to-end.test.js +++ b/tests/e2e/end-to-end.test.js @@ -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'); diff --git a/tests/sample/configs/config-with-unused.json b/tests/sample/configs/config-with-unused.json new file mode 100644 index 0000000..02a5253 --- /dev/null +++ b/tests/sample/configs/config-with-unused.json @@ -0,0 +1,11 @@ +{ + "id": "dark", + "signature": "Best regards,", + "name": "The dark mail team", + "contactMain": "Call (45) 80100100 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" +} diff --git a/tests/unit/check-for-unused.js b/tests/unit/check-for-unused.js index 1caca2d..8efc708 100644 --- a/tests/unit/check-for-unused.js +++ b/tests/unit/check-for-unused.js @@ -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); +}); diff --git a/tests/util.js b/tests/util.js new file mode 100644 index 0000000..e285b72 --- /dev/null +++ b/tests/util.js @@ -0,0 +1,5 @@ +const fs = require('fs'); + +module.exports = { + readFileSync: path => fs.readFileSync(('./', path), 'utf8') +}