Script and tag cleanup, fixed select tests

This commit is contained in:
Angelos Chalaris
2018-01-16 15:15:51 +02:00
parent b37c30d175
commit d8936631e2
8 changed files with 33 additions and 24 deletions

View File

@ -12,7 +12,8 @@ script:
- npm run linter
- npm run builder
- npm run webber
- npm run module
- npm run packager
- npm run tester
after_success:
- chmod +x .travis/push.sh
- .travis/push.sh

View File

@ -26,8 +26,8 @@
"linter": "node ./scripts/lint.js",
"tagger": "node ./scripts/tag.js",
"webber": "node ./scripts/web.js",
"tdd": "node ./scripts/tdd.js",
"module": "node ./scripts/module.js",
"tester": "node ./scripts/tdd.js",
"packager": "node ./scripts/module.js",
"test": "tape test/**/*.test.js | tap-spec"
},
"repository": {

View File

@ -19,7 +19,7 @@ const IMPORTS = './imports.js';
// Regex for selecting code blocks
const codeRE = /```\s*js([\s\S]*?)```/;
// Start the timer of the script
console.time('Module');
console.time('Packager');
// Load tag data from the database and snippets from their folder
try {
const tagDatabase = fs.readFileSync('tag_database', 'utf8');
@ -72,7 +72,7 @@ try {
// Log a success message
console.log(`${chalk.green('SUCCESS!')} Snippet module built!`);
// Log the time taken
console.timeEnd('Module');
console.timeEnd('Packager');
} catch (err) {
// Handle errors (hopefully not!)
console.log(`${chalk.red('ERROR!')} During module creation: ${err}`);

View File

@ -59,7 +59,7 @@ try {
tagDbStats = Object.entries(tagDbData)
.sort((a, b) => a[1][0].localeCompare(b[1][0]))
.reduce((acc, val) => {
acc.hasOwnProperty(val[1]) ? acc[val[1]]++ : (acc[val[1]] = 1);
val[1].forEach(v => acc.hasOwnProperty(v) ? acc[v]++ : (acc[v] = 1));
return acc;
}, {});
} catch (err) {

View File

@ -4,7 +4,8 @@
*/
// Load modules
const fs = require('fs-extra');
const fs = require('fs-extra'), path = require('path');
const child_process = require('child_process');
const chalk = require('chalk');
// Load helper functions (these are from existing snippets in 30 seconds of code!)
const isTravisCI = () => 'TRAVIS' in process.env && 'CI' in process.env;
@ -29,12 +30,12 @@ snippetFiles.push(...snippetFilesArchive);
// Current Snippet that depend on node_modules
const errSnippets = ['JSONToFile', 'readFileLines', 'UUIDGeneratorNode'];
console.time('Tester');
snippetFiles
.filter(fileName => !errSnippets.includes(fileName))
.map(fileName => {
// Check if fileName for snippet exist in test/ dir, if doesnt create
fs.ensureDirSync(`${TEST_PATH}/${fileName}`);
fs.ensureDirSync(path.join(TEST_PATH,fileName));
// return fileName for later use
return fileName;
@ -42,7 +43,7 @@ snippetFiles
.map(fileName => {
const activeOrArchive = snippetFilesActive.includes(fileName) ? SNIPPETS_ACTIVE : SNIPPETS_ARCHIVE;
// Grab snippetData
const fileData = fs.readFileSync(`${activeOrArchive}/${fileName}.md`, 'utf8');
const fileData = fs.readFileSync(path.join(activeOrArchive,`${fileName}.md`), 'utf8');
// Grab snippet Code blocks
const fileCode = fileData.slice(fileData.search(/```\s*js/i), fileData.lastIndexOf('```') + 3);
// Split code based on code markers
@ -80,9 +81,9 @@ snippetFiles
].join('\n');
// Write/Update exportFile which is snippetName.js in respective dir
fs.writeFileSync(`${TEST_PATH}/${fileName}/${fileName}.js`, exportFile);
fs.writeFileSync(path.join(TEST_PATH,fileName,`${fileName}.js`), exportFile);
if ( !fs.existsSync(`${TEST_PATH}/${fileName}/${fileName}.test.js`) ) {
if ( !fs.existsSync(path.join(TEST_PATH,fileName,`${fileName}.test.js`)) ) {
// if snippetName.test.js doesn't exist inrespective dir exportTest
fs.writeFileSync(`${TEST_PATH}/${fileName}/${fileName}.test.js`, exportTest);
}
@ -90,4 +91,11 @@ snippetFiles
// return fileName for later use
return fileName;
});
try {
fs.writeFileSync(path.join(TEST_PATH,'testlog'),`Test log for: ${new Date().toString()}\n`);
child_process.execSync(`npm test >> ${TEST_PATH}/testlog`);
}
catch (e) {
fs.appendFileSync(path.join(TEST_PATH,'testlog'));
}
console.timeEnd('Tester');

View File

@ -75,7 +75,7 @@ indexOfAll:array
initial:array
initialize2DArray:array
initializeArrayWithRange:array,math
initializeArrayWithValues:array,amth
initializeArrayWithValues:array,math
inRange:math
intersection:array,math
invertKeyValues:object
@ -116,7 +116,7 @@ median:math,array
memoize:function
merge:object,array
minBy:math,array,function
minN:array,amth
minN:array,math
negate:function
nthElement:array
objectFromPairs:object,array

View File

@ -1,2 +1,2 @@
module.exports = select = (from, selector) =>
selector.split('.').reduce((prev, cur) => prev && prev[cur], from);
module.exports = select = (from, ...selectors) =>
[...selectors].map(s => s.split('.').reduce((prev, cur) => prev && prev[cur], from));

View File

@ -6,7 +6,7 @@ test('Testing select', (t) => {
//Please go to https://github.com/substack/tape
t.true(typeof select === 'function', 'select is a Function');
const obj = { selector: { to: { val: 'val to select' } } };
t.equal(select(obj, 'selector.to.val'), 'val to select', "Retrieve a property indicated by the selector from an object.");
t.deepEqual(select(obj, 'selector.to.val'), ['val to select'], "Retrieve a property indicated by the selector from an object.");
//t.deepEqual(select(args..), 'Expected');
//t.equal(select(args..), 'Expected');
//t.false(select(args..), 'Expected');