File tree Expand file tree Collapse file tree
33-Building-a-Testing-Framework-From-Scratch Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ const path = require ( 'path' )
2+ const jsdom = require ( 'jsdom' )
3+ const { JSDOM } = jsdom
4+
5+ const render = async ( filename ) => {
6+ const filepath = path . join ( process . cwd ( ) , filename )
7+
8+ const dom = await JSDOM . fromFile ( filePath , {
9+ runScripts : 'dangerously' ,
10+ resources : 'usable'
11+ } )
12+
13+ return dom
14+ }
15+
16+ module . exports = render
Original file line number Diff line number Diff line change 11const fs = require ( 'fs' )
22const path = require ( 'path' )
33const chalk = require ( 'chalk' )
4+ const render = require ( './render.js' )
45
56const forbiddenDirs = [ 'node_modules' ]
67
@@ -11,8 +12,10 @@ class Runner {
1112
1213 async runTests ( ) {
1314 for ( let file of this . testFiles ) {
14- console . log ( chalk . gray ( `---- ${ file . shortName } ` ) ) ;
15+ console . log ( chalk . gray ( `---- ${ file . shortName } ` ) )
1516 const beforeEaches = [ ]
17+ global . render = render
18+
1619 global . beforeEach = ( fn ) => {
1720 beforeEaches . push ( fn )
1821 }
@@ -26,15 +29,14 @@ class Runner {
2629 } catch ( err ) {
2730 const message = err . message . replace ( / \n / g, '\n\t\t' )
2831 console . log ( chalk . red ( '\t' , `X - ${ desc } ` ) )
29- console . log ( chalk . red ( '\t' , message ) ) ;
32+ console . log ( chalk . red ( '\t' , message ) )
3033 }
3134 }
3235
3336 try {
34-
3537 require ( file . name )
36- } catch ( err ) {
37- console . log ( chalk . red ( err . message ) ) ;
38+ } catch ( err ) {
39+ console . log ( chalk . red ( err . message ) )
3840 }
3941 }
4042 }
Original file line number Diff line number Diff line change @@ -35,4 +35,8 @@ Terminal command: `testme`
3535
3636## 11. 12 Better Formatting
3737
38- ## 12. 13 Ignoring Directories
38+ ## 12. 13 Ignoring Directories
39+
40+ ## 13. 15 A Sample Web App
41+
42+ ## 14. 17 Building a Render Function
You can’t perform that action at this time.
0 commit comments