|
1 | 1 | /**
|
2 | 2 | * @license Apache-2.0
|
3 | 3 | *
|
4 |
| -* Copyright (c) 2018 The Stdlib Authors. |
| 4 | +* Copyright (c) 2023 The Stdlib Authors. |
5 | 5 | *
|
6 | 6 | * Licensed under the Apache License, Version 2.0 (the "License");
|
7 | 7 | * you may not use this file except in compliance with the License.
|
|
21 | 21 | // MODULES //
|
22 | 22 |
|
23 | 23 | var tape = require( 'tape' );
|
24 |
| -var proxyquire = require( 'proxyquire' ); |
25 |
| -var isBuffer = require( '@stdlib/assert-is-buffer' ); |
26 |
| -var polyfill = require( './../../dist/polyfill.js' ); |
27 |
| -var nonPolyfill = require( './../../dist/main.js' ); |
28 |
| -var string2buffer = require( './../../dist' ); |
| 24 | +var main = require( './../../dist' ); |
29 | 25 |
|
30 | 26 |
|
31 | 27 | // TESTS //
|
32 | 28 |
|
33 |
| -tape( 'main export is a function', function test( t ) { |
| 29 | +tape( 'main export is defined', function test( t ) { |
34 | 30 | t.ok( true, __filename );
|
35 |
| - t.strictEqual( typeof string2buffer, 'function', 'main export is a function' ); |
36 |
| - t.end(); |
37 |
| -}); |
38 |
| - |
39 |
| -tape( 'in older environments, the main export is a polyfill', function test( t ) { |
40 |
| - var string2buffer = proxyquire( './../dist', { |
41 |
| - './has_from.js': false |
42 |
| - }); |
43 |
| - t.strictEqual( string2buffer, polyfill, 'returns polyfill' ); |
44 |
| - t.end(); |
45 |
| -}); |
46 |
| - |
47 |
| -tape( 'in newer environments, the main export is not a polyfill', function test( t ) { |
48 |
| - var string2buffer = proxyquire( './../dist', { |
49 |
| - './has_from.js': true |
50 |
| - }); |
51 |
| - t.strictEqual( string2buffer, nonPolyfill, 'does not return polyfill' ); |
52 |
| - t.end(); |
53 |
| -}); |
54 |
| - |
55 |
| -tape( 'the function throws an error if not provided a string', function test( t ) { |
56 |
| - var values; |
57 |
| - var i; |
58 |
| - |
59 |
| - values = [ |
60 |
| - 5, |
61 |
| - NaN, |
62 |
| - true, |
63 |
| - false, |
64 |
| - null, |
65 |
| - void 0, |
66 |
| - [], |
67 |
| - [ 1, 2, 3, 4 ], |
68 |
| - {}, |
69 |
| - function noop() {} |
70 |
| - ]; |
71 |
| - |
72 |
| - for ( i = 0; i < values.length; i++ ) { |
73 |
| - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); |
74 |
| - } |
75 |
| - t.end(); |
76 |
| - |
77 |
| - function badValue( value ) { |
78 |
| - return function badValue() { |
79 |
| - string2buffer( value ); |
80 |
| - }; |
81 |
| - } |
82 |
| -}); |
83 |
| - |
84 |
| -tape( 'the function throws an error if not provided a string (encoding)', function test( t ) { |
85 |
| - var values; |
86 |
| - var i; |
87 |
| - |
88 |
| - values = [ |
89 |
| - 5, |
90 |
| - NaN, |
91 |
| - true, |
92 |
| - false, |
93 |
| - null, |
94 |
| - void 0, |
95 |
| - [], |
96 |
| - [ 1, 2, 3, 4 ], |
97 |
| - {}, |
98 |
| - function noop() {} |
99 |
| - ]; |
100 |
| - |
101 |
| - for ( i = 0; i < values.length; i++ ) { |
102 |
| - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); |
103 |
| - } |
104 |
| - t.end(); |
105 |
| - |
106 |
| - function badValue( value ) { |
107 |
| - return function badValue() { |
108 |
| - string2buffer( value, 'utf8' ); |
109 |
| - }; |
110 |
| - } |
111 |
| -}); |
112 |
| - |
113 |
| -tape( 'the function throws an error if not provided a valid encoding argument', function test( t ) { |
114 |
| - var values; |
115 |
| - var i; |
116 |
| - |
117 |
| - values = [ |
118 |
| - 'beep', |
119 |
| - 'boop', |
120 |
| - 'bop', |
121 |
| - 5, |
122 |
| - NaN, |
123 |
| - true, |
124 |
| - false, |
125 |
| - null, |
126 |
| - void 0, |
127 |
| - [], |
128 |
| - [ 1, 2, 3, 4 ], |
129 |
| - {}, |
130 |
| - function noop() {} |
131 |
| - ]; |
132 |
| - |
133 |
| - for ( i = 0; i < values.length; i++ ) { |
134 |
| - t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); |
135 |
| - } |
136 |
| - t.end(); |
137 |
| - |
138 |
| - function badValue( value ) { |
139 |
| - return function badValue() { |
140 |
| - string2buffer( 'beep', value ); |
141 |
| - }; |
142 |
| - } |
143 |
| -}); |
144 |
| - |
145 |
| -tape( 'the function allocates a buffer containing a provided string', function test( t ) { |
146 |
| - var buf = string2buffer( 'beep boop' ); |
147 |
| - t.strictEqual( isBuffer( buf ), true, 'returns a buffer' ); |
148 |
| - t.strictEqual( buf.length, 9, 'has expected length' ); |
149 |
| - t.strictEqual( buf.toString(), 'beep boop', 'returns expected value' ); |
150 |
| - t.end(); |
151 |
| -}); |
152 |
| - |
153 |
| -tape( 'the function allocates a buffer containing a provided string (encoding)', function test( t ) { |
154 |
| - var buf = string2buffer( '7468697320697320612074c3a97374', 'hex' ); |
155 |
| - t.strictEqual( isBuffer( buf ), true, 'returns a buffer' ); |
156 |
| - t.strictEqual( buf.length, 15, 'has expected length' ); |
157 |
| - t.strictEqual( buf.toString(), 'this is a tést', 'returns expected value' ); |
| 31 | + t.strictEqual( main !== void 0, true, 'main export is defined' ); |
158 | 32 | t.end();
|
159 | 33 | });
|
0 commit comments