Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for pear dump
Browse files Browse the repository at this point in the history
jkcdarunday committed Aug 8, 2024

Verified

This commit was signed with the committer’s verified signature.
jkcdarunday Jan Keith Darunday
1 parent c838358 commit 64f02a2
Showing 2 changed files with 452 additions and 6 deletions.
456 changes: 451 additions & 5 deletions test/05-commands.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const test = require('brittle')
const path = require('bare-path')
const Helper = require('./helper')
const fs = require('bare-fs')

const harness = path.join(Helper.root, 'test', 'fixtures', 'harness')
const minimal = path.join(Helper.root, 'test', 'fixtures', 'minimal')
@@ -16,20 +17,78 @@ class Rig {
comment('local sidecar connected')
}

getOrCreateDumpInstance = async () => {
if (this.pearDumpInstance) return this.pearDumpInstance

const testId = Math.floor(Math.random() * 100000)
const argvStage = ['stage', '--json', 'test-' + testId, minimal]
const stager1 = await Helper.open(harness, { tags: ['exit'] }, { lineout: true })
await stager1.inspector.evaluate(`
__PEAR_TEST__.command(${JSON.stringify(argvStage)})
`, { returnByValue: false })

for await (const line of stager1.lineout) {
const result = JSON.parse(line)
if (result.tag === 'addendum') this.pearDumpInstance = result.data
if (result.tag === 'final') break
}

await stager1.inspector.evaluate('__PEAR_TEST__.ipc.destroy()', { returnByValue: false })
await stager1.inspector.close()
await stager1.until.exit

const argvRelease = ['release', '--json', 'test-' + testId, minimal]
const releaser1 = await Helper.open(harness, { tags: ['exit'] }, { lineout: true })
await releaser1.inspector.evaluate(`
__PEAR_TEST__.command(${JSON.stringify(argvRelease)})
`, { returnByValue: false })

for await (const line of releaser1.lineout) {
const result = JSON.parse(line)
if (result.tag === 'final') break
}

await releaser1.inspector.evaluate('__PEAR_TEST__.ipc.destroy()', { returnByValue: false })
await releaser1.inspector.close()
await releaser1.until.exit

fs.writeFileSync(path.join(minimal, 'testfile.txt'), 'this is a test file')

const stager2 = await Helper.open(harness, { tags: ['exit'] }, { lineout: true })
await stager2.inspector.evaluate(`
__PEAR_TEST__.command(${JSON.stringify(argvStage)})
`, { returnByValue: false })

for await (const line of stager2.lineout) {
const result = JSON.parse(line)
if (result.tag === 'addendum') {
this.pearDumpInstance.versionOld = this.pearDumpInstance.version
this.pearDumpInstance.version = result.data.version
}
if (result.tag === 'final') break
}

await stager2.inspector.evaluate('__PEAR_TEST__.ipc.destroy()', { returnByValue: false })
await stager2.inspector.close()
await stager2.until.exit

fs.unlinkSync(path.join(minimal, 'testfile.txt'))

return this.pearDumpInstance
}

cleanup = async ({ comment }) => {
comment('shutting down local sidecar')
setTimeout(async () => {
await this.helper.shutdown()
comment('local sidecar shut down')
}, 5000)
await this.helper.shutdown()
comment('local sidecar shut down')
}
}

const rig = new Rig()

test('commands setup', rig.setup)

