From 1846992eb8e93f6152d5284d8d49eae868930cfe Mon Sep 17 00:00:00 2001 From: Ni55aN Date: Tue, 20 Aug 2024 16:35:26 +0300 Subject: [PATCH] test: add tests for features and validation --- .gitignore | 1 + package-lock.json | 10 ++--- package.json | 7 +-- src/commands/init/index.test.ts | 77 +++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 8 deletions(-) create mode 100644 src/commands/init/index.test.ts diff --git a/.gitignore b/.gitignore index ff54274..dff5673 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ node_modules/ /playwright/.cache/ /.rete-qa /dist +/coverage \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 09c0540..6710b11 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,11 +24,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" } }, "node_modules/@ampproject/remapping": { @@ -7328,9 +7328,9 @@ } }, "node_modules/rete-kit": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/rete-kit/-/rete-kit-1.7.0.tgz", - "integrity": "sha512-IrdRbz3NexBVTEtV6M1S3fK6lINOzPWViQD1y6HXseY8ue6Id4ZtsXaMxZr64g5Yt2eJw78C9IQHUluMj986aQ==", + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/rete-kit/-/rete-kit-1.8.1.tgz", + "integrity": "sha512-wAE/ibiVUDTnn6uoHGDvxgP1dwtFOdcsKk9px3detb2qofuYsdGdpcmhhwkhPqbibKB1qJuiYv0HM5JDa+p8ww==", "dev": true, "dependencies": { "case": "^1.6.3", diff --git a/package.json b/package.json index 3b942a2..38da28a 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "scripts": { "build": "tsc", "dev": "tsc --watch", - "lint": "rete lint" + "lint": "rete lint", + "test": "rete test" }, "author": "Vitaliy Stoliarov", "license": "MIT", @@ -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", diff --git a/src/commands/init/index.test.ts b/src/commands/init/index.test.ts new file mode 100644 index 0000000..d8ce430 --- /dev/null +++ b/src/commands/init/index.test.ts @@ -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 = [] + + 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() + }) +})