Skip to content

Commit

Permalink
Fix tests and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
gschier committed Sep 9, 2024
1 parent 48e62eb commit 035441a
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 42 deletions.
29 changes: 6 additions & 23 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 14 additions & 0 deletions package-lock.json

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

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
7 changes: 5 additions & 2 deletions plugins/importer-openapi/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
18 changes: 4 additions & 14 deletions plugins/importer-postman/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
3 changes: 2 additions & 1 deletion plugins/importer-yaak/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down

0 comments on commit 035441a

Please sign in to comment.