-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtutorial-30-anatomy-of-suman-suite.html
executable file
·165 lines (100 loc) · 7.12 KB
/
tutorial-30-anatomy-of-suman-suite.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Tutorial: Anatomy of Suman Test Suites</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Tutorial: Anatomy of Suman Test Suites</h1>
<section>
<header>
<h2>Anatomy of Suman Test Suites</h2>
</header>
<article>
<p>This article goes into intricate detail about the "hidden" contexts in different scopes of a Suman test </p>
<pre class="prettyprint source lang-js"><code>
//we have our root suite, followed by a nested child suite A, that in turn has a nested child suite B
//if you run this example, and look at the logs, you will get a feel for how a Suman test is executed
const suman = require('suman');
const Test = suman.init(module, {});
Test.describe('root suite description', {}, function () { // we define the root suite
//note: we are in the context of the "root suite"
const self = this; // (avoid the self pattern in Suman tests, here for explanation only :)
this.before(t => {
console.log('1', this === self); //true (has to be, due to arrow functions)
});
this.beforeEach(function (t) {
console.log('2', this === self); //true
});
this.it(function (t) {
console.log('3', this === self); //true
});
this.describe('child suite A', {}, function () { //calling 'this.describe' creates a child suite
console.log('4', this.parent.title === 'root suite description'); // true
const that = this; //we have a new context, and the new context pertains to child suite A
console.log('5', that !== self); // true
this.before(function (t) {
console.log('6', this === that); //true
});
this.beforeEach(t => {
console.log('7', this === that); //true
});
this.it(function (t) {
console.log('8', this === that); //true
});
this.describe('child suite B', {}, function () { //calling 'this.describe' creates a child suite
const ctx = this; //we have a new context, and the new context pertains to child suite B
console.log('9', this.parent.title === 'child suite A'); // true
console.log('10', (ctx !== that && ctx !== self)); // true
this.before(function (t) {
console.log('11', this === ctx); //true
});
this.beforeEach(function (t) {
console.log('12', this === ctx); //true
});
this.it(t => {
console.log('13', this === ctx); //true
});
});
});
});</code></pre><p>in test form that would look like!</p>
<pre class="prettyprint source lang-js"><code>
Test.describe('root suite description', {}, function(assert){ //root suite
//we are in the context of the root suite
const self = this; // (avoid the self pattern in Suman tests, here for explanation only :)
this.before(function(){
assert(this === self); //true
});
this.beforeEach(function(){
assert(this === self); //true
});
this.describe('child suite A', {}, function(){
assert(this.parent.title === 'root suite description'); // true
const that = this; // that !== self // true;
this.describe('child suite B', {}, function(){
assert(this.parent.title === 'child suite A'); // true
});
});
});</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Tutorials</h3><ul><li><a href="tutorial-00-about.html">About Suman</a></li><li><a href="tutorial-01-getting-started.html">Getting Started with Suman</a></li><li><a href="tutorial-02-simple-examples.html">Simple Examples</a></li><li><a href="tutorial-03-high-level-overview.html">Higher Level Overview</a></li><li><a href="tutorial-04-command-line-options.html">Command line options</a></li><li><a href="tutorial-05-advanced-use.html">Advanced Use</a></li><li><a href="tutorial-06-suman-config-file.html">06-suman-config-file</a></li><li><a href="tutorial-07-suman-patterns-and-recipes.html">Suman Patterns and Recipes</a></li><li><a href="tutorial-08-suman-anti-patterns.html">Suman Anti-Patterns</a></li><li><a href="tutorial-09-suman-reporters.html">Suman reporters and creating custom reporters</a></li><li><a href="tutorial-10-dependency-injection.html">10-dependency-injection</a></li><li><a href="tutorial-11-advanced-installation.html">Advanced installation of Suman</a></li><li><a href="tutorial-12-using-suman-with-babel.html">Using Suman with Babel</a></li><li><a href="tutorial-13-test-dir-organization.html">How to organize your test directory</a></li><li><a href="tutorial-14-debugging-suman.html">How to debug Suman tests</a></li><li><a href="tutorial-15-testing-child-processes-with-suman.html">Testing and debugging processes that spawn child processes</a></li><li><a href="tutorial-16-using-spies-with-suman.html">Using test spies with Suman</a></li><li><a href="tutorial-17-suman-server-and-web-reporter.html">About Suman server and built-in web reporter</a></li><li><a href="tutorial-18-tips-and-tricks.html">Tips and tricks</a></li><li><a href="tutorial-19-converting-from-mocha.html">Converting from Mocha to Suman</a></li><li><a href="tutorial-21-running-suman-against-shell-scripts.html">21-running-suman-against-shell-scripts</a></li><li><a href="tutorial-22-case-studies.html">22-case-studies</a></li><li><a href="tutorial-22-programmatic-usage-and-macros.html">22-programmatic-usage-and-macros</a></li><li><a href="tutorial-27-suman-best-practices.html">Best practices with Suman</a></li><li><a href="tutorial-30-anatomy-of-suman-suite.html">Anatomy of Suman Test Suites</a></li><li><a href="tutorial-31-workflows-with-suman.html">Workflows with Suman => Watchers and transpilation</a></li><li><a href="tutorial-40-integrating-with-ci-cd.html">Integrating with CI/CD</a></li><li><a href="tutorial-41-suman-exit-codes.html">List of Suman exit codes</a></li><li><a href="tutorial-42-hidden-secret-features.html">Some secret / hidden features of Suman</a></li><li><a href="tutorial-50-suman-parallelism.html">Complete explanation of Suman parallelism</a></li><li><a href="tutorial-70-usage-with-code-coverage-tools.html">Usage with code coverage tools (namely Istanbul)</a></li><li><a href="tutorial-90-roadmap.html">Suman roadmap and upcoming efforts</a></li><li><a href="tutorial-99-faq.html">FAQ</a></li><li><a href="tutorial-advanced-parallelization-2.html">advanced-parallelization-2</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Wed Feb 08 2017 22:39:23 GMT-0800 (PST)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>