Skip to content

Commit e8681c3

Browse files
authored
Add date to report (#7)
* directory restructure * add date to report using date utility * WIP test date utils * Fix date test
1 parent 794d14c commit e8681c3

File tree

17 files changed

+198
-19
lines changed

17 files changed

+198
-19
lines changed

docs/templates.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Templates
2+
3+
These templates shouldn't be tested on their own. They're used to generate multiple tests in their respective directories, `ava`, `jest`, and `mocha`.
4+
5+
Defining `require` paths to files in the templates should be relative to `<root>/test/<runner>` not necessarily relative to the templates directory.

package-lock.json

Lines changed: 125 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"eslint-config-prettier": "^6.10.0",
3232
"eslint-plugin-import": "^2.20.0",
3333
"eslint-plugin-prettier": "^3.1.2",
34-
"prettier": "1.19.1"
34+
"prettier": "1.19.1",
35+
"sinon": "^9.0.2"
3536
},
3637
"ava": {
3738
"verbose": true

src/fullCircle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ const fullCircle = (self, wait) => {
1414
return self;
1515
};
1616

17-
module.exports = { fullCircle };
17+
module.exports = { fullCircle, main: fullCircle };

src/generateTests/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const TEST_RUNNERS = [AVA, JEST, MOCHA];
55

66
// relative to root
77
const TEST_DIR = './test';
8-
const TEMPLATE_DIR = './src/generateTests/templates';
8+
const TEMPLATE_DIR = './test/templates';
99

1010
const getTemplatePath = testRunner => `${TEMPLATE_DIR}/${testRunner}.js`;
1111
const getDestPath = testRunner => `${TEST_DIR}/${testRunner}`;

src/generateTests/generateTestFiles.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const { promises: fsPromises } = require('fs');
2-
const { range } = require('../range');
2+
3+
const { range } = require('../utils');
34
const { TEMPLATE_PATHS, TEST_RUNNERS } = require('./config');
45

56
const createTestFilename = (num, testDir, testRunner) =>

src/runAllTests.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
const execa = require('execa');
2-
const { shuffle } = require('./');
2+
3+
const { getDateTime, shuffle } = require('./utils');
34

45
// CONSTANTS
56

67
const TEST_RUNNERS = ['ava', 'jest', 'mocha', 'parallel'];
78
const DOTS = '. '.repeat(16);
89
const testRunners = shuffle(TEST_RUNNERS);
910

11+
// just run one for now
12+
// const testRunners = shuffle(TEST_RUNNERS).slice(0, 1);
13+
1014
// UTILS
1115

1216
/**
@@ -66,6 +70,13 @@ const logTestTitle = name => {
6670
console.log('\n\n', DOTS, '\n running tests for', name, '\n', DOTS, '\n\n');
6771
};
6872

73+
const logResultsHeader = () => {
74+
console.log(`\n${'-*'.repeat(20)}`);
75+
console.log(`RESULTS ${getDateTime()}`);
76+
console.log('order:', testRunners);
77+
console.log('');
78+
};
79+
6980
// sort, format, and log test results
7081
const logResults = resultsArr => {
7182
resultsArr
@@ -92,9 +103,6 @@ const testData = testRunners.reduce((acc, name) => {
92103
return acc;
93104
}, {});
94105

95-
// just run one for now
96-
// const sliced = testRunners.slice(0, 1);
97-
98106
const main = () => {
99107
try {
100108
const testResults = [];
@@ -109,10 +117,7 @@ const main = () => {
109117
testResults.push(testData[name]);
110118
}
111119

112-
console.log(`-*-*-*-*-*-*-*-*-*-*-
113-
RESULTS
114-
-*-*-*-*-*-*-*-*-*-*-\n`);
115-
console.log('order:', testRunners, '\n');
120+
logResultsHeader();
116121
logResults(testResults);
117122
} catch (error) {
118123
console.error(error);

src/utils/date.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const options = {
2+
weekday: 'long',
3+
year: 'numeric',
4+
month: 'long',
5+
day: 'numeric',
6+
};
7+
8+
const getDateTime = (inputDate = new Date()) => {
9+
const date = inputDate.toLocaleDateString(undefined, options);
10+
const time = `${inputDate.getHours()}:${inputDate.getMinutes()}:${inputDate.getSeconds()}`;
11+
return `${date} ${time}`;
12+
};
13+
14+
module.exports = {
15+
getDateTime,
16+
};
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
const { fullCircle } = require('./fullCircle');
1+
const dateUtils = require('./date');
22
const { range } = require('./range');
33
const { shuffle } = require('./shuffle');
44

55
module.exports = {
6-
fullCircle,
6+
...dateUtils,
77
range,
88
shuffle,
99
};
File renamed without changes.

0 commit comments

Comments
 (0)