File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change 1+ # Hide JavaScript block
2+
3+ <!-- fiddle JavaScript source not shown -->
4+
5+ ``` html
6+ <div id =" greeting" >Hello</div >
7+ ```
8+
9+ ``` js hide
10+ cy .get (' div#greeting' ).should (' have.text' , ' Hello' )
11+ ```
12+
13+ <!-- fiddle-end -->
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ const debug = require('debug')('cypress-markdown-preprocessor')
44const verbose = require ( 'debug' ) (
55 'cypress-markdown-preprocessor:verbose' ,
66)
7+ verbose . enabled = true
78
89function stripQuotes ( s ) {
910 return s . replace ( / ^ [ ' " ] | [ ' " ] $ / g, '' )
@@ -304,10 +305,21 @@ function extractFiddles(md) {
304305 const jsMaybe = ast . children
305306 . filter ( isJavaScript )
306307 . filter ( shouldIncludeBlock )
308+ . map ( ( codeBlock ) => {
309+ const meta = codeBlock . meta || ''
310+ return {
311+ source : codeBlock . value ,
312+ hide : meta . includes ( 'hide' ) ,
313+ }
314+ } )
307315
308316 if ( jsMaybe . length ) {
309317 // console.log(jsMaybe)
310- const testCode = jsMaybe . map ( ( b ) => b . value ) . join ( '\n' )
318+ const testCode = jsMaybe . map ( ( b ) => b . source ) . join ( '\n' )
319+ const testCodeShow = jsMaybe
320+ . filter ( ( b ) => ! b . hide )
321+ . map ( ( b ) => b . source )
322+ . join ( '\n' )
311323
312324 const commonHtml = htmlMarkup
313325 ? extractFiddleMarkup ( htmlMarkup . value )
@@ -316,6 +328,7 @@ function extractFiddles(md) {
316328 const testFiddle = formFiddleObject ( {
317329 name : fiddle . name ,
318330 test : testCode ,
331+ testShown : testCodeShow || null ,
319332 html : htmlLiveBlockMaybe
320333 ? htmlLiveBlockMaybe . value
321334 : htmlMaybe . length
You can’t perform that action at this time.
0 commit comments