Skip to content

Commit

Permalink
test: add utility process mocha runner to run net module tests
Browse files Browse the repository at this point in the history
  • Loading branch information
devm33 committed Oct 17, 2023
1 parent 66d9eef commit 6d1b1c6
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
7 changes: 7 additions & 0 deletions spec/api-utility-process-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,4 +435,11 @@ describe('utilityProcess module', () => {
await exit;
});
});

it('should pass the api-net-spec tests', async () => {
const child = utilityProcess.fork(path.join(fixturesPath, 'mocha.js'));
child.postMessage('spec/api-net-spec.ts');
const [code] = await once(child, 'exit');
expect(code).to.equal(0);
});
});
61 changes: 61 additions & 0 deletions spec/fixtures/api/utility-process/mocha.js
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);
});
});
});

0 comments on commit 6d1b1c6

Please sign in to comment.