Advanced Suites
Suite Execution Options
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { suite, test, slow, timeout } from '@testdeck/mocha';
@suite(slow(4000))
@timeout(4000)
class Suite {
@test
slowButNotTimedOut(done) {
setTimeout(done, 3500);
}
@test
timedOut(done) {
setTimeout(done, 4500);
}
}
slow
slow
can be used as either a decorator or passed as a parameter to the @suite
decorator.
1
2
3
4
5
6
7
8
import { suite, test, slow } from '@testdeck/mocha';
@suite(slow(2000))
@slow(2000)
class Suite {
// ...
}
timeout
timeout
can be used as either a decorator or passed as a parameter to the @suite
decorator.
1
2
3
4
5
6
7
8
import { suite, test, timeout } from '@testdeck/mocha';
@suite(timeout(2000))
@timeout(2000)
class Suite {
// ...
}
Suite Naming
1
2
3
4
5
6
7
8
9
import { suite, test } from '@testdeck/mocha';
@suite("a custom name for a suite")
class Suite {
@test
test() {
}
}
Pending Suites
A suite can be marked as pending. A pending suite, without any tests will not show up in the report.
The @pending
decorator takes an optional boolean parameter. That way one can make individual suites pending based on
a given condition.
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
import { suite, test, pending } from '@testdeck/mocha';
@suite.pending("a pending suite")
class PendingSuite {
@test
test() {
}
}
@suite
@pending
class AlsoPendingSuite {
@test
test() {
}
}
@suite
@pending(isCondition)
class ConditionallyPendingSuite {
@test
test() {
}
}
Skipping Suites
A suite can be marked as skipped. A skipped suite, without any tests will not show up in the report.
The @skip
decorator takes an optional boolean parameter. That way one can make individual suites skip based on
a given condition.
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
import { suite, test, skip } from '@testdeck/mocha';
@suite.skip("a skipped suite")
class SkippedSuite {
@test
test() {
}
}
@suite
@skip
class AlsoSkippedSuite {
@test
test() {
}
}
@suite
@skip(isCondition)
class ConditionallySkippedSuite {
@test
test() {
}
}
Focused Suites
A suite can be marked as focused. A focused suite, without any tests will not show up in the report.
The @only
decorator takes an optional boolean parameter. That way one can make individual suites focused based on
a given condition.
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
import { suite, test, only } from '@testdeck/mocha';
@suite.only("a focused suite")
class FocusedSuite {
@test
test() {
}
}
@suite
@only
class AlsoFocusedSuite {
@test
test() {
}
}
@suite
@only(isCondition)
class ConditionallyFocusedSuite {
@test
test() {
}
}
Static Lifecycle Hooks
Testdeck
supports static test lifecycle hooks, namely before
and after
, which are equivalent to the beforeAll
and afterAll
test lifecycle hooks found in either of the supported test frameworks.
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
import { suite, test } from '@testdeck/mocha';
import * as k8s from '@kubernetes/client-node';
@suite
class Suite {
private static k8sApi;
static before(): Promise<any> {
const kc = new k8s.KubeConfig();
kc.loadFromDefault();
Suite.k8sApi = kc.makeApiClient(k8s.Core_v1Api);
const namespace = {
metadata: {
name: 'test'
}
};
return Suite.k8sApi.createNamespace(namespace).then(
(response) => {
// ... fire up some pods (kafka/zookeeper, microservice consumer/producer)
}, (err) => {
return Promise.reject(err);
}
);
}
@test
integrationTest() {
// send some message via kafka
// consume and test expected events from kafka topic
}
static after(): Promise<any> {
const k8sApi = Suite.k8sApi;
Suite.k8sApi = null;
// tear down pods and namespace
const namespace = {
metadata: {
name: 'test'
}
};
return k8sApi.deleteNamespace(namespace).then(
(response) => {
// ...
}, (err) => {
return Promise.reject(err);
}
);
}
}
Instance Lifecycle Hooks
Testdeck
also supports instance level test lifecycle hooks, which also go by the names before
and after
. These
hooks are the equivalent to the beforeEach
and afterEach
test lifecycle hooks found in either of the supported test
frameworks.
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
import { suite, test } from '@testdeck/mocha';
import { NgLangParser } from '../src/NgLangParser';
@suite
class Suite {
private cut: NgLangParser;
before() {
this.cut = new NgLangParser();
}
@test
mustParseEmptyString() {
this.cut.parse("");
}
after() {
this.cut = null;
}
}