Skip to content

Commit

Permalink
build: test parallelization ⚡️ (#3319)
Browse files Browse the repository at this point in the history
  • Loading branch information
erickzhao committed Aug 29, 2023
1 parent a7f7a9f commit 478d4a4
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 65 deletions.
72 changes: 45 additions & 27 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 2.1

orbs:
node: electronjs/node@1.1.0
node: electronjs/node@1.4.1

commands:
install:
Expand All @@ -10,25 +10,51 @@ commands:
- node/install:
node-version: '18.15.0'
- checkout
run-fast-tests:
run-lint-and-build:
steps:
- node/install-packages
- run:
name: 'Lint codebase'
command: |
yarn lint
yarn syncpack
- run:
name: 'Build Electron Forge'
command: |
yarn build
run-fast-tests:
steps:
- node/install-packages
- attach_workspace:
at: .
- run:
name: 'Run fast tests'
command: |
yarn test:fast
run-slow-tests:
steps:
- node/install-packages
- attach_workspace:
at: .
- run:
name: 'Run slow tests'
command: |
yarn lint
yarn build
yarn test:slow
echo $(circleci tests glob "packages/**/*_spec_slow.ts")
TEST_GLOB=$(circleci tests glob "packages/**/*_spec_slow.ts" | circleci tests split --split-by=timings)
yarn test $TEST_GLOB
jobs:
lint-and-build:
executor: node/linux
steps:
- install
- run-lint-and-build
- persist_to_workspace:
root: .
paths:
- packages/*/*/dist/*

fast-tests:
parameters:
executor:
Expand Down Expand Up @@ -69,28 +95,21 @@ jobs:
type: enum
enum: ['x64', 'arm64']
executor: << parameters.executor >>
parallelism: 2
steps:
- install
- when:
condition:
equal: [node/windows, << parameters.executor >>]
steps:
- node/install-packages
- run:
name: setup Windows and run slow tests
shell: powershell.exe -ExecutionPolicy Bypass
name: Windows Setup
shell: bash
command: |
Write-Output "Installing WiX Toolset"
choco install --no-progress -y wixtoolset
Write-Output "Reloading PATH"
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
[Environment]::SetEnvironmentVariable("PATH", $env:Path + "C:\Program Files (x86)\WiX Toolset v3.11\bin;", "Machine")
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
npm config set node-gyp "$CIRCLE_WORKING_DIRECTORY\node_modules\node-gyp\bin\node-gyp.js"
yarn lint
yarn build
yarn test:slow
echo 'export PATH=$PATH:"/C/Program Files (x86)/WiX Toolset v3.11/bin"' >> "$BASH_ENV"
cd 'C:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\run-script'
npm install node-gyp@9.4.0
- when:
condition:
equal: [node/linux, << parameters.executor >>]
Expand All @@ -109,20 +128,17 @@ jobs:
libgdk-pixbuf2.0-dev \
libgtk-3-0 \
libgbm1
- when:
condition:
or:
- equal: [node/macos, << parameters.executor >>]
- equal: [node/linux, << parameters.executor >>]
steps:
- run-slow-tests
- store_test_results:
path: ./reports/
- run-slow-tests
- store_test_results:
path: ./reports/

workflows:
tests:
jobs:
- lint-and-build
- fast-tests:
requires:
- lint-and-build
matrix:
parameters:
executor: [node/windows, node/linux, node/macos]
Expand All @@ -133,6 +149,8 @@ workflows:
- executor: node/linux
arch: arm64
- slow-tests:
requires:
- lint-and-build
matrix:
parameters:
executor: [node/windows, node/linux, node/macos]
Expand Down
33 changes: 32 additions & 1 deletion .mocharc.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,47 @@
const path = require('path');
const minimist = require('minimist');

const {
_: [_node, _mocha, ...args], // _ contains the node binary, the mocha binary, and any positional args
...flags
} = minimist(process.argv);

process.env.LINK_FORGE_DEPENDENCIES_ON_INIT = true;

let testGlob;

/**
* Determine which sets of tests to run. Priority goes:
* 1. If positional arguments are passed in, run those files.
* 2. If `--suite` is either slow or fast, run slow or fast test.
* 3. Otherwise, run all spec tests.
*/
if (args.length === 0) {
if (flags.suite === 'fast') {
testGlob = 'packages/**/*_spec.ts';
} else if (flags.suite === 'slow') {
testGlob = 'packages/**/*_spec_slow.ts';
} else {
testGlob = 'packages/**/**/*_spec*';
}
}

// In CI, use the JUnit reporter to upload results to CircleCI.
// Locally, use the default 'spec' reporter.
const reporterConfig = process.env.CI
? {
reporter: 'mocha-junit-reporter',
'reporter-option': ['mochaFile=./reports/test_output.xml'],
}
: {};

module.exports = {
const opts = {
extension: ['ts'],
require: ['ts-node/register', path.join(__dirname, 'tools', 'test-setup.ts')],
spec: testGlob,
timeout: 800000,
recursive: true,
...reporterConfig,
};

module.exports = opts;
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
"lint:fix": "prettier --write .",
"link:prepare": "lerna exec -- node ../../../tools/silent.js yarn link --silent --no-bin-links --link-folder ../../../.links",
"link:remove": "lerna exec -- node ../../../tools/silent.js yarn unlink --silent --no-bin-links --link-folder ../../../.links",
"test": "xvfb-maybe cross-env NODE_ENV=test LINK_FORGE_DEPENDENCIES_ON_INIT=1 TS_NODE_PROJECT='./tsconfig.test.json' TS_NODE_FILES=1 mocha './tools/test-globber.ts'",
"test:fast": "xvfb-maybe cross-env NODE_ENV=test LINK_FORGE_DEPENDENCIES_ON_INIT=1 TS_NODE_PROJECT='./tsconfig.test.json' TEST_FAST_ONLY=1 TS_NODE_FILES=1 mocha './tools/test-globber.ts'",
"test:slow": "xvfb-maybe cross-env NODE_ENV=test LINK_FORGE_DEPENDENCIES_ON_INIT=1 TS_NODE_PROJECT='./tsconfig.test.json' TEST_SLOW_ONLY=1 TS_NODE_FILES=1 mocha './tools/test-globber.ts'",
"test": "xvfb-maybe cross-env NODE_ENV=test TS_NODE_PROJECT='./tsconfig.test.json' TS_NODE_FILES=1 mocha",
"test:fast": "npm run test -- --suite=fast",
"test:slow": "npm run test -- --suite=slow",
"postinstall": "rimraf node_modules/.bin/*.ps1 && ts-node ./tools/gen-tsconfigs.ts && ts-node ./tools/gen-ts-glue.ts",
"prepare": "husky install",
"preversion": "yarn build"
Expand Down
2 changes: 1 addition & 1 deletion packages/maker/appx/test/MakerAppX_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import fs from 'fs-extra';

import { createDefaultCertificate } from '../src/MakerAppX';

describe('MakerApPX', () => {
describe('MakerAppX', () => {
describe('createDefaultCertificate', () => {
const tmpDir = join(tmpdir(), `electron-forge-maker-appx-test-${Date.now()}`);

Expand Down
33 changes: 0 additions & 33 deletions tools/test-globber.ts

This file was deleted.

0 comments on commit 478d4a4

Please sign in to comment.