@@ -71,6 +71,15 @@ function fixturePath(filePath) {
7171 return resolve ( import . meta. dirname , './fixtures' , filePath ) ;
7272}
7373
74+ async function execMarkedString ( args , markdown ) {
75+ const { stdout, stderr } = await execFileAsync ( process . execPath , [
76+ resolve ( import . meta. dirname , '../../bin/marked.js' ) ,
77+ ...args , '--string' , markdown ,
78+ ] ) ;
79+ assert . strictEqual ( stderr , '' ) ;
80+ return stdout ;
81+ }
82+
7483function execMarked ( { args = '' , stdin = '' , stdout = '' , stderr = '' } ) {
7584 const execPath = resolve ( import . meta. dirname , '../../bin/marked' ) ;
7685 return async ( ) => {
@@ -170,6 +179,26 @@ describe('bin/marked', () => {
170179 } ) ;
171180
172181 describe ( 'config' , ( ) => {
182+ it ( 'uses GFM by default' , async ( ) => {
183+ const result = await execMarkedString ( [ ] , '~~test~~' ) ;
184+ assert . strictEqual ( result , '<p><del>test</del></p>\n\n' ) ;
185+ } ) ;
186+
187+ it ( 'uses options from the config file in a separate process' , async ( ) => {
188+ const result = await execMarkedString ( [ '--config' , fixturePath ( 'bin-config.js' ) ] , 'line1\nline2' ) ;
189+ assert . strictEqual ( result , '<p>line1<br>line2</p>\n\n' ) ;
190+ } ) ;
191+
192+ it ( 'uses a tokenizer from the config file' , async ( ) => {
193+ const result = await execMarkedString ( [ '--config' , fixturePath ( 'bin-config-tokenizer.js' ) ] , '`test`' ) ;
194+ assert . strictEqual ( result , '<p><code>TEST</code></p>\n\n' ) ;
195+ } ) ;
196+
197+ it ( 'lets command-line options override config options' , async ( ) => {
198+ const result = await execMarkedString ( [ '--config' , fixturePath ( 'bin-config.js' ) , '--no-breaks' ] , 'line1\nline2' ) ;
199+ assert . strictEqual ( result , '<p>line1\nline2</p>\n\n' ) ;
200+ } ) ;
201+
173202 it ( '-c' , testInput ( {
174203 args : [ '-c' , fixturePath ( 'bin-config.js' ) , '-s' , 'line1\nline2' ] ,
175204 stdout : '<p>line1<br>line2</p>' ,
@@ -225,6 +254,34 @@ describe('bin/marked', () => {
225254 } ) ) ;
226255 } ) ;
227256
257+ describe ( 'tokens' , ( ) => {
258+ async function tokens ( args , markdown ) {
259+ const stdout = await execMarkedString ( [ '--tokens' , ...args ] , markdown ) ;
260+ return JSON . parse ( stdout ) ;
261+ }
262+
263+ it ( 'uses GFM by default' , async ( ) => {
264+ const result = await tokens ( [ ] , '~~test~~' ) ;
265+ assert . strictEqual ( result [ 0 ] . tokens [ 0 ] . type , 'del' ) ;
266+ } ) ;
267+
268+ it ( 'uses options from the config file' , async ( ) => {
269+ const result = await tokens ( [ '--config' , fixturePath ( 'bin-config.js' ) ] , 'line1\nline2' ) ;
270+ assert . deepStrictEqual ( result [ 0 ] . tokens . map ( token => token . type ) , [ 'text' , 'br' , 'text' ] ) ;
271+ } ) ;
272+
273+ it ( 'uses a tokenizer from the config file' , async ( ) => {
274+ const result = await tokens ( [ '--config' , fixturePath ( 'bin-config-tokenizer.js' ) ] , '`test`' ) ;
275+ assert . strictEqual ( result [ 0 ] . tokens [ 0 ] . type , 'codespan' ) ;
276+ assert . strictEqual ( result [ 0 ] . tokens [ 0 ] . text , 'TEST' ) ;
277+ } ) ;
278+
279+ it ( 'lets command-line options override config options' , async ( ) => {
280+ const result = await tokens ( [ '--config' , fixturePath ( 'bin-config.js' ) , '--no-breaks' ] , 'line1\nline2' ) ;
281+ assert . deepStrictEqual ( result [ 0 ] . tokens . map ( token => token . type ) , [ 'text' ] ) ;
282+ } ) ;
283+ } ) ;
284+
228285 describe ( 'input' , ( ) => {
229286 it ( 'input file positional' , testInput ( {
230287 args : [ fixturePath ( 'bin-input.md' ) ] ,
0 commit comments