Skip to content

Commit

Permalink
test: migrate slow tests to use vitest (#3802)
Browse files Browse the repository at this point in the history
* api slow tests to vitest

* finish converting tests, remove all references to mocha

* fix test dir

* more fixture path changes

* fixups

* separate fast and slow configs

* update to jest matchers

* eslint + fuses test fix

* remove files from eslintignore

* remove my todo :)

* build, THEN lint?

* cleanup

* adjust test speeds

* update gitignore

* gitignore update?

* add fixtures back by force

* add fixtures back by force more

* delete

* disable parallelism on fast tests too

* move stuff around

* increase hook timer

* Update .vscode/extensions.json

Co-authored-by: David Sanders <[email protected]>

* remove `cross-env` as dep

---------

Co-authored-by: David Sanders <[email protected]>
  • Loading branch information
erickzhao and dsanders11 authored Jan 20, 2025
1 parent 6dc5fe3 commit f86bd46
Show file tree
Hide file tree
Showing 144 changed files with 456 additions and 896 deletions.
14 changes: 6 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ commands:
steps:
- run: git config --global core.autocrlf input
- node/install:
node-version: '18.20.3'
node-version: 20.17.0
- checkout
run-lint-and-build:
steps:
- node/install-packages
- run:
name: 'Build Electron Forge'
command: |
yarn build
- run:
name: 'Lint codebase'
command: |
yarn lint
yarn syncpack
- run:
name: 'Build Electron Forge'
command: |
yarn build
run-fast-tests:
steps:
- node/install-packages:
Expand All @@ -48,9 +48,7 @@ commands:
- run:
name: 'Run slow tests'
command: |
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
yarn test:slow --reporter=junit --outputFile="./reports/out/test_output.xml"
jobs:
lint-and-build:
Expand Down
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ packages/*/*/index.ts
packages/**/bad.js
tmpl
packages/api/core/helper/dynamic-import.js
packages/plugin/webpack/spec/fixtures/**/*
13 changes: 4 additions & 9 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{
"plugins": ["mocha", "import"],
"env": {
"mocha": true
},
"extends": ["@malept/eslint-config/src/common"],
"globals": {
"NodeJS": "readonly"
Expand All @@ -17,7 +13,6 @@
"vars": "all"
}
],
"mocha/no-exclusive-tests": "error",
"import/order": [
"error",
{
Expand Down Expand Up @@ -69,7 +64,7 @@
}
},
{
"files": ["packages/*/*/test/**/*_spec*.ts", "packages/*/*/test/fixture/**/*.ts"],
"files": ["packages/*/*/spec/**/*.spec.ts", "packages/*/*/spec/fixture/**/*.ts"],
"rules": {
"global-require": "off",
"import/no-dynamic-require": "off",
Expand All @@ -93,21 +88,21 @@
}
},
{
"files": ["packages/api/core/test/**/*.ts", "packages/maker/*/src/Maker*.ts"],
"files": ["packages/api/core/spec/**/*.ts", "packages/maker/*/src/Maker*.ts"],
"rules": {
"@typescript-eslint/no-require-imports": "off"
}
},
{
"files": ["packages/*/*/test/fixture/**/*.js", "packages/*/*/test/fixtures/**/*.js"],
"files": ["packages/*/*/spec/fixture/**/*.js", "packages/*/*/spec/fixtures/**/*.js"],
"rules": {
"node/no-extraneous-require": "off",
"node/no-missing-require": "off",
"node/no-unpublished-require": "off"
}
},
{
"files": ["packages/plugin/webpack/test/fixtures/**/*.js"],
"files": ["packages/plugin/webpack/spec/fixtures/**/*.js"],
"rules": {
"no-process-exit": "off",
"no-undef": "off",
Expand Down
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ packages/api/cli/README.md
packages/**/tsconfig.tsbuildinfo
packages/**/.swc
.webpack
packages/api/core/test/fixture/app-with-scoped-name/out/make
packages/plugin/webpack/test/fixtures/apps/native-modules/package-lock.json
packages/plugin/fuses/test/fixture/app
packages/api/core/spec/fixture/app-with-scoped-name/out/make
packages/plugin/webpack/spec/fixtures/apps/native-modules/package-lock.json
packages/plugin/fuses/spec/fixture/app
.links
reports
packages/**/typedoc.json
47 changes: 0 additions & 47 deletions .mocharc.js

This file was deleted.

2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ packages/*/*/index.ts
packages/*/*/README.md
packages/*/*/tsconfig.json
packages/*/*/typedoc.json
packages/api/core/test/fixture/bad_external_forge_config/bad.js
packages/api/core/spec/fixture/bad_external_forge_config/bad.js
packages/plugin/webpack/spec/**/.webpack
.links
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode", "maty.vscode-mocha-sidebar"]
"recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode", "vitest.explorer"]
}
12 changes: 0 additions & 12 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,5 @@
"source.fixAll.eslint": "explicit"
},
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"mocha.env": {
"TS_NODE_PROJECT": "tsconfig.test.json",
"TS_NODE_FILES": "1",
"TEST_FAST_ONLY": "1"
},
"mocha.files.glob": "packages/*/*/test/**/*_spec*.ts",
"mocha.requires": ["ts-node/register", "tools/test-setup.ts"],
"mocha.options": {
"extension": ["ts"],
"timeout": 800000,
"recursive": true
}
}
15 changes: 3 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
"lint:fix": "prettier --write . && eslint --fix .",
"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": "npm run test:clear && xvfb-maybe cross-env NODE_ENV=test TS_NODE_PROJECT='./tsconfig.test.json' TS_NODE_FILES=1 mocha",
"test:fast": "xvfb-maybe vitest run",
"test:slow": "npm run test -- --suite=slow",
"test": "xvfb-maybe vitest run --project fast --project slow",
"test:fast": "xvfb-maybe vitest run --project fast",
"test:slow": "xvfb-maybe vitest run --project slow",
"test:clear": "ts-node tools/test-clear",
"postinstall": "rimraf node_modules/.bin/*.ps1 && ts-node ./tools/gen-tsconfigs.ts && ts-node ./tools/gen-ts-glue.ts",
"prepare": "husky install",
Expand Down Expand Up @@ -85,8 +85,6 @@
"@electron/fuses": ">=1.0.0",
"@electron/lint-roller": "1.10.1",
"@malept/eslint-config": "^2.0.0",
"@types/chai": "^4.2.12",
"@types/chai-as-promised": "^7.1.2",
"@types/cross-spawn": "^6.0.1",
"@types/debug": "^4.1.5",
"@types/express": "^4.17.9",
Expand All @@ -98,21 +96,16 @@
"@types/lodash": "^4.14.166",
"@types/mime-types": "^2.1.0",
"@types/minimist": "^1.2.0",
"@types/mocha": "^9.0.0",
"@types/node": "^18.0.3",
"@types/node-fetch": "^2.5.5",
"@types/rechoir": "^0.6.1",
"@types/semver": "^7.3.4",
"@types/which": "^2.0.0",
"@typescript-eslint/eslint-plugin": "^8.0.0",
"@typescript-eslint/parser": "^8.0.0",
"chai": "^4.3.3",
"chai-as-promised": "^7.0.0",
"cross-env": "^7.0.2",
"electron-installer-common": "^0.10.2",
"eslint": "^8.56.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-mocha": "^9.0.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-promise": "^6.0.0",
Expand All @@ -124,8 +117,6 @@
"lerna": "^7.4.2",
"lint-staged": "^12.1.7",
"minimist": "^1.2.6",
"mocha": "^9.0.1",
"mocha-junit-reporter": "^2.2.1",
"msw": "^2.7.0",
"prettier": "^2.4.0",
"rimraf": "^3.0.1",
Expand Down
3 changes: 0 additions & 3 deletions packages/api/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
},
"devDependencies": {
"@malept/cross-spawn-promise": "^2.0.0",
"chai": "^4.3.3",
"chai-as-promised": "^7.0.0",
"mocha": "^9.0.1",
"vitest": "^2.1.6"
},
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function runForgeCLI(...extraArgs: string[]): Promise<string> {
return spawn('npx', args);
}

