Skip to content

Commit a1b68cd

Browse files
authored
Merge branch 'mochajs:master' into configurable-max-diff-size
2 parents 8299390 + 509938d commit a1b68cd

27 files changed

+4757
-3476
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,5 +530,6 @@ Michal Dorner <[email protected]>
530530
Curtis Man <[email protected]>
531531
532532
Andrei Rusu <[email protected]>
533+
Quentin Barbe <[email protected]>
533534

534535
# Generated by scripts/update-authors.js

CHANGELOG.md

Lines changed: 67 additions & 47 deletions
Large diffs are not rendered by default.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(The MIT License)
22

3-
Copyright (c) 2011-2021 OpenJS Foundation and contributors, https://openjsf.org
3+
Copyright (c) 2011-2022 OpenJS Foundation and contributors, https://openjsf.org
44

55
Permission is hereby granted, free of charge, to any person obtaining
66
a copy of this software and associated documentation files (the

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,6 @@ Finally, come [chat with the maintainers](https://gitter.im/mochajs/contributors
6565

6666
## License
6767

68-
Copyright 2011-2021 OpenJS Foundation and contributors. Licensed [MIT](https://github.com/mochajs/mocha/blob/master/LICENSE).
68+
Copyright 2011-2022 OpenJS Foundation and contributors. Licensed [MIT](https://github.com/mochajs/mocha/blob/master/LICENSE).
6969

7070
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fmochajs%2Fmocha.svg?type=large)](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fmochajs%2Fmocha?ref=badge_large)

docs/_data/supporters.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
'use strict';
1919

2020
const {loadImage} = require('canvas');
21-
const {writeFile, mkdir, rmdir} = require('fs').promises;
21+
const {writeFile, mkdir, rm} = require('fs').promises;
2222
const {resolve} = require('path');
2323
const debug = require('debug')('mocha:docs:data:supporters');
2424
const needle = require('needle');
@@ -225,7 +225,7 @@ const getSupporters = async () => {
225225
}
226226
);
227227

228-
await rmdir(SUPPORTER_IMAGE_PATH, {recursive: true});
228+
await rm(SUPPORTER_IMAGE_PATH, {recursive: true, force: true});
229229
debug('blasted %s', SUPPORTER_IMAGE_PATH);
230230
await mkdir(SUPPORTER_IMAGE_PATH, {recursive: true});
231231
debug('created %s', SUPPORTER_IMAGE_PATH);

docs/_includes/default.liquid

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,14 @@
2525

2626
<main id="content">{{ content }}</main>
2727

28-
<aside class="sponsorship">
29-
<a
30-
href="https://matomo.org/"
31-
rel="external noopener"
32-
title="Mocha is sponsored by Matomo"
33-
>
34-
<img src="images/matomo-logo.png?trim" loading="lazy" alt="Matomo logo" />
28+
<div class="sponsorship">
29+
<a href="https://matomo.org/" rel="external noopener" title="Mocha is sponsored by Matomo">
30+
<img src="images/matomo-logo.png?trim" loading="lazy" width="100" alt="Matomo logo">
3531
</a>
36-
<a
37-
title="Mocha is an OpenJS Foundation Project"
38-
href="https://openjsf.org"
39-
rel="external noopener"
40-
>
41-
<img
42-
src="/images/openjsf-logo.svg"
43-
loading="lazy"
44-
width="300"
45-
height="94"
46-
alt="OpenJS Foundation Logo"
47-
/>
32+
<a href="https://wallabyjs.com" rel="external noopener" title="Mocha is sponsored by Wallaby" id="wallaby-logo">
33+
<img src="https://wallabyjs.com/assets/img/logoWithText.svg" loading="lazy" width="140" alt="Wallaby logo">
4834
</a>
49-
<a
50-
href="https://wallabyjs.com"
51-
rel="external noopener"
52-
title="Mocha is sponsored by Wallaby"
53-
>
54-
<figure id="wallaby-logo">
55-
<img src="images/wallaby-logo.png" loading="lazy" alt="Wallaby logo" />
56-
<figcaption>Wallaby</figcaption>
57-
</figure>
58-
</a>
59-
</aside>
35+
</div>
6036

6137
<footer>
6238
<div id="copyright-notice">
@@ -100,6 +76,12 @@
10076
</p>
10177
</div>
10278

79+
<div class="openjsf-logo">
80+
<a title="Mocha is an OpenJS Foundation Project" href="https://openjsf.org" rel="external noopener" >
81+
<img src="/images/openjsf-logo.svg" loading="lazy" width="120" alt="OpenJS Foundation Logo">
82+
</a>
83+
</div>
84+
10385
<div id="external-links">
10486
<ul id="openjsf-links">
10587
<li>
@@ -148,9 +130,7 @@
148130
</ul>
149131
<div class="netlify-badge">
150132
<a href="https://www.netlify.com">
151-
<img
152-
src="https://www.netlify.com/img/global/badges/netlify-color-accent.svg" loading="lazy"
153-
/>
133+
<img src="https://www.netlify.com/img/global/badges/netlify-color-accent.svg" loading="lazy">
154134
</a>
155135
</div>
156136
</div>

docs/css/style.css

Lines changed: 18 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ header {
4545
}
4646

4747
#content {
48-
padding-bottom: 60px;
48+
padding-bottom: 30px;
4949
}
5050

5151
#_header h1 {
@@ -242,31 +242,6 @@ img.screenshot {
242242
max-width: 100%;
243243
}
244244

