Skip to content

Commit

Permalink
test: add tests for features and validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ni55aN committed Aug 20, 2024
1 parent 86d7e10 commit 1846992
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules/
/playwright/.cache/
/.rete-qa
/dist
/coverage
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"scripts": {
"build": "tsc",
"dev": "tsc --watch",
"lint": "rete lint"
"lint": "rete lint",
"test": "rete test"
},
"author": "Vitaliy Stoliarov",
"license": "MIT",
Expand All @@ -29,11 +30,11 @@
"devDependencies": {
"@types/tinycolor2": "^1.4.3",
"nodemon": "^2.0.20",
"rete-kit": "^1.7.0",
"rete-kit": "^1.8.1",
"typescript": "^4.9.5"
},
"peerDependencies": {
"rete-kit": "^1.7.0"
"rete-kit": "^1.8.0"
},
"dependencies": {
"@playwright/test": "^1.37.1",
Expand Down
77 changes: 77 additions & 0 deletions src/commands/init/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { beforeEach, describe, expect, it } from '@jest/globals'
import { App } from 'rete-kit'

import { fixtures, getFeatures, validate } from './index'

describe('Features', () => {
fixtures.forEach(fixture => {
describe(`Stack: ${fixture.stack}, Version: ${fixture.version}`, () => {
let features: ReturnType<typeof getFeatures> = []

beforeEach(() => {
const next = false

features = getFeatures(fixture, next).filter(Boolean)
})

it('has common features', () => {
expect(features).toContainEqual(expect.any(App.Features.ZoomAt))
expect(features).toContainEqual(expect.any(App.Features.OrderNodes))
expect(features).toContainEqual(expect.any(App.Features.Dataflow))
expect(features).toContainEqual(expect.any(App.Features.Selectable))
expect(features).toContainEqual(expect.any(App.Features.Minimap))
expect(features).toContainEqual(expect.any(App.Features.Reroute))
})

it('has stack specific features', () => {
if (fixture.stack === 'angular') {
expect(features).toContainEqual(expect.any(App.Features.Angular))
} else if (fixture.stack === 'react') {
expect(features).toContainEqual(expect.any(App.Features.React))
} else if (fixture.stack === 'vue') {
expect(features).toContainEqual(expect.any(App.Features.Vue))
} else if (fixture.stack === 'svelte') {
expect(features).toContainEqual(expect.any(App.Features.Svelte))
}
})
})
})
})

describe('Validation', () => {
it('rejects unknown stack names', () => {
const stacks = ['react', 'angular', 'unknown']
const stackVersions = null

const result = validate(stacks, stackVersions)

expect(result.error).toBe('Unknown stack names: unknown')
})

it('throws an error if versions are specified for multiple stacks', () => {
const stacks = ['react', 'angular']
const stackVersions = ['16', '12']

const result = validate(stacks, stackVersions)

expect(result.error).toBe(`You can't specify versions for multiple stacks`)
})

it('throws an error if unsupported versions are specified', () => {
const stacks = ['react']
const stackVersions = ['unknown']

const result = validate(stacks, stackVersions)

expect(result.error).toBe('Unknown stack versions: unknown')
})

it('should return null if no errors are found', () => {
const stacks = ['react']
const stackVersions = ['16', '17']

const result = validate(stacks, stackVersions)

expect(result.error).toBeNull()
})
})

0 comments on commit 1846992

Please sign in to comment.