1
- 'use strict'
1
+ import fs from 'fs'
2
+ import test from 'tape'
3
+ import alex , { markdown , mdx , text , html } from '../index.js'
2
4
3
- var fs = require ( 'fs' )
4
- var path = require ( 'path' )
5
- var test = require ( 'tape' )
6
- var alex = require ( '..' )
7
-
8
- var html = fs . readFileSync ( path . join ( __dirname , 'fixtures' , 'three.html' ) )
9
- var mdx = fs . readFileSync ( path . join ( __dirname , 'fixtures' , 'four.mdx' ) )
5
+ var threeHtml = fs . readFileSync (
6
+ new URL ( './fixtures/three.html' , import . meta. url )
7
+ )
8
+ var fourMdx = fs . readFileSync ( new URL ( './fixtures/four.mdx' , import . meta. url ) )
10
9
11
10
// Tests. Note that these are small because alex is in fact
12
11
// just a collection of well-tested modules.
@@ -117,20 +116,18 @@ test('alex()', function (t) {
117
116
'should work with deny and profanity config'
118
117
)
119
118
120
- t . deepEqual ( alex . markdown , alex , 'alex. markdown is an alias of alex' )
119
+ t . deepEqual ( markdown , alex , 'markdown is an alias of alex' )
121
120
122
121
t . deepEqual (
123
- alex
124
- . text (
125
- [
126
- 'The `boogeyman` wrote all changes to the **master server**. Thus,' ,
127
- 'the slaves were read-only copies of master. But not to worry,' ,
128
- 'he was a _cripple_.' ,
129
- '' ,
130
- 'Eric is pretty set on beating your butt for the sheriff.'
131
- ] . join ( '\n' )
132
- )
133
- . messages . map ( String ) ,
122
+ text (
123
+ [
124
+ 'The `boogeyman` wrote all changes to the **master server**. Thus,' ,
125
+ 'the slaves were read-only copies of master. But not to worry,' ,
126
+ 'he was a _cripple_.' ,
127
+ '' ,
128
+ 'Eric is pretty set on beating your butt for the sheriff.'
129
+ ] . join ( '\n' )
130
+ ) . messages . map ( String ) ,
134
131
[
135
132
'1:6-1:15: `boogeyman` may be insensitive, use `boogeymonster` instead' ,
136
133
'1:44-1:50: `master` may be insensitive, use `primary`, `hub`, `reference` instead' ,
@@ -140,202 +137,184 @@ test('alex()', function (t) {
140
137
'3:11-3:18: `cripple` may be insensitive, use `person with a limp` instead' ,
141
138
'5:36-5:40: Be careful with `butt`, it’s profane in some cases'
142
139
] ,
143
- 'alex. text()'
140
+ 'text()'
144
141
)
145
142
146
143
t . deepEqual (
147
- alex
148
- . text (
149
- 'The boogeyman asked Eric, the asshat, to beat your butt for the sheriff.' ,
150
- [ 'butt' ]
151
- )
152
- . messages . map ( String ) ,
144
+ text (
145
+ 'The boogeyman asked Eric, the asshat, to beat your butt for the sheriff.' ,
146
+ [ 'butt' ]
147
+ ) . messages . map ( String ) ,
153
148
[
154
149
'1:5-1:14: `boogeyman` may be insensitive, use `boogeymonster` instead' ,
155
150
'1:31-1:37: Don’t use `asshat`, it’s profane'
156
151
] ,
157
- 'alex. text() with allow array'
152
+ 'text() with allow array'
158
153
)
159
154
160
155
t . deepEqual (
161
- alex
162
- . text (
163
- 'The boogeyman asked Eric, the asshat, to beat your butt for the sheriff.' ,
164
- { allow : [ 'butt' ] }
165
- )
166
- . messages . map ( String ) ,
156
+ text (
157
+ 'The boogeyman asked Eric, the asshat, to beat your butt for the sheriff.' ,
158
+ { allow : [ 'butt' ] }
159
+ ) . messages . map ( String ) ,
167
160
[
168
161
'1:5-1:14: `boogeyman` may be insensitive, use `boogeymonster` instead' ,
169
162
'1:31-1:37: Don’t use `asshat`, it’s profane'
170
163
] ,
171
- 'alex. text() with allow config'
164
+ 'text() with allow config'
172
165
)
173
166
174
167
t . deepEqual (
175
- alex
176
- . text (
177
- 'The boogeyman asked Eric, the asshat, to beat your butt for the sheriff.' ,
178
- {
179
- deny : [ 'butt' ]
180
- }
181
- )
182
- . messages . map ( String ) ,
168
+ text (
169
+ 'The boogeyman asked Eric, the asshat, to beat your butt for the sheriff.' ,
170
+ {
171
+ deny : [ 'butt' ]
172
+ }
173
+ ) . messages . map ( String ) ,
183
174
[ '1:52-1:56: Be careful with `butt`, it’s profane in some cases' ] ,
184
- 'alex. text() with deny config'
175
+ 'text() with deny config'
185
176
)
186
177
187
178
t . throws ( function ( ) {
188
- alex . text (
179
+ text (
189
180
'The boogeyman asked Eric, the asshat, to beat your butt for the sheriff.' ,
190
181
{
191
182
allow : [ 'asshat' ] ,
192
183
deny : [ 'boogeyman-boogeywoman' ]
193
184
}
194
185
)
195
- } , 'alex. text() with allow and deny config' )
186
+ } , 'text() with allow and deny config' )
196
187
197
188
t . deepEqual (
198
- alex
199
- . text (
200
- 'The boogeyman asked Eric, the asshat, to beat your butt for the sheriff.' ,
201
- { profanitySureness : 1 }
202
- )
203
- . messages . map ( String ) ,
189
+ text (
190
+ 'The boogeyman asked Eric, the asshat, to beat your butt for the sheriff.' ,
191
+ { profanitySureness : 1 }
192
+ ) . messages . map ( String ) ,
204
193
[
205
194
'1:5-1:14: `boogeyman` may be insensitive, use `boogeymonster` instead' ,
206
195
'1:31-1:37: Don’t use `asshat`, it’s profane'
207
196
] ,
208
- 'alex. text() with profanity config'
197
+ 'text() with profanity config'
209
198
)
210
199
211
200
t . deepEqual (
212
- alex
213
- . text (
214
- 'The boogeyman asked Eric, the asshat, to beat your butt for the sheriff.' ,
215
- {
216
- allow : [ 'asshat' ] ,
217
- profanitySureness : 1
218
- }
219
- )
220
- . messages . map ( String ) ,
201
+ text (
202
+ 'The boogeyman asked Eric, the asshat, to beat your butt for the sheriff.' ,
203
+ {
204
+ allow : [ 'asshat' ] ,
205
+ profanitySureness : 1
206
+ }
207
+ ) . messages . map ( String ) ,
221
208
[ '1:5-1:14: `boogeyman` may be insensitive, use `boogeymonster` instead' ] ,
222
- 'alex. text() with allow and profanity config'
209
+ 'text() with allow and profanity config'
223
210
)
224
211
225
212
t . deepEqual (
226
- alex
227
- . text (
228
- 'The boogeyman asked Eric, the asshat, to beat your butt for the sheriff.' ,
229
- {
230
- deny : [ 'boogeyman-boogeywoman' ] ,
231
- profanitySureness : 1
232
- }
233
- )
234
- . messages . map ( String ) ,
213
+ text (
214
+ 'The boogeyman asked Eric, the asshat, to beat your butt for the sheriff.' ,
215
+ {
216
+ deny : [ 'boogeyman-boogeywoman' ] ,
217
+ profanitySureness : 1
218
+ }
219
+ ) . messages . map ( String ) ,
235
220
[ '1:5-1:14: `boogeyman` may be insensitive, use `boogeymonster` instead' ] ,
236
- 'alex. text() with deny and profanity config'
221
+ 'text() with deny and profanity config'
237
222
)
238
223
239
224
t . deepEqual (
240
- alex . html ( html ) . messages . map ( String ) ,
225
+ html ( threeHtml ) . messages . map ( String ) ,
241
226
[
242
227
'17:22-17:24: `He` may be insensitive, use `They`, `It` instead' ,
243
228
'18:5-18:8: `She` may be insensitive, use `They`, `It` instead' ,
244
229
'18:36-18:42: Don’t use `asshat`, it’s profane' ,
245
230
'18:74-18:78: Be careful with `butt`, it’s profane in some cases'
246
231
] ,
247
- 'alex. html()'
232
+ 'html()'
248
233
)
249
234
250
235
t . deepEqual (
251
- alex . html ( html , [ 'butt' ] ) . messages . map ( String ) ,
236
+ html ( threeHtml , [ 'butt' ] ) . messages . map ( String ) ,
252
237
[
253
238
'17:22-17:24: `He` may be insensitive, use `They`, `It` instead' ,
254
239
'18:5-18:8: `She` may be insensitive, use `They`, `It` instead' ,
255
240
'18:36-18:42: Don’t use `asshat`, it’s profane'
256
241
] ,
257
- 'alex. html() with allow array'
242
+ 'html() with allow array'
258
243
)
259
244
260
245
t . deepEqual (
261
- alex . html ( html , { allow : [ 'butt' ] } ) . messages . map ( String ) ,
246
+ html ( threeHtml , { allow : [ 'butt' ] } ) . messages . map ( String ) ,
262
247
[
263
248
'17:22-17:24: `He` may be insensitive, use `They`, `It` instead' ,
264
249
'18:5-18:8: `She` may be insensitive, use `They`, `It` instead' ,
265
250
'18:36-18:42: Don’t use `asshat`, it’s profane'
266
251
] ,
267
- 'alex. html() with allow config'
252
+ 'html() with allow config'
268
253
)
269
254
270
255
t . deepEqual (
271
- alex
272
- . html ( html , {
273
- deny : [ 'butt' ]
274
- } )
275
- . messages . map ( String ) ,
256
+ html ( threeHtml , {
257
+ deny : [ 'butt' ]
258
+ } ) . messages . map ( String ) ,
276
259
[ '18:74-18:78: Be careful with `butt`, it’s profane in some cases' ] ,
277
- 'alex. html() with deny config'
260
+ 'html() with deny config'
278
261
)
279
262
280
263
t . throws ( function ( ) {
281
- alex . html ( html , {
264
+ html ( threeHtml , {
282
265
allow : [ 'he-she' ] ,
283
266
deny : [ 'butt' ]
284
267
} )
285
- } , 'alex. html() with allow and deny config' )
268
+ } , 'html() with allow and deny config' )
286
269
287
270
t . deepEqual (
288
- alex . html ( html , { profanitySureness : 1 } ) . messages . map ( String ) ,
271
+ html ( threeHtml , { profanitySureness : 1 } ) . messages . map ( String ) ,
289
272
[
290
273
'17:22-17:24: `He` may be insensitive, use `They`, `It` instead' ,
291
274
'18:5-18:8: `She` may be insensitive, use `They`, `It` instead' ,
292
275
'18:36-18:42: Don’t use `asshat`, it’s profane'
293
276
] ,
294
- 'alex. html() with profanity config'
277
+ 'html() with profanity config'
295
278
)
296
279
297
280
t . deepEqual (
298
- alex
299
- . html ( html , {
300
- allow : [ 'he-she' ] ,
301
- profanitySureness : 1
302
- } )
303
- . messages . map ( String ) ,
281
+ html ( threeHtml , {
282
+ allow : [ 'he-she' ] ,
283
+ profanitySureness : 1
284
+ } ) . messages . map ( String ) ,
304
285
[ '18:36-18:42: Don’t use `asshat`, it’s profane' ] ,
305
- 'alex. html() with allow and profanity config'
286
+ 'html() with allow and profanity config'
306
287
)
307
288
308
289
t . deepEqual (
309
- alex
310
- . html ( html , {
311
- deny : [ 'he-she' ] ,
312
- profanitySureness : 1
313
- } )
314
- . messages . map ( String ) ,
290
+ html ( threeHtml , {
291
+ deny : [ 'he-she' ] ,
292
+ profanitySureness : 1
293
+ } ) . messages . map ( String ) ,
315
294
[
316
295
'17:22-17:24: `He` may be insensitive, use `They`, `It` instead' ,
317
296
'18:5-18:8: `She` may be insensitive, use `They`, `It` instead'
318
297
] ,
319
- 'alex. html() with deny and profanity config'
298
+ 'html() with deny and profanity config'
320
299
)
321
300
322
301
t . deepEqual (
323
- alex . mdx ( mdx ) . messages . map ( String ) ,
302
+ mdx ( fourMdx ) . messages . map ( String ) ,
324
303
[
325
304
'3:1-3:4: `She` may be insensitive, use `They`, `It` instead' ,
326
305
'3:32-3:38: Don’t use `asshat`, it’s profane' ,
327
306
'3:70-3:74: Be careful with `butt`, it’s profane in some cases'
328
307
] ,
329
- 'alex. mdx()'
308
+ 'mdx()'
330
309
)
331
310
332
311
t . deepEqual (
333
- alex . mdx ( mdx , [ 'butt' ] ) . messages . map ( String ) ,
312
+ mdx ( fourMdx , [ 'butt' ] ) . messages . map ( String ) ,
334
313
[
335
314
'3:1-3:4: `She` may be insensitive, use `They`, `It` instead' ,
336
315
'3:32-3:38: Don’t use `asshat`, it’s profane'
337
316
] ,
338
- 'alex. mdx() with options'
317
+ 'mdx() with options'
339
318
)
340
319
341
320
t . end ( )
0 commit comments