@@ -2,7 +2,6 @@ import assert from 'node:assert/strict'
2
2
import test from 'node:test'
3
3
import { fromHtml } from 'hast-util-from-html'
4
4
import { readingTime } from './index.js'
5
- import * as mod from './index.js'
6
5
7
6
// https://simple.wikipedia.org/wiki/Reading
8
7
const somewhatSimple = `<p>Reading is what we do when we understand writing.</p>
@@ -28,62 +27,67 @@ const somewhatComplex = `<p>Since the length or duration of words is clearly var
28
27
const tree = fromHtml ( somewhatComplex , { fragment : true } )
29
28
const treeSomewhatSimple = fromHtml ( somewhatSimple , { fragment : true } )
30
29
31
- test ( 'readingTime' , ( ) => {
32
- assert . deepEqual (
33
- Object . keys ( mod ) . sort ( ) ,
34
- [ 'readingTime' ] ,
35
- 'should expose the public api'
36
- )
30
+ test ( 'readingTime' , async function ( t ) {
31
+ await t . test ( 'should expose the public api' , async function ( ) {
32
+ assert . deepEqual ( Object . keys ( await import ( './index.js' ) ) . sort ( ) , [
33
+ 'readingTime'
34
+ ] )
35
+ } )
37
36
38
- assert . deepEqual (
39
- readingTime ( tree ) . toFixed ( 2 ) ,
40
- '1.22' ,
41
- 'should estimate (somewhat complex)'
42
- )
37
+ await t . test ( 'should estimate (somewhat complex)' , async function ( ) {
38
+ assert . deepEqual ( readingTime ( tree ) . toFixed ( 2 ) , '1.22' )
39
+ } )
43
40
44
- assert . deepEqual (
45
- readingTime ( treeSomewhatSimple ) . toFixed ( 2 ) ,
46
- '1.10' ,
47
- 'should estimate (somewhat simple)'
48
- )
41
+ await t . test ( 'should estimate (somewhat simple)' , async function ( ) {
42
+ assert . deepEqual ( readingTime ( treeSomewhatSimple ) . toFixed ( 2 ) , '1.10' )
43
+ } )
49
44
50
- assert . deepEqual (
51
- readingTime ( { type : 'root' , children : [ ] } ) . toFixed ( 2 ) ,
52
- '0.00' ,
53
- 'should estimate (empty)'
54
- )
45
+ await t . test ( 'should estimate (empty)' , async function ( ) {
46
+ assert . deepEqual (
47
+ readingTime ( { type : 'root' , children : [ ] } ) . toFixed ( 2 ) ,
48
+ '0.00'
49
+ )
50
+ } )
55
51
56
- assert . deepEqual (
57
- readingTime ( tree , { age : 12 } ) . toFixed ( 2 ) ,
58
- '2.44' ,
59
- 'should take age into account (1, somewhat complex)'
60
- )
61
- assert . deepEqual (
62
- readingTime ( treeSomewhatSimple , { age : 12 } ) . toFixed ( 2 ) ,
63
- '1.98' ,
64
- 'should take age into account (1, somewhat simple)'
52
+ await t . test (
53
+ 'should take age into account (1, somewhat complex)' ,
54
+ async function ( ) {
55
+ assert . deepEqual ( readingTime ( tree , { age : 12 } ) . toFixed ( 2 ) , '2.44' )
56
+ }
65
57
)
66
58
67
- assert . deepEqual (
68
- readingTime ( tree , { age : 21 } ) . toFixed ( 2 ) ,
69
- '0.75' ,
70
- 'should take age into account (2, somewhat complex)'
71
- )
72
- assert . deepEqual (
73
- readingTime ( treeSomewhatSimple , { age : 21 } ) . toFixed ( 2 ) ,
74
- '0.71' ,
75
- 'should take age into account (2, somewhat simple)'
59
+ await t . test (
60
+ 'should take age into account (1, somewhat simple)' ,
61
+ async function ( ) {
62
+ assert . deepEqual (
63
+ readingTime ( treeSomewhatSimple , { age : 12 } ) . toFixed ( 2 ) ,
64
+ '1.98'
65
+ )
66
+ }
76
67
)
77
68
78
- assert . deepEqual (
79
- readingTime ( tree , { age : 1 } ) . toFixed ( 2 ) ,
80
- '4.46' ,
81
- 'should cap at a reasonable time (1)'
69
+ await t . test (
70
+ 'should take age into account (2, somewhat complex)' ,
71
+ async function ( ) {
72
+ assert . deepEqual ( readingTime ( tree , { age : 21 } ) . toFixed ( 2 ) , '0.75' )
73
+ }
82
74
)
83
75
84
- assert . deepEqual (
85
- readingTime ( tree , { age : 81 } ) . toFixed ( 2 ) ,
86
- '0.70' ,
87
- 'should cap at a reasonable time (2)'
76
+ await t . test (
77
+ 'should take age into account (2, somewhat simple)' ,
78
+ async function ( ) {
79
+ assert . deepEqual (
80
+ readingTime ( treeSomewhatSimple , { age : 21 } ) . toFixed ( 2 ) ,
81
+ '0.71'
82
+ )
83
+ }
88
84
)
85
+
86
+ await t . test ( 'should cap at a reasonable time (1)' , async function ( ) {
87
+ assert . deepEqual ( readingTime ( tree , { age : 1 } ) . toFixed ( 2 ) , '4.46' )
88
+ } )
89
+
90
+ await t . test ( 'should cap at a reasonable time (2)' , async function ( ) {
91
+ assert . deepEqual ( readingTime ( tree , { age : 81 } ) . toFixed ( 2 ) , '0.70' )
92
+ } )
89
93
} )
0 commit comments