245-
.sponsorship a {
246-
display: flex;
247-
justify-content: center;
248-
align-items: center;
249-
}
250-
251-
.sponsorship a img {
252-
display: block;
253-
object-fit: cover;
254-
width: 100%;
255-
height: 100%;
256-
}
257-
258-
.sponsorship {
259-
display: flex;
260-
justify-content: center;
261-
margin-bottom: 60px;
262-
align-items: center;
263-
}
264-
265-
.sponsorship a {
266-
padding: 0 40px;
267-
text-decoration: none;
268-
}
269-
270245
footer {
271246
background-color: #eee;
272247
border-top: 1px solid #ddd;
@@ -309,12 +284,29 @@ footer {
309284
content: ' | ';
310285
}
311286

287+
.openjsf-logo {
288+
margin-bottom: 10px;
289+
}
290+
312291
#external-links .netlify-badge {
313292
position: absolute;
314293
right: 0;
315294
bottom: 0;
316295
}
317296

297+
.sponsorship {
298+
display: flex;
299+
align-items: center;
300+
justify-content: center;
301+
margin-bottom: 30px;
302+
}
303+
304+
.sponsorship a {
305+
display: inline-block;
306+
margin-right: 15px;
307+
margin-left: 15px;
308+
}
309+
318310
.dl-inline dt,
319311
.dl-inline dd {
320312
display: inline;
@@ -335,23 +327,6 @@ blockquote {
335327
padding: 10px;
336328
}
337329

338-
figure#wallaby-logo {
339-
vertical-align: top;
340-
display: inline-block;
341-
text-align: center;
342-
}
343-
figure#wallaby-logo figcaption {
344-
margin-top: 10px;
345-
display: block;
346-
font-family: 'Open Sans', -apple-system, system-ui, 'Segoe UI', Oxygen, Ubuntu,
347-
Cantarell, 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
348-
font-weight: 400;
349-
letter-spacing: 2px;
350-
text-transform: uppercase;
351-
color: #2c2c2c;
352-
-webkit-font-smoothing: antialiased;
353-
}
354-
355330
table {
356331
width: 100%;
357332
}

docs/index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,12 @@ Free-tier cloud CI services may not provide a suitable multi-core container or V
13891389

13901390
It's unlikely (but not impossible) to see a performance gain from a [job count](#-jobs-count-j-count) _greater than_ the number of available CPU cores. That said, _play around with the job count_--there's no one-size-fits all, and the unique characteristics of your tests will determine the optimal number of jobs; it may even be that fewer is faster!
13911391

1392+
### Parallel Mode Worker IDs
1393+
1394+
> _New in v9.2.0_
1395+
1396+
Each process launched by parallel mode is assigned a unique id, from 0 for the first process to be launched, to N-1 for the Nth process. This worker id may be accessed in tests via the environment variable `MOCHA_WORKER_ID`. It can be used for example to assign a different database, service port, etc for each test process.
1397+
13921398
## Root Hook Plugins
13931399

13941400
> _New in v8.0.0_

lib/nodejs/buffered-worker-pool.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,23 @@ class BufferedWorkerPool {
7575
process.execArgv.join(' ')
7676
);
7777

78-
this.options = {...WORKER_POOL_DEFAULT_OPTS, opts, maxWorkers};
78+
let counter = 0;
79+
const onCreateWorker = ({forkOpts}) => {
80+
return {
81+
forkOpts: {
82+
...forkOpts,
83+
// adds an incremental id to all workers, which can be useful to allocate resources for each process
84+
env: {...process.env, MOCHA_WORKER_ID: counter++}
85+
}
86+
};
87+
};
88+
89+
this.options = {
90+
...WORKER_POOL_DEFAULT_OPTS,
91+
...opts,
92+
maxWorkers,
93+
onCreateWorker
94+
};
7995
this._pool = workerpool.pool(WORKER_PATH, this.options);
8096
}
8197

lib/nodejs/esm-utils.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,30 @@ exports.requireOrImport = hasStableEsmImplementation
5353
err.code === 'ERR_UNSUPPORTED_DIR_IMPORT'
5454
) {
5555
try {
56+
// Importing a file usually works, but the resolution of `import` is the ESM
57+
// resolution algorithm, and not the CJS resolution algorithm. So in this case
58+
// if we fail, we may have failed because we tried the ESM resolution and failed
59+
// So we try to `require` it
5660
return require(file);
5761
} catch (requireErr) {
58-
if (requireErr.code === 'ERR_REQUIRE_ESM') {
59-
// This happens when the test file is a JS file, but via type:module is actually ESM,
62+
if (
63+
requireErr.code === 'ERR_REQUIRE_ESM' ||
64+
(requireErr instanceof SyntaxError &&
65+
requireErr
66+
.toString()
67+
.includes('Cannot use import statement outside a module'))
68+
) {
69+
// ERR_REQUIRE_ESM happens when the test file is a JS file, but via type:module is actually ESM,
6070
// AND has an import to a file that doesn't exist.
61-
// This throws an `ERR_MODULE_NOT_FOUND` // error above,
71+
// This throws an `ERR_MODULE_NOT_FOUND` error above,
6272
// and when we try to `require` it here, it throws an `ERR_REQUIRE_ESM`.
6373
// What we want to do is throw the original error (the `ERR_MODULE_NOT_FOUND`),
6474
// and not the `ERR_REQUIRE_ESM` error, which is a red herring.
75+
//
76+
// SyntaxError happens when in an edge case: when we're using an ESM loader that loads
77+
// a `test.ts` file (i.e. unrecognized extension), and that file includes an unknown
78+
// import (which thows an ERR_MODULE_NOT_FOUND). require-ing it will throw the
79+
// syntax error, because we cannot require a file that has import-s.
6580
throw err;
6681
} else {
6782
throw requireErr;

0 commit comments

Comments
 (0)