feat: add stage condition checks

This commit is contained in:
wancat committed 2024-03-08 00:47:50 +08:00
1 parent 77fe2d37b3
commit 5bea2ea78c
3 files changed
+60 -13

No files matched your search

+1 -1
View File
@@ -3,7 +3,7 @@ import { IFileExistenceChecker, FileType, FileInput } from '../src/types.js'
import { checkFiles } from '../src/condition/FileMatcher.js'
import { Condition } from '../src/condition/Condition.js'
class MockFileChecker implements IFileExistenceChecker {
export class MockFileChecker implements IFileExistenceChecker {
private files: FileInput[] = [
{
path: '/home/user/hello.txt',
+53 -9
View File
@@ -1,7 +1,11 @@
import { test, expect } from '@jest/globals'
import { Stage } from '../src/Stage'
import { FileType } from '../src/types'
import { MockFileChecker } from './asyncCondition.test'
test('check stage condition', () => {
const checker = new MockFileChecker()
test('check stage condition', async () => {
const stage = new Stage({
id: 'stage1',
name: 'List the files using `ls`',
@@ -11,15 +15,55 @@ test('check stage condition', () => {
},
})
expect(
stage.satisfies({
command: 'ls',
pwd: '/home/user',
})
await stage.satisfies(
{
command: 'ls',
pwd: '/home/user',
},
checker
)
).toBe(true)
expect(
stage.satisfies({
command: 'ls',
pwd: '/home/user/Downloads',
})
await stage.satisfies(
{
command: 'ls',
pwd: '/home/user/Downloads',
},
checker
)
).toBe(false)
})
test('check stage with async condition truthy', async () => {
const stage = new Stage({
id: 'stage1',
name: 'Create file',
condition: {
files: [
{
path: '/home/user/hello.txt',
type: FileType.FILE,
exists: true,
},
],
},
})
expect(await stage.satisfies({}, checker)).toBe(true)
})
test('check stage with async condition falsy', async () => {
const stage = new Stage({
id: 'stage1',
name: 'Create file',
condition: {
files: [
{
path: '/home/user/not-exists.txt',
type: FileType.FILE,
exists: true,
},
],
},
})
expect(await stage.satisfies({}, checker)).toBe(false)
})