test('pear stage --json <channel> <dir>', async function ({ plan, alike, is }) {
test('pear stage --json <channel> <absolute-path>', async function ({ plan, alike, is }) {
plan(2)

const testId = Math.floor(Math.random() * 100000)
@@ -58,4 +117,391 @@ test('pear stage --json <channel> <dir>', async function ({ plan, alike, is }) {
is(code, 0)
})

test.todo('pear stage <channel> <absolute-path>')
test.todo('pear stage <channel> <relative-path>')
test.todo('pear stage <channel> <relative-path> (package.json pear.config.stage.entrypoints <relative-paths>)')
test.todo('pear stage <channel> <relative-path> (package.json pear.config.stage.ignore <relative-paths>)')
test.todo('pear stage --json <channel> <relative-path>')
test.todo('pear stage --dry-run <channel> <relative-path>')
test.todo('pear stage --dry-run --json <channel> <relative-path>')
test.todo('pear stage --bare <channel> <relative-path>')
test.todo('pear stage --bare --json <channel> <relative-path>')
test.todo('pear stage --ignore <list> <channel> <relative-path>')
test.todo('pear stage --ignore <list> --json <channel> <relative-path>')
test.todo('pear stage --truncate <n> <channel> <relative-path>')
test.todo('pear stage --truncate <n> --json <channel> <relative-path>')
test.todo('pear stage --name <name> <channel> <relative-path>')
test.todo('pear stage --name <name> --json <channel> <relative-path>')
test.todo('pear stage --ignore <list> --name <name> <channel> <relative-path>')
test.todo('pear stage --ignore <list> --name <name> --json <channel> <relative-path>')
test.todo('pear stage --dry-run --bare --ignore <list> --truncate <n> --name <name> <channel> <relative-path>')
test.todo('pear stage --dry-run --bare --ignore <list> --truncate <n> --name <name> --json <channel> <relative-path>')
test.todo('pear stage pear://<key>')
test.todo('pear stage --json pear://<key>')
test.todo('pear stage --dry-run pear://<key>')
test.todo('pear stage --dry-run --json pear://<key>')
test.todo('pear stage --bare pear://<key>')
test.todo('pear stage --bare --json pear://<key>')
test.todo('pear stage --ignore <list> pear://<key>')
test.todo('pear stage --ignore <list> --json pear://<key>')
test.todo('pear stage --truncate <n> pear://<key>')
test.todo('pear stage --truncate <n> --json pear://<key>')
test.todo('pear stage --name <name> pear://<key>')
test.todo('pear stage --name <name> --json pear://<key>')
test.todo('pear stage --ignore <list> --name <name> pear://<key>')
test.todo('pear stage --ignore <list> --name <name> --json pear://<key>')
test.todo('pear stage --dry-run --bare --ignore <list> --truncate <n> --name <name> pear://<key>')
test.todo('pear stage --dry-run --bare --ignore <list> --truncate <n> --name <name> --json pear://<key>')

test.todo('pear seed <channel> <absolute-path>')
test.todo('pear seed <channel> <relative-path>')
test.todo('pear seed --json <channel> <relative-path>')
test.todo('pear seed --seeders <key> <channel> <relative-path>')
test.todo('pear seed --seeders <key> --json <channel> <relative-path>')
test.todo('pear seed --name <name> <channel> <relative-path>')
test.todo('pear seed --name <name> --json <channel> <relative-path>')
test.todo('pear seed pear://<key>')
test.todo('pear seed --json pear://<key>')
test.todo('pear seed --seeders <key> pear://<key>')
test.todo('pear seed --seeders <key> --json pear://<key>')
test.todo('pear seed --name <name> pear://<key>')
test.todo('pear seed --name <name> --json pear://<key>')

test.todo('pear run <absolute-path>')
test.todo('pear run <relative-path>')
test.todo('pear run <relative-path> --tmp-store')
test.todo('pear run <relative-path> --store <relative-path>')
test.todo('pear run <relative-path> --store <absolute-path>')
test.todo('pear run <relative-path> --unsafe-clear-app-storage')
test.todo('pear run <relative-path> --unsafe-clear-preferences')
test.todo('pear run file:///<absolute-path>')
test.todo('pear run pear://<key>')
test.todo('pear run pear://<key>/<entrypoint>')
test.todo('pear run pear://<key> --store <path>')
test.todo('pear run pear://<key> --tmp-store')
test.todo('pear run pear://<key> --unsafe-clear-app-storage')
test.todo('pear run pear://<key> --unsafe-clear-preferences')

test.todo('pear run <relative-path> (package.json pear.config.previewFor <key>)')
test.todo('pear run <relative-path> (package.json pear.config.links <keys>)')
test.todo('pear run <relative-path> (package.json pear.config.links <hosts>)')
test.todo('pear run <relative-path> (package.json pear.config.type <terminal | desktop>)')
test.todo('pear run <relative-path> --updates-diff')
test.todo('pear run <relative-path> --no-updates')
test.todo('pear run <relative-path> --link <url>')
test.todo('pear run <relative-path> --updates-diff --no-updates') // TODO: after task Paparam flag relationships
test.todo('pear run <relative-path> --tmp-store --store <path>') // TODO: after task Paparam flag relationships
test.todo('pear run pear://<key> --updates-diff')
test.todo('pear run pear://<key> --no-updates')
test.todo('pear run pear://<key> --link <url>')
test.todo('pear run pear://<key> --checkout <n>')
test.todo('pear run pear://<key> --checkout release')
test.todo('pear run pear://<key> --checkout staged')
test.todo('pear run pear://<key> --checkout <n> --unsafe-clear-app-storage --unsafe-clear-preferences')

test.todo('pear release <channel> <absolute-path>')
test.todo('pear release <channel> <relative-path>')
test.todo('pear release --json <channel> <relative-path>')
test.todo('pear release pear://<key>')
test.todo('pear release --json pear://<key>')
test.todo('pear release --checkout <n> pear://<key>')
test.todo('pear release --checkout <n> --json pear://<key>')
test.todo('pear release --checkout staged pear://<key>')
test.todo('pear release --checkout staged --json pear://<key>')
test.todo('pear release --checkout release pear://<key>')
test.todo('pear release --checkout release --json pear://<key>')

test.todo('pear info')
test.todo('pear info --json')
test.todo('pear info <channel> <relative-path>')
test.todo('pear info --json <channel> <relative-path>')
test.todo('pear info --changelog <channel> <relative-path>')
test.todo('pear info --changelog --json <channel> <relative-path>')
test.todo('pear info --changelog --metadata <channel> <relative-path>')
test.todo('pear info --changelog --metadata --json <channel> <relative-path>')
test.todo('pear info --changelog --key <key> <channel> <relative-path>')
test.todo('pear info --changelog --key <key> --json <channel> <relative-path>')
test.todo('pear info --changelog --metadata --key <channel> <relative-path>')
test.todo('pear info --changelog --metadata --key --json <channel> <relative-path>')
test.todo('pear info --full-changelog <channel> <relative-path>')
test.todo('pear info --full-changelog --metadata <channel> <relative-path>')
test.todo('pear info --full-changelog --metadata --json <channel> <relative-path>')
test.todo('pear info --full-changelog --metadata --key <channel> <relative-path>')
test.todo('pear info --full-changelog --metadata --key --json <channel> <relative-path>')
test.todo('pear info --full-changelog --changelog') // TODO: after task Paparam flag relationships
test.todo('pear info --metadata <channel> <relative-path>')
test.todo('pear info --metadata --key <channel> <relative-path>')
test.todo('pear info --metadata --key --json <channel> <relative-path>')
test.todo('pear info --key <channel> <relative-path>')
test.todo('pear info --key --json <channel> <relative-path>')
test.todo('pear info pear://<key>')
test.todo('pear info --json pear://<key>')
test.todo('pear info --changelog pear://<key>')
test.todo('pear info --changelog --json pear://<key>')
test.todo('pear info --changelog --metadata pear://<key>')
test.todo('pear info --changelog --metadata --json pear://<key>')
test.todo('pear info --changelog --key pear://<key>')
test.todo('pear info --changelog --key --json pear://<key>')
test.todo('pear info --changelog --metadata --key pear://<key>')
test.todo('pear info --changelog --metadata --key --json pear://<key>')
test.todo('pear info --full-changelog pear://<key>')
test.todo('pear info --full-changelog --metadata pear://<key>')
test.todo('pear info --full-changelog --metadata --json pear://<key>')
test.todo('pear info --full-changelog --metadata --key pear://<key>')
test.todo('pear info --full-changelog --metadata --key --json pear://<key>')
test.todo('pear info --metadata pear://<key>')
test.todo('pear info --metadata --key pear://<key>')
test.todo('pear info --metadata --key --json pear://<key>')
test.todo('pear info --key pear://<key>')
test.todo('pear info --key --json pear://<key>')

test.todo('pear info --no-changelog <channel> <relative-path>')
test.todo('pear info --no-changelog --json <channel> <relative-path>')
test.todo('pear info --no-metadata <channel> <relative-path>')
test.todo('pear info --no-metadata --json <channel> <relative-path>')
test.todo('pear info --no-key <channel> <relative-path>')
test.todo('pear info --no-key --json <channel> <relative-path>')
test.todo('pear info --no-changelog --no-metadata <channel> <relative-path>')
test.todo('pear info --no-changelog --no-metadata --json <channel> <relative-path>')
test.todo('pear info --no-changelog --no-key <channel> <relative-path>')
test.todo('pear info --no-changelog --no-key --json <channel> <relative-path>')
test.todo('pear info --no-key --no-metadata <channel> <relative-path>')
test.todo('pear info --no-key --no-metadata --json <channel> <relative-path>')
test.todo('pear info --no-changelog --no-metadata --no-key <channel> <relative-path>')
test.todo('pear info --no-changelog --no-metadata --no-key --json <channel> <relative-path>')
test.todo('pear info --no-changelog pear://<key>')
test.todo('pear info --no-changelog --json pear://<key>')
test.todo('pear info --no-metadata pear://<key>')
test.todo('pear info --no-metadata --json pear://<key>')
test.todo('pear info --no-key pear://<key>')
test.todo('pear info --no-key --json pear://<key>')
test.todo('pear info --no-changelog --no-metadata pear://<key>')
test.todo('pear info --no-changelog --no-metadata --json pear://<key>')
test.todo('pear info --no-changelog --no-key pear://<key>')
test.todo('pear info --no-changelog --no-key --json pear://<key>')
test.todo('pear info --no-key --no-metadata pear://<key>')
test.todo('pear info --no-key --no-metadata --json pear://<key>')
test.todo('pear info --no-changelog --no-metadata --no-key pear://<key>')
test.todo('pear info --no-changelog --no-metadata --no-key --json pear://<key>')

test('pear dump pear://<key> <absolute-path>', async function ({ plan, is, teardown }) {
plan(5)
const { link } = await rig.getOrCreateDumpInstance()

const testId = Math.floor(Math.random() * 100000)
const targetDir = path.join(harness, `pear-dump-${testId}`)
teardown(async () => fs.promises.rm(targetDir, { recursive: true }))

const running = await Helper.open(harness, { tags: ['exit'] }, { lineout: true })
const argv = ['dump', link, targetDir]
await running.inspector.evaluate(`
__PEAR_TEST__.command(${JSON.stringify(argv)})
`, { returnByValue: false })

let dumpSuccess = false
for await (const line of running.lineout) {
if (line.endsWith('Success')) {
dumpSuccess = true
break
}
}

await running.inspector.evaluate('__PEAR_TEST__.ipc.destroy()', { returnByValue: false })
await running.inspector.close()

is(dumpSuccess, true, 'should dump successfully')
is(fs.existsSync(targetDir), true, 'should create target directory')
is(fs.existsSync(path.join(targetDir, 'package.json')), true, 'should dump package.json')
is(fs.existsSync(path.join(targetDir, 'testfile.txt')), true, 'should dump testfile.txt')
const { code } = await running.until.exit
is(code, 0, 'should have exit code 0')
})

test('pear dump pear://<key> <relative-path>', async function ({ plan, is, teardown }) {
plan(5)
const { link } = await rig.getOrCreateDumpInstance()

const testId = Math.floor(Math.random() * 100000)
const targetDir = path.join(minimal, `pear-dump-${testId}`)
const targetDirRelative = path.relative(harness, targetDir)
teardown(async () => fs.promises.rm(targetDir, { recursive: true }))

const running = await Helper.open(harness, { tags: ['exit'] }, { lineout: true })
const argv = ['dump', link, targetDirRelative]
await running.inspector.evaluate(`
__PEAR_TEST__.command(${JSON.stringify(argv)})
`, { returnByValue: false })

let dumpSuccess = false
for await (const line of running.lineout) {
if (line.endsWith('Success')) {
dumpSuccess = true
break
}
}

await running.inspector.evaluate('__PEAR_TEST__.ipc.destroy()', { returnByValue: false })
await running.inspector.close()

is(dumpSuccess, true, 'should dump successfully')
is(fs.existsSync(targetDir), true, 'should create target directory')
is(fs.existsSync(path.join(targetDir, 'package.json')), true, 'should dump package.json')
is(fs.existsSync(path.join(targetDir, 'testfile.txt')), true, 'should dump testfile.txt')
const { code } = await running.until.exit
is(code, 0, 'should have exit code 0')
})

test('pear dump --checkout <n> pear://<key> <relative-path>', async function ({ plan, is, teardown }) {
plan(5)
const { link, versionOld } = await rig.getOrCreateDumpInstance()

const testId = Math.floor(Math.random() * 100000)
const targetDir = path.join(minimal, `pear-dump-${testId}`)
const targetDirRelative = path.relative(harness, targetDir)
teardown(async () => fs.promises.rm(targetDir, { recursive: true }))

const running = await Helper.open(harness, { tags: ['exit'] }, { lineout: true })
const argv = ['dump', link, '--checkout', `${versionOld}`, targetDirRelative]
await running.inspector.evaluate(`
__PEAR_TEST__.command(${JSON.stringify(argv)})
`, { returnByValue: false })

let dumpSuccess = false
for await (const line of running.lineout) {
if (line.endsWith('Success')) {
dumpSuccess = true
break
}
}

await running.inspector.evaluate('__PEAR_TEST__.ipc.destroy()', { returnByValue: false })
await running.inspector.close()

is(dumpSuccess, true, 'should dump successfully')
is(fs.existsSync(targetDir), true, 'should create target directory')
is(fs.existsSync(path.join(targetDir, 'package.json')), true, 'should dump package.json')
is(fs.existsSync(path.join(targetDir, 'testfile.txt')), false, 'should not dump testfile.txt')
const { code } = await running.until.exit
is(code, 0, 'should have exit code 0')
})

test('pear dump --checkout staged pear://<key> <relative-path>', async function ({ plan, is, teardown }) {
plan(5)
const { link } = await rig.getOrCreateDumpInstance()

const testId = Math.floor(Math.random() * 100000)
const targetDir = path.join(minimal, `pear-dump-${testId}`)
const targetDirRelative = path.relative(harness, targetDir)
teardown(async () => fs.promises.rm(targetDir, { recursive: true }))

const running = await Helper.open(harness, { tags: ['exit'] }, { lineout: true })
const argv = ['dump', link, '--checkout', 'staged', targetDirRelative]
await running.inspector.evaluate(`
__PEAR_TEST__.command(${JSON.stringify(argv)})
`, { returnByValue: false })

let dumpSuccess = false
for await (const line of running.lineout) {
if (line.endsWith('Success')) {
dumpSuccess = true
break
}
}

await running.inspector.evaluate('__PEAR_TEST__.ipc.destroy()', { returnByValue: false })
await running.inspector.close()

is(dumpSuccess, true, 'should dump successfully')
is(fs.existsSync(targetDir), true, 'should create target directory')
is(fs.existsSync(path.join(targetDir, 'package.json')), true, 'should dump package.json')
is(fs.existsSync(path.join(targetDir, 'testfile.txt')), true, 'should dump testfile.txt')
const { code } = await running.until.exit
is(code, 0, 'should have exit code 0')
})

// TODO: Uncomment once --checkout release is supported
// test('pear dump --checkout release pear://<key> <relative-path>', async function ({ plan, is, teardown }) {
// plan(5)
// const { link } = await rig.getOrCreateDumpInstance()
//
// const testId = Math.floor(Math.random() * 100000)
// const targetDir = path.join(minimal, `pear-dump-${testId}`)
// const targetDirRelative = path.relative(harness, targetDir)
// teardown(async () => fs.promises.rm(targetDir, { recursive: true }))
//
// const running = await Helper.open(harness, { tags: ['exit'] }, { lineout: true })
// const argv = ['dump', link, '--checkout', 'release', targetDirRelative]
// await running.inspector.evaluate(`
// __PEAR_TEST__.command(${JSON.stringify(argv)})
// `, { returnByValue: false })
//
// let dumpSuccess = false
// for await (const line of running.lineout) {
// if (line.endsWith('Success')) {
// dumpSuccess = true
// break
// }
// }
//
// await running.inspector.evaluate('__PEAR_TEST__.ipc.destroy()', { returnByValue: false })
// await running.inspector.close()
//
// is(dumpSuccess, true, 'should dump successfully')
// is(fs.existsSync(targetDir), true, 'should create target directory')
// is(fs.existsSync(path.join(targetDir, 'package.json')), true, 'should dump package.json')
// is(fs.existsSync(path.join(targetDir, 'testfile.txt')), false, 'should not dump testfile.txt')
// const { code } = await running.until.exit
// is(code, 0, 'should have exit code 0')
// })

test('pear dump --json pear://<key> <relative-path>', async function ({ plan, is, alike, teardown }) {
plan(5)
const { link } = await rig.getOrCreateDumpInstance()

const testId = Math.floor(Math.random() * 100000)
const targetDir = path.join(minimal, `pear-dump-${testId}`)
const targetDirRelative = path.relative(harness, targetDir)
teardown(async () => fs.promises.rm(targetDir, { recursive: true }))

const running = await Helper.open(harness, { tags: ['exit'] }, { lineout: true })
const argv = ['dump', '--json', link, targetDirRelative]
await running.inspector.evaluate(`
__PEAR_TEST__.command(${JSON.stringify(argv)})
`, { returnByValue: false })

const seen = new Set()
const tags = []
for await (const line of running.lineout) {
const result = JSON.parse(line)
if (seen.has(result.tag)) continue
seen.add(result.tag)
tags.push(result.tag)
if (result.tag === 'final') break
}

await running.inspector.evaluate('__PEAR_TEST__.ipc.destroy()', { returnByValue: false })
await running.inspector.close()

alike(tags, ['dumping', 'byte-diff', 'final'], 'should output correct tags')
is(fs.existsSync(targetDir), true, 'should create target directory')
is(fs.existsSync(path.join(targetDir, 'package.json')), true, 'should dump package.json')
is(fs.existsSync(path.join(targetDir, 'testfile.txt')), true, 'should dump testfile.txt')
const { code } = await running.until.exit
is(code, 0, 'should have exit code 0')
})

test.todo('pear shift <source> <destination>')
test.todo('pear shift --json <source> <destination>')
test.todo('pear shift --force <source> <destination>')
test.todo('pear shift --force --json <source> <destination>')

test.todo('pear gc releases')
test.todo('pear gc releases --json')
test.todo('pear gc sidecars')
test.todo('pear gc sidecars --json')

test.todo('pear versions')
test.todo('pear versions --json')
test.todo('pear -v')

test('commands cleanup', rig.cleanup)
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ async function runTests () {
await import('./02-shutdown.test.js')
await import('./03-teardown.test.js')
await import('./04-updates.test.js')
// await import('./05-commands.test.js')
await import('./05-commands.test.js')
await import('./06-worker.test.js')

test.resume()

0 comments on commit 64f02a2

Please sign in to comment.