Skip to content

Commit 02cecf2

Browse files
committed
teardown tests
1 parent aacd6f4 commit 02cecf2

File tree

4 files changed

+65
-2
lines changed

4 files changed

+65
-2
lines changed

test/crasher.test.js

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const Helper = require('./helper')
1010
const dirname = __dirname
1111

1212
test('crasher uncaught exception', async function (t) {
13+
t.plan(2)
14+
1315
const dir = path.join(dirname, 'fixtures', 'crasher-uncaught-exception')
1416

1517
const teardown = Helper.rig({ runtimeArgv: [dir] })
@@ -39,6 +41,8 @@ test('crasher uncaught exception', async function (t) {
3941
})
4042

4143
test('crasher unhandled rejection', async function (t) {
44+
t.plan(2)
45+
4246
const dir = path.join(dirname, 'fixtures', 'crasher-unhandled-rejection')
4347

4448
const teardown = Helper.rig({ runtimeArgv: [dir] })
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const Helper = require('../../helper')
2+
3+
Helper.rig({ state: { config: { args: Bare.argv.slice(4) } } })
4+
5+
const pipe = Pear.pipe
6+
7+
Pear.teardown(async () => {
8+
await new Promise((resolve) => {
9+
pipe.write('teardown\n', resolve)
10+
})
11+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const Helper = require('../../helper')
2+
3+
Helper.rig({ state: { config: { args: Bare.argv.slice(4) } } })
4+
5+
const teardown = require('../../../teardown')
6+
7+
const pipe = Pear.pipe
8+
9+
teardown(async () => {
10+
await new Promise((resolve) => {
11+
pipe.write('teardown\n', resolve)
12+
})
13+
}, 10) // lower position runs first
14+
15+
teardown(async () => {
16+
await new Promise((resolve) => {
17+
pipe.write('error\n', resolve)
18+
})
19+
}, 100) // higher position runs later

test/teardown.test.js

+31-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,36 @@
11
'use strict'
22

33
const { test } = require('brittle')
4+
const path = require('bare-path')
45

5-
test('teardown', async function (t) {
6-
// TODO: write tests
6+
const Helper = require('./helper')
7+
8+
const dirname = __dirname
9+
10+
test('teardown default', async function (t) {
11+
t.plan(1)
12+
13+
const dir = path.join(dirname, 'fixtures', 'teardown-default')
14+
15+
const teardown = Helper.rig({ runtimeArgv: [dir] })
16+
t.teardown(teardown)
17+
18+
const pipe = Pear.run(dir)
19+
20+
const td = await Helper.untilResult(pipe, { runFn: () => pipe.end() })
21+
t.is(td, 'teardown', 'teardown executed')
22+
})
23+
24+
test('teardown with position', async function (t) {
25+
t.plan(1)
26+
27+
const dir = path.join(dirname, 'fixtures', 'teardown-with-position')
28+
29+
const teardown = Helper.rig({ runtimeArgv: [dir] })
30+
t.teardown(teardown)
31+
32+
const pipe = Pear.run(dir)
33+
34+
const td = await Helper.untilResult(pipe, { runFn: () => pipe.end() })
35+
t.is(td, 'teardown', 'teardown executed')
736
})

0 commit comments

Comments
 (0)