diff --git a/.circleci/config.yml b/.circleci/config.yml index db67136aa4..320a9a8125 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,7 +1,7 @@ version: 2.1 orbs: - node: electronjs/node@1.1.0 + node: electronjs/node@1.4.1 commands: install: @@ -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: @@ -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 >>] @@ -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] @@ -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] diff --git a/.mocharc.js b/.mocharc.js index 4a77d12cff..b365b23201 100644 --- a/.mocharc.js +++ b/.mocharc.js @@ -1,5 +1,33 @@ 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', @@ -7,10 +35,13 @@ const reporterConfig = process.env.CI } : {}; -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; diff --git a/package.json b/package.json index 285085a463..4f353de2b0 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/packages/maker/appx/test/MakerAppX_spec.ts b/packages/maker/appx/test/MakerAppX_spec.ts index 203e4d2d9c..9375c82556 100644 --- a/packages/maker/appx/test/MakerAppX_spec.ts +++ b/packages/maker/appx/test/MakerAppX_spec.ts @@ -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()}`); diff --git a/tools/test-globber.ts b/tools/test-globber.ts deleted file mode 100644 index c1a2ee1019..0000000000 --- a/tools/test-globber.ts +++ /dev/null @@ -1,33 +0,0 @@ -import * as path from 'path'; - -import glob from 'fast-glob'; -import minimist from 'minimist'; - -import { getPackageInfoSync } from './utils'; - -const argv = minimist(process.argv.slice(process.argv.findIndex((arg) => arg === 'mocha.opts'))); - -const isSlow = argv.slow || process.env.TEST_SLOW_ONLY; -const isFast = argv.fast || process.env.TEST_FAST_ONLY; - -const packages = getPackageInfoSync(); -const testFiles: string[] = []; - -for (const p of packages) { - if (argv.match && !p.name.includes(argv.match)) continue; - - // normalize for Windows - const packagePath = p.path.replace(/\\/g, '/'); - const specGlob: string[] = []; - - if (argv.glob) { - specGlob.push(path.posix.join(packagePath, argv.glob)); - } else { - specGlob.push(path.posix.join(packagePath, 'test', '**', `*_spec${isFast ? '' : isSlow ? '_slow' : '*'}.ts`)); - } - testFiles.push(...glob.sync(specGlob)); -} - -for (const f of testFiles) { - require(f); -}