File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /**
2+ * @file quint.js
3+ * A minimum testing framework with QUnit-like (https://qunitjs.com/) APIs
4+ * @author Tom Tang <xmader@distributive.network>
5+ * @date Aug 2023
6+ */
7+
8+ const QUnitAssert = {
9+ arity ( fn , length )
10+ {
11+ if ( fn . length !== length ) throw new Error ( `'${ fn } ' does not have arity of ${ length } ` ) ;
12+ } ,
13+ isFunction ( x )
14+ {
15+ if ( typeof x !== 'function' ) throw new Error ( `'${ x } ' is not a function` ) ;
16+ } ,
17+ name ( x , name )
18+ {
19+ if ( x . name !== name ) throw new Error ( `'${ x } ' does not have a name of ${ name } ` ) ;
20+ } ,
21+ true ( x )
22+ {
23+ if ( x !== true ) throw new Error ( `'${ x } ' is not true` ) ;
24+ } ,
25+ false ( x )
26+ {
27+ if ( x !== false ) throw new Error ( `'${ x } ' is not false` ) ;
28+ } ,
29+ same ( a , b )
30+ {
31+ if ( a !== b ) throw new Error ( `'${ a } ' does not equal to '${ b } '` ) ;
32+ } ,
33+ arrayEqual ( a , b )
34+ {
35+ if ( JSON . stringify ( a ) !== JSON . stringify ( b ) ) throw new Error ( `'${ a } ' does not equal to '${ b } '` ) ;
36+ } ,
37+ throws ( fn , error )
38+ {
39+ try
40+ {
41+ fn ( ) ;
42+ }
43+ catch ( err )
44+ {
45+ if ( ! err . toString ( ) . includes ( error ) ) throw new Error ( `'${ fn } ' throws '${ err } ' but expects '${ error } '` ) ;
46+ return ;
47+ }
48+ throw new Error ( `'${ fn } ' does not throw` ) ;
49+ } ,
50+ looksNative ( fn )
51+ {
52+ if ( ! fn . toString ( ) . includes ( '[native code]' ) ) throw new Error ( `'${ fn } ' does not look native` ) ;
53+ } ,
54+ enumerable ( obj , propertyName )
55+ {
56+ const descriptor = Object . getOwnPropertyDescriptor ( obj , propertyName ) ;
57+ if ( ! descriptor . enumerable ) throw new Error ( `'${ obj [ Symbol . toStringTag ] } .${ propertyName } ' is not enumerable` ) ;
58+ } ,
59+ } ;
60+
61+ const QUnit = {
62+ test ( name , callback )
63+ {
64+ callback ( QUnitAssert ) ;
65+ } ,
66+ skip ( name , callback )
67+ {
68+ // no op
69+ }
70+ } ;
71+
72+ module . exports = QUnit ;
You can’t perform that action at this time.
0 commit comments