-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom.spec.js
40 lines (34 loc) · 1.02 KB
/
custom.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { strictEqual } from 'node:assert'
import { test } from 'node:test'
import { readFile } from 'node:fs/promises'
import { sep, mkPromise } from './test-util.js'
import Pcall from '../src/index.js'
const { log } = console
sep('_')
test('---STATIC--- [GOOD]', async () => {
sep('#')
const path = 'test/sample-good.json'
const opts = { encoding: 'utf8' }
const [err, res] = await Pcall(readFile, path, opts)
log('@STATIC::', res, '::')
log('>>', { err, res }, '<<<')
strictEqual(err, null)
})
test('---INSTANCE--- [GOOD]', async () => {
sep('#')
const path = 'test/sample-good.json'
const opts = { encoding: 'utf8' }
const pcall = new Pcall({
onSuccess: (res) => {
console.log('CUSTOM onSuccess handler', {args, res})
},
onFailure: 'foo', // illegals will be ignored
})
log('pcall', pcall)
const [err, res] = await pcall(readFile, path, opts)
log('@INSTANCE::', { err, res }, '::')
strictEqual(err, null)
})
// process.exit()
// log('##################')
// log('###################')