Skip to content

Commit 3148fb2

Browse files
committed
Section 33: Adding Basic Reporting
1 parent 3464506 commit 3148fb2

3 files changed

Lines changed: 22 additions & 10 deletions

File tree

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,30 @@ class Runner {
77
}
88

99
async runTests() {
10-
for(let file of this.testFiles) {
11-
10+
for (let file of this.testFiles) {
1211
const beforeEaches = []
1312
global.beforeEach = (fn) => {
1413
beforeEaches.push(fn)
1514
}
1615

17-
global.it = (desc,fn) => {
16+
global.it = (desc, fn) => {
1817
// console.log(desc);
19-
beforeEaches.forEach(func => func())
20-
fn()
18+
beforeEaches.forEach((func) => func())
19+
try {
20+
fn()
21+
console.log(`OK - ${desc}`);
22+
} catch (err) {
23+
console.log(`X - ${desc}`);
24+
console.log('\t', err.message);
25+
}
2126
}
2227

23-
require(file.name)
28+
try {
29+
30+
require(file.name)
31+
} catch(err) {
32+
console.log(err.message);
33+
}
2434
}
2535
}
2636

@@ -36,7 +46,7 @@ class Runner {
3646
} else if (stats.isDirectory()) {
3747
const childFiles = await fs.promises.readdir(filepath)
3848

39-
files.push(...childFiles.map(f => path.join(file, f)))
49+
files.push(...childFiles.map((f) => path.join(file, f)))
4050
}
4151
}
4252
}

33-Building-a-Testing-Framework-From-Scratch/01-testme/sampleproject/test/forEach.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ it('should sum an array', () => {
2323
})
2424

2525
it('beforeEach is ran each time', () => {
26-
assert.strictEqual(numbers.length, 3)
27-
// assert.strictEqual(numbers.length, 4) // this will fail
26+
// assert.strictEqual(numbers.length, 3)
27+
assert.strictEqual(numbers.length, 4) // this will fail
2828
})

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@
2727

2828
Terminal command: `testme`
2929

30-
## 8. 09 Implementing 'beforeEach' and 'it'
30+
## 8. 09 Implementing 'beforeEach' and 'it'
31+
32+
## 9. 10 Adding Basic Reporting

0 commit comments

Comments
 (0)