1 of 85

Marco Ippolito

Exploring Node.js�test runner

© Copyright 2023 NearForm Ltd. All Rights Reserved.

2 of 85

Marco Ippolito

@satanacchio

Senior Developer Experience Engineer @NearForm

Core contributor @Node.js

Open Source Enthusiast

2

3 of 85

@satanacchio

What’s a test runner?

3

4 of 85

@satanacchio

A test runner is a tool used to run or execute tests and export results

4

5 of 85

@satanacchio

It selects the source code directories and picks the test files to run

5

6 of 85

@satanacchio

A few examples…

  • JUnit

6

7 of 85

@satanacchio

A few examples…

  • JUnit

  • pytest

7

8 of 85

@satanacchio

A few examples…

  • JUnit

  • pytest

  • go test

8

9 of 85

@satanacchio

A few examples…

  • JUnit

  • pytest

  • go test

  • xUnit

9

10 of 85

So cypress is a test runner right?

@satanacchio

10

11 of 85

@satanacchio

11

12 of 85

@satanacchio

Classification

  • Mocha is a test runner and a testing framework

12

13 of 85

@satanacchio

Test runners always include testing framework

13

14 of 85

@satanacchio

Classification

  • Mocha is a test runner and a testing framework

  • Cypress is a testing framework (built on mocha)

14

15 of 85

@satanacchio

Classification

  • Mocha is a test runner and a testing framework

  • Cypress is a testing framework (built on mocha)

  • Chai is an assertion library (built on mocha)

15

16 of 85

What about ?

@satanacchio

16

17 of 85

@satanacchio

17

18 of 85

@satanacchio

18

19 of 85

@satanacchio

19

20 of 85

@satanacchio

20

21 of 85

@satanacchio

21

22 of 85

@satanacchio

22

23 of 85

@satanacchio

23

24 of 85

@satanacchio

24

25 of 85

@satanacchio

25

26 of 85

@satanacchio

26

27 of 85

@satanacchio

27

28 of 85

Why are there so many test runners?

@satanacchio

28

29 of 85

@satanacchio

Node.js follows the “minimal core” principle, it delegates everything non essential to the ecosystem

29

30 of 85

@satanacchio

30

31 of 85

Improving developer experience and reducing surface for NPM supply chain attacks

@satanacchio

31

32 of 85

@satanacchio

Node.js was shipping only an assertion library.

32

33 of 85

@satanacchio

Node.js was shipping only an assertion library. It needed a native test runner

33

34 of 85

@satanacchio

Node.js was shipping only an assertion library. It needed a native test runner, and a testing framework

34

35 of 85

@satanacchio

35

36 of 85

@satanacchio

The test runner is stable and production ready�with Node 20

36

37 of 85

We finally

made it!

@satanacchio

37

38 of 85

@satanacchio

The test runner was inspired by node-tap

38

39 of 85

@satanacchio

39

40 of 85

@satanacchio

Some features!

  • Filtering (only, skip, —test-name-pattern)

40

41 of 85

@satanacchio

Some features!

  • Filtering (only, skip, —test-name-pattern)
  • Subtest

41

42 of 85

@satanacchio

Some features!

  • Filtering (only, skip, —test-name-pattern)
  • Subtest
  • Reporting (tap, spec, dot, junit)

42

43 of 85

@satanacchio

Some features!

  • Filtering (only, skip, —test-name-pattern)
  • Subtest
  • Reporting (tap, spec, dot, junit)
  • Mocking

43

44 of 85

@satanacchio

Some features!

  • Filtering (only, skip, —test-name-pattern)
  • Subtest
  • Reporting (tap, spec, dot, junit)
  • Mocking
  • Watch mode (--watch)

44

45 of 85

@satanacchio

Some features!

  • Filtering (only, skip, —test-name-pattern)
  • Subtest
  • Reporting (tap, spec, dot, junit)
  • Mocking
  • Watch mode (--watch)
  • Code coverage (--experimental-test-coverage)

45

46 of 85

“Talk is cheap, show me the code!” - Linus Torvalds

@satanacchio

46

47 of 85

@satanacchio

47

48 of 85

@satanacchio

48

49 of 85

@satanacchio

49

50 of 85

@satanacchio

50

51 of 85

@satanacchio

51

52 of 85

@satanacchio

52

53 of 85

@satanacchio

53

54 of 85

@satanacchio

54

55 of 85

@satanacchio

55

56 of 85

@satanacchio

56

57 of 85

@satanacchio

57

58 of 85

@satanacchio

58

59 of 85

@satanacchio

59

60 of 85

@satanacchio

60

61 of 85

@satanacchio

61

62 of 85

@satanacchio

62

63 of 85

@satanacchio

63

64 of 85

@satanacchio

64

65 of 85

@satanacchio

65

66 of 85

@satanacchio

66

67 of 85

@satanacchio

67

68 of 85

@satanacchio

68

69 of 85

@satanacchio

69

70 of 85

@satanacchio

70

71 of 85

@satanacchio

71

72 of 85

@satanacchio

72

73 of 85

Should I migrate my existing test suite tomorrow?

@satanacchio

73

74 of 85

@satanacchio

74

75 of 85

@satanacchio

Cons

  • Small ecosystem (libraries built on top, guides)

75

76 of 85

@satanacchio

Cons

  • Small ecosystem (libraries built on top, guides)

  • Fewer api compared to other test runners

76

77 of 85

@satanacchio

Cons

  • Small ecosystem (libraries built on top, guides)

  • Fewer api compared to other test runners�
  • No typescript support (natively, you can use ts-node)

77

78 of 85

@satanacchio

Desired features

  • Planning

78

79 of 85

@satanacchio

Desired features

  • Planning

  • Fake Timers

79

80 of 85

@satanacchio

Desired features

  • Planning

  • Fake Timers

80

81 of 85

@satanacchio

The test runner is evolving fast!

81

82 of 85

@satanacchio

Desired features

  • Planning

  • Fake Timers

  • Exit on failure

82

83 of 85

@satanacchio

83

84 of 85

@satanacchio

Desired features

  • Planning

  • Fake Timers

  • Exit on failure

  • Expect failure

84

85 of 85

United States:

International:

United Kingdom:

Ireland:

(916) 299-6882

+353 51 330 290

0870 067 95569

051 330 290

nearform.com

sales@nearform.com

Thanks for listening!!!