Skip to content

Commit

Permalink
enforce test order
Browse files Browse the repository at this point in the history
  • Loading branch information
loreanvictor committed Jan 5, 2024
1 parent d08e2b9 commit 8e59e9b
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 32 deletions.
5 changes: 5 additions & 0 deletions e2e/all.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import './sanity-test.mjs'
import './basic-test.mjs'
import './glob-test.mjs'
import './readwrite-test.mjs'
import './local-test.mjs'
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
65 changes: 33 additions & 32 deletions e2e/util.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,38 @@ export function scenario(name, testFn, options) {
options ??= {}
options.root ??= '.'

test('scenario: ' + name, async () => {
const fixsrc = name.split(':')[0]
const fixture = join('e2e', 'fixtures', fixsrc)

await access(fixture)
const stat = await lstat(fixture)
expect(stat.isDirectory()).toBe(true)

const dir = await mkdtemp('test-')
await cp(fixture, dir, { recursive: true })

const cwd = join(dir, options.root)
const cmd = $({ cwd })
const bin = await getBinPath()
console.log(bin)
const run = (...args) => execa(bin, args, { cwd })

try {
await testFn(run, {
dir,
$: async (...args) => (await cmd(...args)).stdout,
ls: async (path = '.') => {
const { stdout } = await cmd`ls -a ${path}`
return stdout.split('\n').filter(x => x !== '.' && x !== '..')
},
read: async file => {
return await readFile(join(cwd, file), 'utf8')
}
})
} finally {
await rm(dir, { recursive: true })
}
describe('scenario: ' + name, () => {
test('runs as expected', async () => {
const fixsrc = name.split(':')[0]
const fixture = join('e2e', 'fixtures', fixsrc)

await access(fixture)
const stat = await lstat(fixture)
expect(stat.isDirectory()).toBe(true)

const dir = await mkdtemp('test-')
await cp(fixture, dir, { recursive: true })

const cwd = join(dir, options.root)
const cmd = $({ cwd })
const bin = await getBinPath()
const run = (...args) => execa(bin, args, { cwd })

try {
await testFn(run, {
dir,
$: async (...args) => (await cmd(...args)).stdout,
ls: async (path = '.') => {
const { stdout } = await cmd`ls -a ${path}`
return stdout.split('\n').filter(x => x !== '.' && x !== '..')
},
read: async file => {
return await readFile(join(cwd, file), 'utf8')
}
})
} finally {
await rm(dir, { recursive: true })
}
})
})
}

0 comments on commit 8e59e9b

Please sign in to comment.