Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable parallel mocha testing #5011

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/build/bin/run-mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Usage:

'use strict';

const path = require('path');
const fs = require('fs-extra');

function run(argv, options) {
const utils = require('./utils');

Expand Down Expand Up @@ -58,6 +61,17 @@ function run(argv, options) {
mochaOpts.splice(lang, 2);
}

// Set `--parallel` for `@loopback/*` packages
Copy link
Member

@bajtos bajtos Jun 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this is a good idea, because it affects code outside our monorepo too. Two examples:

  • Example projects created via lb4 example <name>. Besides the extra complexity related to parallel testing, I am concerned about the impact on performance. Based on my measurement, examples/todo tests are ~15x slower when executed in parallel:

    examples/todo$ npm t
    (...)
      29 passing (481ms)
    
    examples/todo$ npm t -- --parallel
    (...)
      29 passing (7s)
    
  • External repositories like https://github.com/strongloop/loopback4-example-shopping. I am not sure how much work is required to support parallel testing in the shopping example and I would rather not block upgrading to the latest @loopback/build version until we can figure out parallel testing.

I am proposing to enable parallel testing by changing npm run mocha script to add --parallel flag to mocha CLI options.

Copy link
Member

@bajtos bajtos Jun 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See e.g. b44c7ee

-"mocha": "node packages/build/bin/run-mocha --lang en_US.UTF-8 --timeout 5000 \"packages/*/dist/__tests__/**/*.js\" \"extensions/*/dist/__tests__/**/*.js\" \"examples/*/dist/__tests__/**/*.js\" \"packages/cli/test/**/*.js\" \"packages/build/test/*/*.js\"",
+"mocha": "node packages/build/bin/run-mocha --lang en_US.UTF-8 --timeout 15000 --parallel \"packages/*/dist/__tests__/**/*.js\" \"extensions/*/dist/__tests__/**/*.js\" \"examples/*/dist/__tests__/**/*.js\" \"packages/cli/test/**/*.js\" \"packages/build/test/*/*.js\"",

Having said that, I think it's time to move flags from run-mocha CLI args into the monorepo-level .mocharc.js file. That way they are always applied, for example when running a subset of tests manually via node packages/build/bin/run-mocha path/to/some/files.

if (!mochaOpts.includes('--parallel')) {
const pkgFile = path.join(utils.getPackageDir(), 'package.json');
if (fs.existsSync(pkgFile)) {
const pkg = fs.readJsonSync(pkgFile);
if (pkg.name.startsWith('@loopback/')) {
mochaOpts.push('--parallel');
}
}
}

const args = [...mochaOpts];

return utils.runCLI('mocha/bin/mocha', args, options);
Expand Down