Fix tests and lint

This commit is contained in:
Gregory Schier
2024-09-09 11:49:05 -07:00
parent 48e62eb1d9
commit 035441a492
6 changed files with 35 additions and 42 deletions

View File

@@ -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',

View File

@@ -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({

View File

@@ -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', () => {