diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index fdafa3f..9be304b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -14,28 +14,11 @@ jobs: with: node-version: "lts/*" - - run: npm install + - name: Install Dependencies + run: npm install - - run: npm test - working-directory: npm/cli-darwin-arm64 - env: { NODE_AUTH_TOKEN: "${{ secrets.NPM_TOKEN }}" } + - name: Lint + run: npm run lint - - name: Publish @yaakapp/cli-darwin-x64 - run: npm publish --provenance --access public - working-directory: npm/cli-darwin-x64 - env: { NODE_AUTH_TOKEN: "${{ secrets.NPM_TOKEN }}" } - - - name: Publish @yaakapp/cli-linux-x64 - run: npm publish --provenance --access public - working-directory: npm/cli-linux-x64 - env: { NODE_AUTH_TOKEN: "${{ secrets.NPM_TOKEN }}" } - - - name: Publish @yaakapp/cli-win32-x64 - run: npm publish --provenance --access public - working-directory: npm/cli-win32-x64 - env: { NODE_AUTH_TOKEN: "${{ secrets.NPM_TOKEN }}" } - - - name: Publish @yaakapp/cli - run: npm publish --provenance --access public - working-directory: npm/cli - env: { NODE_AUTH_TOKEN: "${{ secrets.NPM_TOKEN }}" } + - name: Run Tests + run: npm test diff --git a/package-lock.json b/package-lock.json index 1a54adc..9ac01b9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,6 +7,7 @@ "name": "@yaakapp/plugins", "devDependencies": { "jsonpath": "^1.1.1", + "typescript": "^5.5.2", "vitest": "^2.0.4" } }, @@ -1408,6 +1409,19 @@ "node": ">= 0.8.0" } }, + "node_modules/typescript": { + "version": "5.6.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.2.tgz", + "integrity": "sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, "node_modules/underscore": { "version": "1.12.1", "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.12.1.tgz", diff --git a/package.json b/package.json index 8ce4ad1..d535aa6 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,12 @@ "private": true, "scripts": { "build": "node scripts/build-plugins.cjs", - "test": "vitest run" + "test": "vitest run", + "lint": "tsc" }, "devDependencies": { "jsonpath": "^1.1.1", - "vitest": "^2.0.4" + "vitest": "^2.0.4", + "typescript": "^5.5.2" } } diff --git a/plugins/importer-openapi/tests/index.test.ts b/plugins/importer-openapi/tests/index.test.ts index f89dcf7..29a2ce3 100644 --- a/plugins/importer-openapi/tests/index.test.ts +++ b/plugins/importer-openapi/tests/index.test.ts @@ -1,21 +1,24 @@ +import { Context } from '@yaakapp/api'; import * as fs from 'node:fs'; import * as path from 'node:path'; import { describe, expect, test } from 'vitest'; import { pluginHookImport } from '../src'; +const ctx = {} as Context; + describe('importer-openapi', () => { const p = path.join(__dirname, 'fixtures'); const fixtures = fs.readdirSync(p); test('Skips invalid file', async () => { - const imported = await pluginHookImport({}, '{}'); + const imported = await pluginHookImport(ctx, '{}'); expect(imported).toBeUndefined(); }) for (const fixture of fixtures) { test('Imports ' + fixture, async () => { const contents = fs.readFileSync(path.join(p, fixture), 'utf-8'); - const imported = await pluginHookImport({}, contents); + const imported = await pluginHookImport(ctx, contents); expect(imported?.resources.workspaces).toEqual([ expect.objectContaining({ name: 'Swagger Petstore - OpenAPI 3.0', diff --git a/plugins/importer-postman/tests/index.test.ts b/plugins/importer-postman/tests/index.test.ts index 1085216..0ab8767 100644 --- a/plugins/importer-postman/tests/index.test.ts +++ b/plugins/importer-postman/tests/index.test.ts @@ -1,29 +1,19 @@ +import { Context, Model } from '@yaakapp/api'; import * as fs from 'node:fs'; import * as path from 'node:path'; -import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'; -import { Model } from '../../../src-web/lib/models'; +import { describe, expect, test } from 'vitest'; import { pluginHookImport } from '../src'; -let originalRandom = Math.random; +const ctx = {} as Context; describe('importer-postman', () => { - beforeEach(() => { - let i = 0; - // Psuedo-random number generator to ensure consistent ID generation - Math.random = vi.fn(() => ((i++ * 1000) % 133) / 100); - }); - - afterEach(() => { - Math.random = originalRandom; - }); - const p = path.join(__dirname, 'fixtures'); const fixtures = fs.readdirSync(p); for (const fixture of fixtures) { test('Imports ' + fixture, () => { const contents = fs.readFileSync(path.join(p, fixture), 'utf-8'); - const imported = pluginHookImport({}, contents); + const imported = pluginHookImport(ctx, contents); const folder0 = newId('folder'); const folder1 = newId('folder'); expect(imported).toEqual({ diff --git a/plugins/importer-yaak/tests/index.test.ts b/plugins/importer-yaak/tests/index.test.ts index 38e4413..0e4187d 100644 --- a/plugins/importer-yaak/tests/index.test.ts +++ b/plugins/importer-yaak/tests/index.test.ts @@ -1,7 +1,8 @@ +import { Context } from '@yaakapp/api'; import { describe, expect, test } from 'vitest'; import { pluginHookImport } from '../src'; -const ctx = {}; +const ctx = {} as Context; describe('importer-yaak', () => { test('Skips invalid imports', () => {