forked from electron/electron
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add utility process mocha runner to run net module tests
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
const path = require('node:path'); | ||
const v8 = require('node:v8'); | ||
|
||
require('ts-node/register'); | ||
|
||
v8.setFlagsFromString('--expose_gc'); | ||
|
||
const Mocha = require('mocha'); | ||
const mochaOptions = { | ||
forbidOnly: process.env.CI | ||
}; | ||
if (process.env.CI) { | ||
mochaOptions.retries = 3; | ||
} | ||
if (process.env.MOCHA_REPORTER) { | ||
mochaOptions.reporter = process.env.MOCHA_REPORTER; | ||
} | ||
if (process.env.MOCHA_MULTI_REPORTERS) { | ||
mochaOptions.reporterOptions = { | ||
reporterEnabled: process.env.MOCHA_MULTI_REPORTERS | ||
}; | ||
} | ||
const mocha = new Mocha(mochaOptions); | ||
|
||
const { runCleanupFunctions } = require('../../../lib/spec-helpers'); | ||
mocha.suite.on('suite', function attach (suite) { | ||
suite.afterEach('cleanup', runCleanupFunctions); | ||
suite.on('suite', attach); | ||
}); | ||
|
||
if (!process.env.MOCHA_REPORTER) { | ||
mocha.ui('bdd').reporter('tap'); | ||
} | ||
|
||
const mochaTimeout = process.env.MOCHA_TIMEOUT || 30000; | ||
mocha.timeout(mochaTimeout); | ||
|
||
const baseElectronDir = path.resolve(__dirname, '../../../..'); | ||
|
||
process.parentPort.on('message', (e) => { | ||
console.log('child received', e); | ||
console.log('path', path.join(baseElectronDir, e.data)); | ||
|
||
mocha.addFile(path.join(baseElectronDir, e.data)); | ||
|
||
// Set up chai in the correct order | ||
const chai = require('chai'); | ||
chai.use(require('chai-as-promised')); | ||
chai.use(require('dirty-chai')); | ||
|
||
// Show full object diff | ||
// https://github.com/chaijs/chai/issues/469 | ||
chai.config.truncateThreshold = 0; | ||
|
||
mocha.run((failures) => { | ||
// Ensure the callback is called after runner is defined | ||
process.nextTick(() => { | ||
process.exit(failures); | ||
}); | ||
}); | ||
}); |