Skip to content

Commit

Permalink
test: refactor fast suite to use vitest (#3797)
Browse files Browse the repository at this point in the history
* i guess this works

* remove resolution

* checkpoint

* clean up :)

* forgot to push up lockfile

* resolveDir spec

* upgrade-forge-config tests

* convert start tests + cleanup

* install-dependencies

* delete superseded tests

* appx tests

* makerbase tests

* makerdeb test

* makerdmg tests

* flatpak and pkg

* rpm tests

* maker snap

* wix

* maker-zip tests

* local electron plugin

* webpack plugin tests

* vite tests

* MSW a few publishers

* publisher github

* finish up tests

* remove packages

* generalize assertion for publish test

* increase test timeout

* use junit reporter in CI

* turn down parallelism?

* fixes :)

* add xvfb-maybe

* increase timeout again on npm install in asset relocator patch test

* debug statement

* does this fix it?

* fully migrate to jest-like matchers

* make timeout longer

* increase test timeout again
  • Loading branch information
erickzhao authored Jan 10, 2025
1 parent 570a429 commit 8dd2f13
Show file tree
Hide file tree
Showing 123 changed files with 4,742 additions and 3,766 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ commands:
- run:
name: 'Run fast tests'
command: |
yarn test:fast
yarn test:fast --reporter=junit --outputFile="./reports/out/test_output.xml"
run-slow-tests:
steps:
Expand Down
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ packages/*/*/index.ts
packages/**/bad.js
tmpl
packages/api/core/helper/dynamic-import.js
packages/plugin/webpack/spec/fixtures/**/*
12 changes: 3 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"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": "npm run test -- --suite=fast",
"test:fast": "xvfb-maybe vitest run",
"test:slow": "npm run test -- --suite=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",
Expand Down Expand Up @@ -91,7 +91,6 @@
"@types/debug": "^4.1.5",
"@types/express": "^4.17.9",
"@types/express-ws": "^3.0.0",
"@types/fetch-mock": "^7.3.1",
"@types/fs-extra": "^9.0.6",
"@types/interpret": "^1.1.1",
"@types/keyv": "^3.1.4",
Expand All @@ -102,11 +101,8 @@
"@types/mocha": "^9.0.0",
"@types/node": "^18.0.3",
"@types/node-fetch": "^2.5.5",
"@types/proxyquire": "^1.3.28",
"@types/rechoir": "^0.6.1",
"@types/semver": "^7.3.4",
"@types/sinon": "^10.0.0",
"@types/sinon-chai": "^3.2.5",
"@types/which": "^2.0.0",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
Expand All @@ -121,7 +117,6 @@
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-tsdoc": "^0.2.14",
"fetch-mock": "^9.10.7",
"fork-ts-checker-webpack-plugin": "^7.2.13",
"generate-changelog": "^1.8.0",
"husky": "^7.0.1",
Expand All @@ -131,15 +126,14 @@
"minimist": "^1.2.6",
"mocha": "^9.0.1",
"mocha-junit-reporter": "^2.2.1",
"msw": "^2.7.0",
"prettier": "^2.4.0",
"proxyquire": "^2.1.3",
"rimraf": "^3.0.1",
"sinon": "^13.0.1",
"sinon-chai": "^3.6.0",
"syncpack": "^11.2.1",
"ts-node": "^10.0.0",
"typedoc": "0.25.13",
"typescript": "^4.6.3",
"vitest": "^2.1.6",
"xvfb-maybe": "^0.2.1",
"yaml-hook": "^1.0.0"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/api/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"@malept/cross-spawn-promise": "^2.0.0",
"chai": "^4.3.3",
"chai-as-promised": "^7.0.0",
"mocha": "^9.0.1"
"mocha": "^9.0.1",
"vitest": "^2.1.6"
},
"dependencies": {
"@electron-forge/core": "7.6.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { expect } from 'chai';
import { describe, expect, it } from 'vitest';

import { checkValidPackageManagerVersion } from '../src/util/check-system';

describe('check-system', () => {
describe('validPackageManagerVersion', () => {
it('should consider whitelisted versions to be valid', () => {
expect(() => checkValidPackageManagerVersion('NPM', '3.10.1', '^3.0.0')).to.not.throw();
expect(() => checkValidPackageManagerVersion('NPM', '3.10.1', '^3.0.0')).not.toThrow();
});

it('should consider Yarn nightly versions to be invalid', () => {
expect(() => checkValidPackageManagerVersion('Yarn', '0.23.0-20170311.0515', '0.23.0')).to.throw();
expect(() => checkValidPackageManagerVersion('Yarn', '0.23.0-20170311.0515', '0.23.0')).toThrow();
});

it('should consider invalid semver versions to be invalid', () => {
expect(() => checkValidPackageManagerVersion('Yarn', '0.22', '0.22.0')).to.throw();
expect(() => checkValidPackageManagerVersion('Yarn', '0.22', '0.22.0')).toThrow();
});
});
});
19 changes: 19 additions & 0 deletions packages/api/cli/spec/cli.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import path from 'node:path';

import { spawn } from '@malept/cross-spawn-promise';
import { describe, expect, it } from 'vitest';

function runForgeCLI(...extraArgs: string[]): Promise<string> {
const args = ['ts-node', path.resolve(__dirname, '../src/electron-forge.ts'), ...extraArgs];
return spawn('npx', args);
}

describe('cli', { timeout: 30_000 }, () => {
it('should not fail on known subcommands', async () => {
await expect(runForgeCLI('help')).resolves.toMatch(/Usage:/);
});

it('should fail on unknown subcommands', async () => {
await expect(runForgeCLI('nonexistent')).rejects.toThrow(Error);
});
});
30 changes: 0 additions & 30 deletions packages/api/cli/test/cli_spec.ts

This file was deleted.

5 changes: 1 addition & 4 deletions packages/api/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@
"chai-as-promised": "^7.0.0",
"cross-env": "^7.0.2",
"electron-installer-common": "^0.10.2",
"fetch-mock": "^9.10.7",
"mocha": "^9.0.1",
"proxyquire": "^2.1.3",
"sinon": "^13.0.1",
"sinon-chai": "^3.6.0",
"vitest": "^2.1.6",
"yaml-hook": "^1.0.0"
},
"dependencies": {
Expand Down
87 changes: 87 additions & 0 deletions packages/api/core/spec/fast/make.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/* eslint-disable node/no-unsupported-features/es-syntax */
import * as path from 'node:path';

import { describe, expect, it, vi } from 'vitest';

import make from '../../src/api/make';

vi.mock(import('@electron-forge/core-utils'), async (importOriginal) => {
const mod = await importOriginal();
return {
...mod,
getElectronVersion: vi.fn().mockResolvedValue('1.0.0'),
};
});

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

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

it('works with @scoped package names', { timeout: 10_000 }, async () => {
const result = await make({
arch: 'x64',
dir: path.join(fixtureDir, 'app-with-scoped-name'),
platform: 'linux',
skipPackage: true,
});
expect(result).toHaveLength(1);
expect(result[0].artifacts).toEqual([expect.stringContaining('@scope-package-linux-x64-1.0.0.zip')]);
});

it('can override targets', async () => {
const results = await make({
arch: 'x64',
dir: path.join(fixtureDir, 'app-with-custom-maker-config'),
overrideTargets: ['../custom-maker'],
platform: 'linux',
skipPackage: true,
});

expect(results[0].artifacts).toEqual(['from config']);
});

it('throws an error if the name is not a string', async () => {
await expect(
make({
arch: 'x64',
dir: path.join(fixtureDir, 'maker-name-wrong-type'),
platform: 'linux',
skipPackage: true,
})
).rejects.toThrowError(/^The following maker config has a maker name that is not a string:/);
});

it('throws an error if the name is missing', async () => {
await expect(
make({
arch: 'x64',
dir: path.join(fixtureDir, 'maker-sans-name'),
platform: 'linux',
skipPackage: true,
})
).rejects.toThrowError(/^The following maker config is missing a maker name:/);
});

it('can skip makers via config', async () => {
await expect(
make({
arch: 'x64',
dir: path.join(fixtureDir, 'app-with-maker-disable'),
platform: 'linux',
skipPackage: true,
})
).rejects.toThrowError(/Could not find any make targets configured for the "linux" platform./);
});

it('throws if maker cannot be resolved', async () => {
const opts = {
arch: 'x64',
dir: path.join(fixtureDir, 'app-with-custom-maker-config'),
platform: 'linux',
skipPackage: true,
};

await expect(make(opts)).rejects.toThrowError("Could not find module with name '@electron-forge/non-existent-forge-maker'");
});
});
Loading

0 comments on commit 8dd2f13

Please sign in to comment.