• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nicholaswmin / dyno / 10360138570

12 Aug 2024 10:12PM UTC coverage: 95.046% (+0.4%) from 94.662%
10360138570

push

github

web-flow
feat: added global `before`/`after` hooks (#6)

* docs: tweaks

* docs: add renamed example

* fix: report evt loop in millis

* feat: added main before/after hooks and tests

* build: version bump

---------

Co-authored-by: Nicholas Kyriakides <nicholaswmin@Nicholass-MacBook-Air.local>

499 of 549 branches covered (90.89%)

Branch coverage included in aggregate %.

234 of 237 new or added lines in 10 files covered. (98.73%)

2168 of 2257 relevant lines covered (96.06%)

543.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.88
/test/integration/hooks/task.test.js
1
import fs from 'node:fs'
1✔
2
import test from 'node:test'
1✔
3
import { join } from 'node:path'
1✔
4
import { dyno } from '../../../index.js'
1✔
5

1✔
6
test('#dyno() task before/after hooks', async t => {
1✔
7
  let jsons = []
1✔
8

1✔
9
  t.before(async () => {
1✔
10
    const paths = [ 'before.json', 'task.json', 'after.json' ]
1✔
11
      .map(p => join(import.meta.dirname, `./tasks/temp/${p}`))
1✔
12

1✔
13
    paths.forEach(path => fs.rmSync(path, { force: true }))
1✔
14
    
1✔
15
    await dyno(join(import.meta.dirname, 'tasks/runs-hooks.js'), {
1✔
16
      parameters: { cyclesPerSecond: 5, threads: 2, durationMs: 200 }
1✔
17
    })
1✔
18
    
1✔
19
    jsons = paths.map(path => fs.readFileSync(path, 'utf8'))
1✔
20
      .map(file => JSON.parse(file))
1✔
21
      .sort((a, b) => a.created - b.created)
1✔
22
  })
1✔
23
  
1✔
24
  t.todo('single-file, local hooks', async t => {
1✔
NEW
25
    // @REVIEW
×
NEW
26
    // hard to test, single-file benchmarks means the main-file
×
NEW
27
    // is run as a thread
×
28
  })
1✔
29
  
1✔
30
  await t.test('all 3 hooks run', async t => {
1✔
31
    t.assert.strictEqual(jsons.length, 3)
1✔
32
  })
1✔
33

1✔
34
  await t.test('jsons created recently', async t => {
1✔
35
    const since = Date.now() - jsons.at(0).created < 1000
1✔
36
    t.assert.ok(since < 1000, `jsons were created > 1000ms ago, is ${since} ms`)
1✔
37
  })
1✔
38

1✔
39
  await t.test('#before hook', async t => {
1✔
40
    const i = jsons.findIndex(json => json.hook === 'before')
1✔
41
    
1✔
42
    await t.test('runs', async t => {
1✔
43
      t.assert.ok(jsons !== 1, 'no { hook: "before" } JSON found')
1✔
44
    })
1✔
45

1✔
46
    await t.test('runs first', async t => {
1✔
47
      t.assert.strictEqual(i, 0)
1✔
48
    })
1✔
49
  })
1✔
50
  
1✔
51
  await t.test('#task', async t => {
1✔
52
    const i = jsons.findIndex(json => json.hook === 'task')
1✔
53
    
1✔
54
    await t.test('runs', async t => {
1✔
55
      t.assert.ok(jsons !== 1, 'no { hook: "task" } JSON found')
1✔
56
    })
1✔
57

1✔
58
    await t.test('runs second', async t => {
1✔
59
      t.assert.strictEqual(i, 1)
1✔
60
    })
1✔
61
  })
1✔
62
  
1✔
63
  await t.test('#after hook', async t => {
1✔
64
    const i = jsons.findIndex(json => json.hook === 'after')
1✔
65
    
1✔
66
    await t.test('runs', async t => {
1✔
67
      t.assert.ok(jsons !== 1, 'no { hook: "after" } JSON found')
1✔
68
    })
1✔
69

1✔
70
    await t.test('runs last', async t => {
1✔
71
      t.assert.strictEqual(i, 2)
1✔
72
    })
1✔
73
  })
1✔
74
})
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc