mocha-distributed 0.9.2 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,9 +7,6 @@ services:
7
7
  ports:
8
8
  - 6379:6379
9
9
 
10
- networks:
11
- - mordor_gh_network
12
-
13
10
  redis-commander:
14
11
  image: rediscommander/redis-commander:latest
15
12
  environment:
@@ -19,9 +16,3 @@ services:
19
16
  depends_on:
20
17
  - redis
21
18
 
22
- networks:
23
- - mordor_gh_network
24
-
25
- networks:
26
- mordor_gh_network:
27
- external: true
@@ -24,7 +24,7 @@ describe ('suite-1-async', async function () {
24
24
 
25
25
  describe ('suite-1-sync', function () {
26
26
  it ('test-1.1-async', async function () {
27
- await util.sleep(0.5);
27
+ await util.sleep(1.5);
28
28
  })
29
29
 
30
30
  it ('test-1.2-sync', function () {
@@ -39,3 +39,27 @@ describe ('suite-1.2-sync', function () {
39
39
  });
40
40
  });
41
41
  });
42
+
43
+ describe ('suite-1.3-io', function () {
44
+ it ('console.log', function () {
45
+ console.log ("Writing from console.log\nAnother line")
46
+ });
47
+
48
+ it ('console.error', function () {
49
+ console.error ("Writing from console.error\nAnother line")
50
+ });
51
+
52
+ it ('process.stdout', function () {
53
+ process.stdout.write("Writing from process.stdout. No newline.")
54
+ });
55
+
56
+ it ('process.stderr', function () {
57
+ process.stderr.write("Writing from process.stderr. No newline.")
58
+ });
59
+
60
+ it ('process.stdout & process.stderr', function () {
61
+ process.stdout.write("stdout output\nanother line")
62
+ process.stderr.write("stderr output\nanother line\nand yet another one.")
63
+ });
64
+
65
+ });
package/index.js CHANGED
@@ -32,6 +32,8 @@ if (g_granularity !== GRANULARITY.TEST) {
32
32
 
33
33
  let g_redis = null;
34
34
 
35
+ let g_capture = { stdout: null, stderr: null };
36
+
35
37
  // -----------------------------------------------------------------------------
36
38
  // getTestPath
37
39
  //
@@ -57,6 +59,28 @@ function getTestPath(testContext) {
57
59
  return path.reverse();
58
60
  }
59
61
 
62
+ // -----------------------------------------------------------------------------
63
+ // captureStream
64
+ // -----------------------------------------------------------------------------
65
+ function captureStream(stream) {
66
+ var oldWrite = stream.write;
67
+ var buf = [];
68
+
69
+ stream.write = function(chunk, encoding, callback){
70
+ buf.push (chunk.toString()); // chunk is a String or Buffer
71
+ oldWrite.apply(stream, arguments);
72
+ }
73
+
74
+ return {
75
+ unhook(){
76
+ stream.write = oldWrite;
77
+ },
78
+ captured(){
79
+ return buf;
80
+ }
81
+ };
82
+ }
83
+
60
84
  // -----------------------------------------------------------------------------
61
85
  // Initialize redis once before the tests
62
86
  // -----------------------------------------------------------------------------
@@ -131,14 +155,36 @@ exports.mochaHooks = {
131
155
  this.currentTest.title += " (skipped by mocha_distributted)";
132
156
  this.skip();
133
157
  }
158
+ else {
159
+ g_capture.stdout = captureStream(process.stdout);
160
+ g_capture.stderr = captureStream(process.stderr);
161
+ }
134
162
  },
135
163
  afterEach(done) {
136
164
  const SKIPPED = "pending";
137
165
  const FAILED = "failed";
166
+ const PASSED = "passed";
167
+
168
+ let capturedStdout = '';
169
+ let capturedStderr = '';
170
+ if (g_capture.stdout) {
171
+ const stdoutArray = g_capture.stdout.captured();
172
+ capturedStdout = stdoutArray.join('');
173
+ capturedStdout = capturedStdout.replace(/\s*\u001b\[3[12]m[^\n]*\n$/g, '');
174
+ g_capture.stdout.unhook();
175
+ g_capture.stdout = null;
176
+ }
177
+
178
+ if (g_capture.stderr) {
179
+ capturedStderr = g_capture.stderr.captured().join('');
180
+ g_capture.stderr.unhook();
181
+ g_capture.stderr = null;
182
+ }
138
183
 
139
184
  // Save all data in redis in a way it can be retrieved and aggregated
140
185
  // easily for all test by an external reporter
141
186
  if (this.currentTest.state !== SKIPPED) {
187
+ const stateFixed = this.currentTest.state || (this.currentTest.timedOut ? FAILED : PASSED)
142
188
  const testResult = {
143
189
  id: getTestPath(this.currentTest),
144
190
  type: this.currentTest.type,
@@ -148,10 +194,12 @@ exports.mochaHooks = {
148
194
  startTime: Date.now() - (this.currentTest.duration || 0),
149
195
  endTime: Date.now(),
150
196
  file: this.currentTest.file,
151
- state: this.currentTest.state,
152
- failed: this.currentTest.state === FAILED,
197
+ state: stateFixed,
198
+ failed: stateFixed === FAILED,
153
199
  speed: this.currentTest.speed,
154
200
  err: this.currentTest.err || null,
201
+ stdout: capturedStdout,
202
+ stderr: capturedStderr
155
203
  };
156
204
 
157
205
  // save results as single line on purpose
@@ -160,7 +208,7 @@ exports.mochaHooks = {
160
208
  g_redis.expire(key, g_expirationTime);
161
209
 
162
210
  // increment passed_count/failed_count & set expiry time
163
- const countKey = `${g_testExecutionId}:${this.currentTest.state}_count`
211
+ const countKey = `${g_testExecutionId}:${stateFixed}_count`
164
212
  g_redis.incr(countKey);
165
213
  g_redis.expire(countKey, g_expirationTime);
166
214
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mocha-distributed",
3
- "version": "0.9.2",
4
- "description": "Run multiple mocha suites and tests in parallel, from different processes or different machines",
3
+ "version": "0.9.3",
4
+ "description": "Run multiple mocha suites and tests in parallel, from different processes and different machines. Results available on a redis database.",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -14,6 +14,7 @@
14
14
  "integration tests",
15
15
  "pipelines",
16
16
  "chai",
17
+ "expect",
17
18
  "kubernetes",
18
19
  "docker",
19
20
  "mocha-parallel-tests",