@@ -66,91 +66,85 @@ const otherTests = [
66
66
{ name : 'Gemoji (4)' , input : ':ok_hand: :hatched_chick: Two in a row' }
67
67
]
68
68
69
- main ( )
69
+ const files = await fs . readdir ( categoryBase )
70
+ /** @type {Array<{name: string, input: string, markdownOverwrite?: string, expected?: string}> } */
71
+ const tests = [ ...otherTests ]
72
+ let index = - 1
70
73
71
- async function main ( ) {
72
- const files = await fs . readdir ( categoryBase )
73
- /** @type {Array<{name: string, input: string, markdownOverwrite?: string, expected?: string}> } */
74
- const tests = [ ...otherTests ]
75
- let index = - 1
74
+ // Create a test case with a bunch of examples.
75
+ while ( ++ index < files . length ) {
76
+ const name = files [ index ]
76
77
77
- // Create a test case with a bunch of examples.
78
- while ( ++ index < files . length ) {
79
- const name = files [ index ]
78
+ if ( name === 'index.js' ) continue
80
79
81
- if ( name === 'index.js' ) continue
80
+ // These result in Git(Hub) thinking it’s a binary file.
81
+ if ( name === 'Control' || name === 'Surrogate' ) continue
82
82
83
- // These result in Git(Hub) thinking it’s a binary file .
84
- if ( name === 'Control' || name === 'Surrogate ') continue
83
+ // This prevents GH from rendering markdown to HTML .
84
+ if ( name === 'Other ' ) continue
85
85
86
- // This prevents GH from rendering markdown to HTML.
87
- if ( name === 'Other' ) continue
86
+ /** @type {{default: Array<number>} } */
87
+ const { default : codePoints } = await import ( new URL ( name + '/code-points.js' , categoryBase ) . href )
88
+ /** @type {Array<number> } */
89
+ const subs = [ ]
88
90
89
- const fp = `./ ${ name } /code-points.js`
91
+ let n = - 1
90
92
91
- /** @type {{default: Array<number>} } */
92
- const { default : codePoints } = await import ( new URL ( fp , categoryBase ) . href )
93
- /** @type {Array<number> } */
94
- const subs = [ ]
95
-
96
- let n = - 1
97
-
98
- while ( ++ n < samples ) {
99
- subs . push ( codePoints [ Math . floor ( codePoints . length / samples * n ) ] )
100
- }
93
+ while ( ++ n < samples ) {
94
+ subs . push ( codePoints [ Math . floor ( codePoints . length / samples * n ) ] )
95
+ }
101
96
102
- subs . push ( codePoints [ codePoints . length - 1 ] )
97
+ subs . push ( codePoints [ codePoints . length - 1 ] )
103
98
104
- tests . push ( { name, input : 'a' + [ ...new Set ( subs ) ] . map ( d => String . fromCodePoint ( d ) ) . join ( ' ' ) + 'b' } )
105
- }
99
+ tests . push ( { name, input : 'a' + [ ...new Set ( subs ) ] . map ( d => String . fromCodePoint ( d ) ) . join ( ' ' ) + 'b' } )
100
+ }
106
101
107
- // Create a Gist.
108
- const filename = 'readme.md'
109
- const gistResult = await octo . gists . create ( {
110
- files : {
111
- [ filename ] : {
112
- content : tests . map ( d => {
113
- return d . markdownOverwrite || toMarkdown ( { type : 'heading' , depth : 1 , children : [ { type : 'text' , value : d . input } ] } , { extensions : [ gfmToMarkdown ( ) ] } )
114
- } ) . join ( '\n\n' )
115
- }
102
+ // Create a Gist.
103
+ const filename = 'readme.md'
104
+ const gistResult = await octo . gists . create ( {
105
+ files : {
106
+ [ filename ] : {
107
+ content : tests . map ( d => {
108
+ return d . markdownOverwrite || toMarkdown ( { type : 'heading' , depth : 1 , children : [ { type : 'text' , value : d . input } ] } , { extensions : [ gfmToMarkdown ( ) ] } )
109
+ } ) . join ( '\n\n' )
116
110
}
117
- } )
111
+ }
112
+ } )
118
113
119
- const file = ( gistResult . data . files || { } ) [ filename ]
114
+ const file = ( gistResult . data . files || { } ) [ filename ]
120
115
121
- if ( ! file || ! gistResult . data . html_url || ! gistResult . data . id ) {
122
- throw new Error ( 'Something weird happened contacting GitHub' )
123
- }
116
+ if ( ! file || ! gistResult . data . html_url || ! gistResult . data . id ) {
117
+ throw new Error ( 'Something weird happened contacting GitHub' )
118
+ }
124
119
125
- if ( ! file . language ) {
126
- throw new Error ( 'The generated markdown was seen as binary data instead of text by GitHub. This is likely because there are weird characters (such as control characters or lone surrogates) in it' )
127
- }
120
+ if ( ! file . language ) {
121
+ throw new Error ( 'The generated markdown was seen as binary data instead of text by GitHub. This is likely because there are weird characters (such as control characters or lone surrogates) in it' )
122
+ }
128
123
129
- // Fetch the rendered page.
130
- const response = await fetch ( gistResult . data . html_url , {
131
- headers : { Authorization : 'token ' + ghToken }
132
- } )
124
+ // Fetch the rendered page.
125
+ const response = await fetch ( gistResult . data . html_url , {
126
+ headers : { Authorization : 'token ' + ghToken }
127
+ } )
133
128
134
- const doc = await response . text ( )
129
+ const doc = await response . text ( )
135
130
136
- // Remove the Gist.
137
- await octo . gists . delete ( { gist_id : gistResult . data . id } )
131
+ // Remove the Gist.
132
+ await octo . gists . delete ( { gist_id : gistResult . data . id } )
138
133
139
- const tree = unified ( ) . use ( rehypeParse ) . parse ( doc )
140
- const markdownBody = select ( '.markdown-body' , tree )
134
+ const tree = unified ( ) . use ( rehypeParse ) . parse ( doc )
135
+ const markdownBody = select ( '.markdown-body' , tree )
141
136
142
- if ( ! markdownBody ) {
143
- throw new Error ( 'The generated markdown could not be rendered by GitHub as HTML. This is likely because there are weird characters in it' )
144
- }
137
+ if ( ! markdownBody ) {
138
+ throw new Error ( 'The generated markdown could not be rendered by GitHub as HTML. This is likely because there are weird characters in it' )
139
+ }
145
140
146
- const anchors = selectAll ( 'h1 .anchor' , markdownBody )
141
+ const anchors = selectAll ( 'h1 .anchor' , markdownBody )
147
142
148
- anchors . forEach ( ( node , i ) => {
149
- const href = ( node . properties || { } ) . href
150
- if ( typeof href === 'string' ) {
151
- tests [ i ] . expected = href . slice ( 1 )
152
- }
153
- } )
143
+ anchors . forEach ( ( node , i ) => {
144
+ const href = ( node . properties || { } ) . href
145
+ if ( typeof href === 'string' ) {
146
+ tests [ i ] . expected = href . slice ( 1 )
147
+ }
148
+ } )
154
149
155
- await fs . writeFile ( new URL ( '../test/fixtures.json' , import . meta. url ) , JSON . stringify ( tests , null , 2 ) + '\n' )
156
- }
150
+ await fs . writeFile ( new URL ( '../test/fixtures.json' , import . meta. url ) , JSON . stringify ( tests , null , 2 ) + '\n' )
0 commit comments