Skip to content

Commit bbeb248

Browse files
committed
Section 33: Building a Render Function
1 parent d038b75 commit bbeb248

3 files changed

Lines changed: 28 additions & 6 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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

33-Building-a-Testing-Framework-From-Scratch/01-testme/runner.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const fs = require('fs')
22
const path = require('path')
33
const chalk = require('chalk')
4+
const render = require('./render.js')
45

56
const 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
}

33-Building-a-Testing-Framework-From-Scratch/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)