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

test: refactor fast suite to use vitest #3797

Merged
merged 40 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
2f066f8
i guess this works
erickzhao Nov 30, 2024
f3dd453
remove resolution
erickzhao Dec 18, 2024
40e263a
checkpoint
erickzhao Dec 18, 2024
9af6daf
clean up :)
erickzhao Dec 18, 2024
5fd4661
forgot to push up lockfile
erickzhao Dec 20, 2024
2b86202
resolveDir spec
erickzhao Dec 20, 2024
906d59d
upgrade-forge-config tests
erickzhao Dec 20, 2024
1932774
convert start tests + cleanup
erickzhao Dec 23, 2024
8dc93bd
install-dependencies
erickzhao Jan 2, 2025
b19b131
delete superseded tests
erickzhao Jan 2, 2025
bb323ac
appx tests
erickzhao Jan 2, 2025
6701453
makerbase tests
erickzhao Jan 3, 2025
ebcf814
makerdeb test
erickzhao Jan 3, 2025
bc5d578
makerdmg tests
erickzhao Jan 3, 2025
d51c89b
flatpak and pkg
erickzhao Jan 3, 2025
15a8ca1
rpm tests
erickzhao Jan 6, 2025
0a9bd3b
maker snap
erickzhao Jan 6, 2025
80a3923
wix
erickzhao Jan 6, 2025
42adb6b
maker-zip tests
erickzhao Jan 6, 2025
37becf2
local electron plugin
erickzhao Jan 6, 2025
1d0c4cf
webpack plugin tests
erickzhao Jan 7, 2025
e40fb82
vite tests
erickzhao Jan 7, 2025
c92c316
MSW a few publishers
erickzhao Jan 8, 2025
8ec5baf
publisher github
erickzhao Jan 9, 2025
8c202fd
finish up tests
erickzhao Jan 9, 2025
fcabab3
remove packages
erickzhao Jan 9, 2025
bfe1996
generalize assertion for publish test
erickzhao Jan 9, 2025
327e039
increase test timeout
erickzhao Jan 9, 2025
69882d2
use junit reporter in CI
erickzhao Jan 9, 2025
d9ec6c7
Merge branch 'main' into modern-tests
erickzhao Jan 9, 2025
a83a571
turn down parallelism?
erickzhao Jan 9, 2025
d3ae2e3
fixes :)
erickzhao Jan 9, 2025
f2b1e5b
add xvfb-maybe
erickzhao Jan 9, 2025
f8c0cba
increase timeout again on npm install in asset relocator patch test
erickzhao Jan 9, 2025
0969c3f
debug statement
erickzhao Jan 9, 2025
23f79ec
does this fix it?
erickzhao Jan 9, 2025
1e7af04
fully migrate to jest-like matchers
erickzhao Jan 9, 2025
4e1bdd7
make timeout longer
erickzhao Jan 9, 2025
4618257
increase test timeout again
erickzhao Jan 9, 2025
ed5aa8f
Merge branch 'main' into modern-tests
erickzhao Jan 10, 2025
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
4 changes: 2 additions & 2 deletions .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 Expand Up @@ -114,7 +114,7 @@ jobs:
type: enum
enum: ['x64', 'arm64']
executor: << parameters.executor >>
parallelism: 2
parallelism: 1
erickzhao marked this conversation as resolved.
Show resolved Hide resolved
steps:
- install
- when:
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",
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that Mocha and Chai are still needed for our slow test suite. I'll work on removing those in a follow-up PR.

"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 }, () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

how was 30s determined for this test? I'm wondering if we can revisit this and adjust as necessary

Copy link
Member Author

Choose a reason for hiding this comment

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

I had the default and kept increasing it until it stopped flaking 😓

I think a future task would maybe be if we can move this to the slow test suite as well.

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
Loading