Skip to content

Commit

Permalink
chore: selftest
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Feb 12, 2024
1 parent d541c20 commit c32c228
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"typecheck": "tsc",
"format": "prettier --ignore-path .gitignore --check .",
"format:fix": "pnpm format --write",
"test:self": "tsx ecosystem-ci.ts _selftest",
"test": "tsx ecosystem-ci.ts"
},
"simple-git-hooks": {
Expand Down
31 changes: 31 additions & 0 deletions tests/_selftest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import path from 'path'
import fs from 'fs'
import { runInRepo } from '../utils.ts'
import type { RunOptions } from '../types.d.ts'

export async function test(options: RunOptions) {
await runInRepo({
...options,
repo: 'volarjs/ecosystem-ci',
branch: 'main',
build: async () => {
const dir = path.resolve(options.workspace, 'ecosystem-ci')
const pkgFile = path.join(dir, 'package.json')
const pkg = JSON.parse(await fs.promises.readFile(pkgFile, 'utf-8'))
if (pkg.name !== 'volar-ecosystem-ci') {
throw new Error(
`invalid checkout, expected package.json with "name":"volar-ecosystem-ci" in ${dir}`,
)
}
pkg.scripts.selftestscript =
"[ -f ../../volar/packages/language-core/index.js ] || (echo 'volar build failed' && exit 1)"
await fs.promises.writeFile(
pkgFile,
JSON.stringify(pkg, null, 2),
'utf-8',
)
},
test: 'pnpm run selftestscript',
verify: false,
})
}
2 changes: 1 addition & 1 deletion tests/mdx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export async function test(options: RunOptions) {
agent: 'npm',
repo: 'mdx-js/mdx-analyzer',
branch: 'main',
test: 'test',
test: 'test-api',
})
}
2 changes: 1 addition & 1 deletion types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export interface CommandOptions {

export interface RepoOptions {
repo: string
branch: string
dir?: string
branch?: string
tag?: string
commit?: string
shallow?: boolean
Expand Down
6 changes: 0 additions & 6 deletions utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ function initWorkspace(workspace: string) {
}

export async function setupRepo(options: RepoOptions) {
if (options.branch == null) {
options.branch = 'master'
}
if (options.shallow == null) {
options.shallow = true
}
Expand Down Expand Up @@ -196,9 +193,6 @@ export async function runInRepo(options: RunOptions & RepoOptions) {
if (options.skipGit == null) {
options.skipGit = false
}
if (options.branch == null) {
options.branch = 'master'
}

const {
build,
Expand Down

0 comments on commit c32c228

Please sign in to comment.