-
Notifications
You must be signed in to change notification settings - Fork 235
Expand file tree
/
Copy pathplugin.acceptance.test.ts
More file actions
executable file
·77 lines (62 loc) · 2.24 KB
/
plugin.acceptance.test.ts
File metadata and controls
executable file
·77 lines (62 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import fs from 'fs-extra'
import path from 'node:path'
import {fileURLToPath} from 'node:url'
import {x} from '../../scripts/utils/script-exec.js'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const plugins = ['@heroku-cli/plugin-applink']
const skipOnWindows = process.platform === 'win32' ? it.skip : it
function resolvePluginPath(plugin: string): null | string {
const candidates = [
path.resolve(__dirname, '../../node_modules', plugin, 'package.json'),
path.resolve(__dirname, '../../../node_modules', plugin, 'package.json'),
]
for (const p of candidates) {
if (fs.existsSync(p)) return path.dirname(p)
}
return null
}
function safeCloneDirName(plugin: string): string {
return plugin.replace('@heroku-cli/', '')
}
describe('plugins', function () {
for (const plugin of plugins) {
const pluginRoot = resolvePluginPath(plugin)
if (!pluginRoot) {
it.skip(plugin, async function () {})
continue
}
skipOnWindows(plugin, async () => {
const cwd = path.resolve(__dirname, '../../tmp/plugin', safeCloneDirName(plugin))
await fs.remove(cwd)
const pkg = await fs.readJSON(path.join(pluginRoot, 'package.json'))
const repo = pkg.repository
if (!repo) {
throw new Error('No repository found')
}
const repoUrl = typeof repo === 'string' ? repo : repo.url
if (!repoUrl) {
throw new Error('No repository URL found in package.json')
}
let cloneUrl: string
if (repoUrl.includes('+')) {
cloneUrl = repoUrl.split('+')[1]
} else if (repoUrl.startsWith('github:')) {
cloneUrl = `https://github.com/${repoUrl.slice(7)}.git`
} else if (repoUrl.startsWith('http://') || repoUrl.startsWith('https://')) {
cloneUrl = repoUrl
} else if (/^[^/]+\/[^/]+$/.test(repoUrl)) {
cloneUrl = `https://github.com/${repoUrl}.git`
} else {
cloneUrl = repoUrl
}
await x('git', ['clone', cloneUrl, cwd])
const opts = {
cwd, stderr: 'inherit', stdin: 'inherit', stdout: 'inherit',
} as const
await x('git', ['checkout', `v${pkg.version}`], opts)
await x('npm', [], opts)
await x('npm', ['test'], opts)
})
}
})