-
-
Notifications
You must be signed in to change notification settings - Fork 549
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
Changes from all commits
2f066f8
f3dd453
40e263a
9af6daf
5fd4661
2b86202
906d59d
1932774
8dc93bd
b19b131
bb323ac
6701453
ebcf814
bc5d578
d51c89b
15a8ca1
0a9bd3b
80a3923
42adb6b
37becf2
1d0c4cf
e40fb82
c92c316
8ec5baf
8c202fd
fcabab3
bfe1996
327e039
69882d2
d9ec6c7
a83a571
d3ae2e3
f2b1e5b
f8c0cba
0969c3f
23f79ec
1e7af04
4e1bdd7
4618257
ed5aa8f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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(); | ||
}); | ||
}); | ||
}); |
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 }, () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
}); | ||
}); |
This file was deleted.
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'"); | ||
}); | ||
}); |
There was a problem hiding this comment.
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.