Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: vitest workspaces #868

Merged
merged 5 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 59 additions & 116 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"publish": "npx lerna publish",
"prelint": "npm run build",
"pretest": "npm run build",
"test": "npx lerna run test --stream"
"test": "vitest --coverage"
},
"repository": {
"type": "git",
Expand All @@ -27,10 +27,12 @@
],
"devDependencies": {
"@readme/eslint-config": "^14.0.0",
"@vitest/coverage-v8": "^1.6.0",
"alex": "^11.0.1",
"eslint": "^8.57.0",
"lerna": "^8.1.2",
"prettier": "^3.2.5"
"prettier": "^3.2.5",
"vitest": "^1.6.0"
},
"prettier": "@readme/eslint-config/prettier"
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
"content": {
"application/json": {
"schema": {
"$ref": "./test/__fixtures__/bundle/pet.json"
"$ref": "./pet.json"
}
},
"application/xml": {
"schema": {
"$ref": "./test/__fixtures__/bundle/pet.json"
"$ref": "./pet.json"
}
}
},
Expand Down
47 changes: 47 additions & 0 deletions packages/oas-normalize/test/index.chdir.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* eslint-disable unicorn/prefer-module -- We use `require.resolve` for reading YAML fixtures. */
import type { OpenAPIV3 } from 'openapi-types';

import path from 'node:path';

import { describe, it, expect, beforeEach, afterEach } from 'vitest';

import OASNormalize from '../src/index.js';

/**
* @note only tests that require `process.chdir()` should be in this file.
*/

describe('#bundle', () => {
let originalCwd: string;

beforeEach(() => {
originalCwd = process.cwd();
});

afterEach(() => {
process.chdir(originalCwd);
});

it('should bundle an external schema in', async () => {
const petSchema = await import('./__fixtures__/bundle/pet.json').then(r => r.default);
const contents = require.resolve('./__fixtures__/bundle/definition.json');
process.chdir(path.dirname(contents));
const o = new OASNormalize(contents, { enablePaths: true });
const bundled = (await o.bundle()) as OpenAPIV3.Document;

expect(bundled.components?.requestBodies?.Pet).toStrictEqual({
description: 'Pet object that needs to be added to the store',
required: true,
content: {
'application/json': {
schema: {
$ref: '#/components/requestBodies/Pet/content/application~1xml/schema',
},
},
'application/xml': {
schema: petSchema,
},
},
});
});
});
22 changes: 0 additions & 22 deletions packages/oas-normalize/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,28 +117,6 @@ describe('#load', () => {
});

describe('#bundle', () => {
it('should bundle an external schema in', async () => {
const petSchema = await import('./__fixtures__/bundle/pet.json').then(r => r.default);
const contents = require.resolve('./__fixtures__/bundle/definition.json');
const o = new OASNormalize(contents, { enablePaths: true });
const bundled = (await o.bundle()) as OpenAPIV3.Document;

expect(bundled.components?.requestBodies?.Pet).toStrictEqual({
description: 'Pet object that needs to be added to the store',
required: true,
content: {
'application/json': {
schema: {
$ref: '#/components/requestBodies/Pet/content/application~1xml/schema',
},
},
'application/xml': {
schema: petSchema,
},
},
});
});

describe('Postman support', () => {
it('should convert a Postman collection if supplied', async () => {
const postman = await import('./__fixtures__/postman/petstore.collection.json').then(r => r.default);
Expand Down
11 changes: 11 additions & 0 deletions packages/oas-normalize/vitest.config.chdir.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { defineProject } from 'vitest/config';

// This config is for test files that use `process.chdir`.
export default defineProject({
test: {
include: ['**/test/index.chdir.test.ts'],
name: 'oas-normalize (chdir)',
pool: 'forks',
},
});
15 changes: 15 additions & 0 deletions packages/oas-normalize/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { defineProject } from 'vitest/config';

export default defineProject({
test: {
/**
* Deliberately excluding index.chdir.test.ts since that uses `process.chdir`
* and therefore requires a different `pool` setting.
*
* @see {@link ./vitest.config.chdir.ts}
*/
exclude: ['test/index.chdir.test.ts'],
name: 'oas-normalize',
},
});
8 changes: 8 additions & 0 deletions packages/oas-normalize/vitest.workspace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* eslint-disable require-extensions/require-extensions */
// eslint-disable-next-line import/no-extraneous-dependencies
import { defineWorkspace } from 'vitest/config';

import defaultConfig from './vitest.config';
import chdirConfig from './vitest.config.chdir';

export default defineWorkspace([defaultConfig, chdirConfig]);
13 changes: 13 additions & 0 deletions vitest.workspace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { defineWorkspace } from 'vitest/config';

// eslint-disable-next-line require-extensions/require-extensions
import chdirConfig from './packages/oas-normalize/vitest.config.chdir';

export default defineWorkspace([
'packages/*',
{
// including another config for a test that requires the `pool: forks` option.
...chdirConfig,
},
]);