Skip to content

Commit c9710cf

Browse files
authored
chore: migrate e2e to vitest (#5590)
* chore: migrate e2e to vitest Also ensure that tests that do modify the global config do properly backup and restore the whole config folder * chore: migrate telemetry test to vitest
1 parent 3bf1eef commit c9710cf

File tree

12 files changed

+523
-427
lines changed

12 files changed

+523
-427
lines changed

e2e.config.mjs

Lines changed: 0 additions & 11 deletions
This file was deleted.

e2e/install.e2e.mjs

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import { promises, readFileSync, existsSync } from 'fs'
1+
import { readFileSync, existsSync } from 'fs'
2+
import { mkdir } from 'fs/promises'
23
import { platform } from 'os'
34
import { join, resolve } from 'path'
45
import { env } from 'process'
56
import { fileURLToPath } from 'url'
67

7-
import test from 'ava'
88
import execa from 'execa'
9+
import { expect, test } from 'vitest'
910

1011
import { packageManagerConfig, packageManagerExists } from './utils.mjs'
1112

1213
const { version } = JSON.parse(readFileSync(fileURLToPath(new URL('../package.json', import.meta.url)), 'utf-8'))
13-
const { mkdir } = promises
1414

1515
/**
1616
* Prepares the workspace for the test suite to run
@@ -23,28 +23,22 @@ const prepare = async (folderName) => {
2323
}
2424

2525
Object.entries(packageManagerConfig).forEach(([packageManager, { install: installCmd, lockFile }]) => {
26-
/** @type {import('ava').TestInterface} */
27-
const testSuite = packageManagerExists(packageManager) ? test.serial : test.skip
28-
29-
testSuite(`${packageManager} → should install the cli and run the help command`, async (t) => {
30-
const cwd = await prepare(`${packageManager}-try-install`)
31-
await execa(...installCmd, { stdio: env.DEBUG ? 'inherit' : 'ignore', cwd })
32-
33-
t.is(existsSync(join(cwd, lockFile)), true, `Generated lock file ${lockFile} does not exists in ${cwd}`)
34-
35-
const binary = resolve(join(cwd, `./node_modules/.bin/netlify${platform() === 'win32' ? '.cmd' : ''}`))
36-
const { stdout } = await execa(binary, ['help'], { cwd })
37-
38-
t.is(stdout.trim().startsWith('VERSION'), true, `Help command does not start with 'VERSION':\n\n${stdout}`)
39-
t.is(
40-
stdout.includes(`netlify-cli/${version}`),
41-
true,
42-
`Help command does not include 'netlify-cli/${version}':\n\n${stdout}`,
43-
)
44-
t.is(
45-
stdout.includes(`$ netlify [COMMAND]`),
46-
true,
47-
`Help command does not include '$ netlify [COMMAND]':\n\n${stdout}`,
48-
)
49-
})
26+
test.runIf(packageManagerExists(packageManager))(
27+
`${packageManager} → should install the cli and run the help command`,
28+
async () => {
29+
const cwd = await prepare(`${packageManager}-try-install`)
30+
await execa(...installCmd, { stdio: env.DEBUG ? 'inherit' : 'ignore', cwd })
31+
32+
expect(existsSync(join(cwd, lockFile)), `Generated lock file ${lockFile} does not exists in ${cwd}`).toBe(true)
33+
34+
const binary = resolve(join(cwd, `./node_modules/.bin/netlify${platform() === 'win32' ? '.cmd' : ''}`))
35+
const { stdout } = await execa(binary, ['help'], { cwd })
36+
37+
expect(stdout.trim(), `Help command does not start with 'VERSION':\n\n${stdout}`).toMatch(/^VERSION/)
38+
expect(stdout, `Help command does not include 'netlify-cli/${version}':\n\n${stdout}`).toContain(
39+
`netlify-cli/${version}`,
40+
)
41+
expect(stdout, `Help command does not include '$ netlify [COMMAND]':\n\n${stdout}`).toMatch('$ netlify [COMMAND]')
42+
},
43+
)
5044
})

0 commit comments

Comments
 (0)