File tree Expand file tree Collapse file tree 2 files changed +7
-5
lines changed Expand file tree Collapse file tree 2 files changed +7
-5
lines changed Original file line number Diff line number Diff line change 1
1
+++
2
2
title = " ReInvent: 重新造轮子系列(序言)"
3
3
date = 2025-02-16T22:10:00-08:00
4
- lastmod = 2025-02-17T11:12:38 -08:00
4
+ lastmod = 2025-02-17T11:20:03 -08:00
5
5
tags = [" reinvent" ]
6
6
categories = [" ReInvent: 重新造轮子系列" ]
7
7
draft = false
@@ -27,7 +27,9 @@ toc = true
27
27
也希望其他人也可以从中受益。
28
28
29
29
30
- ## <span class =" section-num " >2</span > 目录 {#目录}
30
+ ## <span class =" section-num " >2</span > 项目 {#项目}
31
+
32
+ GitHub: < https://github.com/ramsayleung/reinvent >
31
33
32
34
原书是用 node + Javascript 编写的,部分代码因API变更而变得不可用,因此本项目也做了对应修改,并将 Javascript 替换成 Typescript, 通过类型系统来降低维护成本。
33
35
Original file line number Diff line number Diff line change 1
1
+++
2
2
title = " 重新造轮子系列(一):从0开发单元测试框架"
3
3
date = 2025-02-16T22:27:00-08:00
4
- lastmod = 2025-02-17T11:07 :56-08:00
4
+ lastmod = 2025-02-17T11:19 :56-08:00
5
5
tags = [" reinvent" ]
6
6
categories = [" ReInvent: 重新造轮子系列" ]
7
7
draft = false
72
72
73
73
{{< figure src="/ox-hugo/unit_test_result_state.png" >}}
74
74
75
- 我们把要实现的单元测试框架命名为 = Hope=, 根据上面的状态机,我们很快就可以写出一个原型:
75
+ 我们把要实现的单元测试框架命名为 ` Hope ` , 根据上面的状态机,我们很快就可以写出一个原型:
76
76
77
77
单元测试用例接收一个函数作为参数,然后又集中运行所有的测试用例,并根据是否抛出异常以及异常的类型来判断结果:
78
78
@@ -198,7 +198,7 @@ export default new Hope()
198
198
上面的代码又是如何实现单例模式的呢?依靠的是 Node 的两个运行机制:
199
199
200
200
1 . 在加载一个 ` module ` 的时候, 它就会解释并执行 ` module ` 的代码,这意味着它会运行 ` new Hope() ` 并且导出新创建的实例
201
- 2 . 那么是否意味着,每个 ` import ` 语句都会运行一下 ` new Hope() ` 呢? 并不是,Node会缓存导入的 ` module= ,也就是说无论一个 = module ` 被导入多少次, 它也只会执行一次代码。
201
+ 2 . 那么是否意味着,每个 ` import ` 语句都会运行一下 ` new Hope() ` 呢? 并不是,Node会缓存导入的 ` module ` ,也就是说无论一个 ` module ` 被导入多少次, 它也只会执行一次代码。
202
202
203
203
只要导入 ` hope.ts ` 之后, 就可以使用 ` hope.test() ` 会注册单元测试用例,以便后续执行:
204
204
![ ] ( /ox-hugo/unit_test_hope_structure.svg )
You can’t perform that action at this time.
0 commit comments