describe('cli', { timeout: 30_000 }, () => {
describe('cli', () => {
it('should not fail on known subcommands', async () => {
await expect(runForgeCLI('help')).resolves.toMatch(/Usage:/);
});
Expand Down
10 changes: 0 additions & 10 deletions packages/api/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@
"typings": "dist/api/index.d.ts",
"author": "Samuel Attard",
"license": "MIT",
"scripts": {
"coverage:base": "nyc yarn test:base",
"test": "yarn test:base test/**/*_spec.ts test/**/*_spec_slow.ts",
"test:base": "cross-env TS_NODE_FILES=1 mocha --config ../../../.mocharc.js",
"test:fast": "yarn test:base test/fast/**/*_spec.ts",
"test:slow": "yarn test:base test/slow/**/*_spec_slow.ts"
},
"devDependencies": {
"@electron-forge/maker-appx": "7.6.0",
"@electron-forge/maker-deb": "7.6.0",
Expand All @@ -28,11 +21,8 @@
"@types/interpret": "^1.1.1",
"@types/progress": "^2.0.5",
"@types/rechoir": "^0.6.1",
"chai": "^4.3.3",
"chai-as-promised": "^7.0.0",
"cross-env": "^7.0.2",
"electron-installer-common": "^0.10.2",
"mocha": "^9.0.1",
"vitest": "^2.1.6",
"yaml-hook": "^1.0.0"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"env": {
"mocha": true
},
"rules": {
"class-methods-use-this": 0,
"import/no-extraneous-dependencies": 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { execSync } from 'node:child_process';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';

import { expect } from 'chai';
import fs from 'fs-extra';
import { beforeEach, describe, expect, it } from 'vitest';

import { initGit } from '../../src/api/init-scripts/init-git';

Expand All @@ -13,56 +13,56 @@ let dirID = Date.now();
const ensureTestDirIsNonexistent = async () => {
dir = path.resolve(os.tmpdir(), `electron-forge-git-test-${dirID}`);
dirID += 1;
await fs.remove(dir);
await fs.promises.rm(dir, { recursive: true, force: true });
};

describe('init-git', () => {
beforeEach(async () => {
await ensureTestDirIsNonexistent();
await fs.mkdir(dir);
await fs.promises.mkdir(dir, { recursive: true });
});

it('creates Git repository when run inside non-Git directory', async () => {
await initGit(dir);
const gitDir = path.join(dir, '.git');
expect(await fs.pathExists(gitDir), 'the .git directory inside the folder').to.equal(true);
expect(fs.existsSync(gitDir), 'the .git directory inside the folder').toEqual(true);
});

it('skips when run at root of Git repository', async () => {
await execSync('git init', { cwd: dir });
execSync('git init', { cwd: dir });

const gitDir = path.join(dir, '.git');
const config = path.join(gitDir, 'config');
const statBefore = await fs.lstat(config);
const statBefore = await fs.promises.lstat(config);
const before = statBefore.mtimeMs;

await initGit(dir);

const statAfter = await fs.lstat(config);
const statAfter = await fs.promises.lstat(config);
const after = statAfter.mtimeMs;

expect(after, 'the config file in the repository').to.equal(before);
expect(after, 'the config file in the repository').toEqual(before);
});

it('skips when run in subdirectory of Git repository', async () => {
await execSync('git init', { cwd: dir });
execSync('git init', { cwd: dir });

const gitDir = path.join(dir, '.git');
const config = path.join(gitDir, 'config');
const statBefore = await fs.lstat(config);
const statBefore = await fs.promises.lstat(config);
const before = statBefore.mtimeMs;

const subdir = path.join(dir, 'some', 'other', 'folder');
const innerGitDir = path.join(subdir, '.git');

await fs.mkdirp(subdir);
await fs.promises.mkdir(subdir, { recursive: true });

await initGit(subdir);

const statAfter = await fs.lstat(config);
const statAfter = await fs.promises.lstat(config);
const after = statAfter.mtimeMs;

expect(after, 'the config file in the repository').to.equal(before);
expect(await fs.pathExists(innerGitDir), 'a nested .git directory inside the repository').to.equal(false);
expect(after, 'the config file in the repository').toEqual(before);
expect(fs.existsSync(innerGitDir), 'a nested .git directory inside the repository').toEqual(false);
});
});
2 changes: 1 addition & 1 deletion packages/api/core/spec/fast/make.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ vi.mock(import('@electron-forge/core-utils'), async (importOriginal) => {
});

describe('make', () => {
const fixtureDir = path.resolve(__dirname, '../../test/fixture');
const fixtureDir = path.resolve(__dirname, '../fixture');

it.todo('should call "package"');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { describe, expect, it } from 'vitest';

import locateElectronExecutable from '../../../src/util/electron-executable';

const fixtureDir = path.resolve(__dirname, '..', '..', '..', 'test', 'fixture', 'electron-executable');
const fixtureDir = path.resolve(__dirname, '..', '..', 'fixture', 'electron-executable');

describe('locateElectronExecutable', () => {
it('returns the correct path to electron', async () => {
Expand Down
Loading

0 comments on commit f86bd46

Please sign in to comment.