Skip to content

Commit

Permalink
feat: move vitest to root using workspace config
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanshatford committed Apr 24, 2024
1 parent d4b6dbb commit 443136e
Show file tree
Hide file tree
Showing 144 changed files with 449 additions and 424 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ jobs:
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: ./packages/openapi-ts/coverage
directory: ./coverage
flags: unittests
fail_ci_if_error: true
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@
"lint": "prettier --check . && eslint .",
"openapi-ts": "pnpm --filter @hey-api/openapi-ts --",
"prepare": "husky",
"test:coverage": "pnpm --recursive test:coverage",
"test:e2e": "pnpm --recursive test:e2e",
"test:update": "pnpm --recursive test:update",
"test": "pnpm --recursive test",
"test": "vitest run --project unit",
"test:coverage": "vitest run --project unit --coverage",
"test:e2e": "vitest run --project e2e --no-file-parallelism",
"test:update": "vitest watch --project unit --update",
"typecheck": "pnpm --recursive typecheck"
},
"engines": {
"node": "^18.0.0 || >=20.0.0"
},
"devDependencies": {
"@angular/cli": "17.3.5",
"@changesets/cli": "2.27.1",
"@rollup/plugin-commonjs": "25.0.7",
"@rollup/plugin-terser": "0.4.4",
Expand Down
4 changes: 0 additions & 4 deletions packages/client-axios/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@
"clean": "rimraf dist coverage node_modules/.cache",
"dev": "rimraf dist && pnpm build-bundle --watch",
"prepublishOnly": "pnpm build",
"test:coverage": "vitest run --coverage",
"test:update": "vitest watch --update",
"test:watch": "vitest watch",
"test": "vitest run",
"typecheck": "tsc --noEmit"
},
"engines": {
Expand Down
14 changes: 0 additions & 14 deletions packages/client-axios/vitest.config.ts

This file was deleted.

4 changes: 0 additions & 4 deletions packages/client-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
"clean": "rimraf dist coverage node_modules/.cache",
"dev": "rimraf dist && pnpm build-bundle --watch",
"prepublishOnly": "pnpm build",
"test:coverage": "vitest run --coverage",
"test:update": "vitest watch --update",
"test:watch": "vitest watch",
"test": "vitest run",
"typecheck": "tsc --noEmit"
},
"engines": {
Expand Down
14 changes: 0 additions & 14 deletions packages/client-core/vitest.config.ts

This file was deleted.

4 changes: 0 additions & 4 deletions packages/client-fetch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@
"clean": "rimraf dist coverage node_modules/.cache",
"dev": "rimraf dist && pnpm build-bundle --watch",
"prepublishOnly": "pnpm build",
"test:coverage": "vitest run --coverage",
"test:update": "vitest watch --update",
"test:watch": "vitest watch",
"test": "vitest run",
"typecheck": "tsc --noEmit"
},
"engines": {
Expand Down
14 changes: 0 additions & 14 deletions packages/client-fetch/vitest.config.ts

This file was deleted.

5 changes: 0 additions & 5 deletions packages/openapi-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,7 @@
"clean": "rimraf dist test/generated test/e2e/generated coverage node_modules/.cache",
"dev": "rimraf dist && pnpm build-bundle --watch",
"prepublishOnly": "pnpm build",
"test:coverage": "vitest run --config vitest.config.unit.ts --coverage",
"test:e2e": "vitest run --config vitest.config.e2e.ts",
"test:sample": "node test/sample.cjs",
"test:update": "vitest watch --config vitest.config.unit.ts --update",
"test:watch": "vitest watch --config vitest.config.unit.ts",
"test": "vitest run --config vitest.config.unit.ts",
"typecheck": "tsc --noEmit"
},
"engines": {
Expand Down
20 changes: 14 additions & 6 deletions packages/openapi-ts/src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';

import { describe, it } from 'vitest';

import { createClient } from './index';

const __dirname = fileURLToPath(new URL('.', import.meta.url));

const v2Spec = path.resolve(__dirname, '../test/spec/v2.json');
const v3Spec = path.resolve(__dirname, '../test/spec/v3.json');

describe('index', () => {
it('parses v2 without issues', async () => {
await createClient({
dryRun: true,
input: './test/spec/v2.json',
output: './generated/v2/',
input: v2Spec,
output: path.resolve(__dirname, '../test/generated/v2/'),
});
});

it('parses v3 without issues', async () => {
await createClient({
dryRun: true,
input: './test/spec/v3.json',
output: './generated/v3/',
input: v3Spec,
output: path.resolve(__dirname, '../test/generated/v3/'),
});
});

Expand All @@ -24,7 +32,7 @@ describe('index', () => {
dryRun: true,
input:
'https://raw.githubusercontent.com/hey-api/openapi-ts/main/packages/openapi-ts/test/spec/v2.json',
output: './generated/v2-downloaded/',
output: path.resolve(__dirname, '../test/generated/v2-downloaded/'),
});
});

Expand All @@ -33,7 +41,7 @@ describe('index', () => {
dryRun: true,
input:
'https://raw.githubusercontent.com/hey-api/openapi-ts/main/packages/openapi-ts/test/spec/v3.json',
output: './generated/v3-downloaded/',
output: path.resolve(__dirname, '../test/generated/v3-downloaded/'),
});
});
});

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import type { ApiRequestOptions } from './ApiRequestOptions';

type Headers = Record<string, string>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import type { ApiRequestOptions } from './ApiRequestOptions';

type Headers = Record<string, string>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import type { ApiRequestOptions } from './ApiRequestOptions';

type Headers = Record<string, string>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import type { ApiRequestOptions } from './ApiRequestOptions';

type Headers = Record<string, string>;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import type { ApiRequestOptions } from './ApiRequestOptions';

type Headers = Record<string, string>;
type Middleware<T> = (value: T) => T | Promise<T>;
type Resolver<T> = (options: ApiRequestOptions) => Promise<T>;

export class Interceptors<T> {
_fns: Middleware<T>[];

constructor() {
this._fns = [];
}

eject(fn: Middleware<T>) {
const index = this._fns.indexOf(fn);
if (index !== -1) {
this._fns = [...this._fns.slice(0, index), ...this._fns.slice(index + 1)];
}
}

use(fn: Middleware<T>) {
this._fns = [...this._fns, fn];
}
}

export type OpenAPIConfig = {
BASE: string;
CREDENTIALS: 'include' | 'omit' | 'same-origin';
ENCODE_PATH?: ((path: string) => string) | undefined;
HEADERS?: Headers | Resolver<Headers> | undefined;
PASSWORD?: string | Resolver<string> | undefined;
TOKEN?: string | Resolver<string> | undefined;
USERNAME?: string | Resolver<string> | undefined;
VERSION: string;
WITH_CREDENTIALS: boolean;
interceptors: {
request: Interceptors<RequestInit>;
response: Interceptors<Response>;
};
};

export const OpenAPI: OpenAPIConfig = {
BASE: 'http://localhost:3000/base',
CREDENTIALS: 'include',
ENCODE_PATH: undefined,
HEADERS: undefined,
PASSWORD: undefined,
TOKEN: undefined,
USERNAME: undefined,
VERSION: '1.0',
WITH_CREDENTIALS: false,
interceptors: {
request: new Interceptors(),
response: new Interceptors(),
},
};
Loading

0 comments on commit 443136e

Please sign in to comment.