Skip to content

Commit 8b2edd1

Browse files
authored
feat: use Git created file timestamp, closes #159 (#160)
1 parent 51b05b1 commit 8b2edd1

File tree

5 files changed

+159
-85
lines changed

5 files changed

+159
-85
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ $ npx collect-fiddles --print cypress/e2e/A.md cypress/e2e/B.md
228228
$ npx collect-fiddles --filename out.json 'cypress/e2e/**/*.md'
229229
```
230230

231+
Note: for created timestamp, it gets the Git created date to avoid depending on the file write timestamps
232+
233+
```
234+
git log --diff-filter=A --follow --format=%aD -1 -- <filename>
235+
```
236+
231237
## Examples
232238

233239
See the presentation [Using End-to-end Tests as Documentation](https://slides.com/bahmutov/tests-are-docs)

bin/collect-fiddles.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,24 @@ debug('arguments %o', args)
2121

2222
// remove "node" and the script name from the list of arguments
2323
const markdownPattern = args._.slice(2)
24-
const fiddles = collectFiddlesIn(markdownPattern)
24+
collectFiddlesIn(markdownPattern)
25+
.then((fiddles) => {
26+
console.log(
27+
'found %d fiddle(s) across Markdown file(s)',
28+
fiddles.length,
29+
)
2530

26-
console.log(
27-
'found %d fiddle(s) across Markdown file(s)',
28-
fiddles.length,
29-
)
30-
31-
if (args['--print']) {
32-
console.log(fiddles)
33-
}
31+
if (args['--print']) {
32+
console.log(fiddles)
33+
}
3434

35-
if (args['--filename']) {
36-
const text = JSON.stringify(fiddles, null, 2) + '\n'
37-
fs.writeFileSync(args['--filename'], text)
38-
console.log('write fiddles to JSON file %s', args['--filename'])
39-
}
35+
if (args['--filename']) {
36+
const text = JSON.stringify(fiddles, null, 2) + '\n'
37+
fs.writeFileSync(args['--filename'], text)
38+
console.log('write fiddles to JSON file %s', args['--filename'])
39+
}
40+
})
41+
.catch((e) => {
42+
console.error(e)
43+
process.exit(1)
44+
})

0 commit comments

Comments
 (0)