Skip to content

Commit

Permalink
feat(test): moving unit testing over to vitest (#789)
Browse files Browse the repository at this point in the history
* feat: moving unit testing over to vitest

* fix: bringing back a test and making it work

* feat: upgrading eslint and movin us to prettier 3

* fix: remove unused jest config

* Update package.json

Co-authored-by: Kanad Gupta <[email protected]>

* chore: bump eslint-config pkg

---------

Co-authored-by: Kanad Gupta <[email protected]>
  • Loading branch information
erunion and kanadgupta authored Aug 13, 2023
1 parent 68b248e commit 190a6c7
Show file tree
Hide file tree
Showing 51 changed files with 6,795 additions and 9,617 deletions.
21 changes: 1 addition & 20 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,39 +1,20 @@
{
"extends": [
"@readme/eslint-config",
"@readme/eslint-config/docs",
"@readme/eslint-config/typescript"
],
"root": true,
"plugins": ["jsdoc"],
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-use-before-define": ["error", { "classes": false }],

"camelcase": "off",

// Though we aren't requiring JSDoc blocks to be present, if they are they should be properly
// formatted.
"jsdoc/require-jsdoc": "off",
"jsdoc/tag-lines": "off",

"max-classes-per-file": "off",
"no-param-reassign": "off",

"no-underscore-dangle": ["error", {
"allow": ["_key"]
}]
},
"overrides": [
{
"files": "*.ts",
"rules": {
// TypeScript types are better suited for these cases instead.
"jsdoc/require-param": "off",
"jsdoc/require-param-type": "off",
"jsdoc/require-returns": "off",
"jsdoc/require-returns-type": "off"
}
}
]
}
}
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ __tests__/
coverage/
.eslint*
.prettier*
jest.*.js
5 changes: 1 addition & 4 deletions __tests__/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"extends": "@readme/eslint-config/testing",
"rules": {
"testing-library/prefer-presence-queries": "off"
}
"extends": "@readme/eslint-config/testing/vitest"
}
10 changes: 5 additions & 5 deletions __tests__/__fixtures__/json-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function buildSchemaCore(opts: Parameters<typeof generateJSONSchemaFixture>[0] =

function generateScenarioName(
scenario: keyof typeof SCHEMA_SCENARIOS,
opts: Parameters<typeof generateJSONSchemaFixture>[0] = {}
opts: Parameters<typeof generateJSONSchemaFixture>[0] = {},
) {
const caseOptions: string[] = [];

Expand All @@ -126,7 +126,7 @@ export default function generateJSONSchemaFixture(
example?: unknown;
examples?: Record<string, unknown>;
required?: boolean;
} = {}
} = {},
): SchemaObject {
const props = buildSchemaCore(opts);
const schemas: { scenario: string; schema: any }[] = [];
Expand All @@ -141,7 +141,7 @@ export default function generateJSONSchemaFixture(
const getPolymorphismScenario = (
polyType: string,
scenario: keyof typeof SCHEMA_SCENARIOS,
allowEmptyValue?: boolean
allowEmptyValue?: boolean,
) => {
return {
scenario: `${polyType}:${generateScenarioName(scenario, { ...opts, allowEmptyValue })}`,
Expand Down Expand Up @@ -181,7 +181,7 @@ export default function generateJSONSchemaFixture(
getScenario('mixed primitive'),
getPolymorphismScenario('oneOf', 'mixed primitive'),
getPolymorphismScenario('allOf', 'mixed primitive'),
getPolymorphismScenario('anyOf', 'mixed primitive')
getPolymorphismScenario('anyOf', 'mixed primitive'),
);

if (opts.allowEmptyValue !== undefined) {
Expand Down Expand Up @@ -214,7 +214,7 @@ export default function generateJSONSchemaFixture(
getScenario('mixed primitive', false),
getPolymorphismScenario('oneOf', 'mixed primitive', true),
getPolymorphismScenario('allOf', 'mixed primitive', false),
getPolymorphismScenario('anyOf', 'mixed primitive', false)
getPolymorphismScenario('anyOf', 'mixed primitive', false),
);
}

Expand Down
8 changes: 4 additions & 4 deletions __tests__/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`#dereference() should add metadata to components pre-dereferencing to preserve their lineage stored as \`title\` if the \`preserveRefAsJSONSchemaTitle\` option is supplied 1`] = `
exports[`#dereference() > should add metadata to components pre-dereferencing to preserve their lineage > stored as \`title\` if the \`preserveRefAsJSONSchemaTitle\` option is supplied 1`] = `
{
"/pet": {
"post": {
Expand Down Expand Up @@ -2073,7 +2073,7 @@ exports[`#dereference() should add metadata to components pre-dereferencing to p
}
`;

exports[`#dereference() should add metadata to components pre-dereferencing to preserve their lineage stored as \`x-readme-ref-name 1`] = `
exports[`#dereference() > should add metadata to components pre-dereferencing to preserve their lineage > stored as \`x-readme-ref-name 1`] = `
{
"/multischema/of-everything": {
"post": {
Expand Down Expand Up @@ -3444,7 +3444,7 @@ exports[`#dereference() should add metadata to components pre-dereferencing to p
}
`;

exports[`#operation() should return a default when no operation 1`] = `
exports[`#operation() > should return a default when no operation 1`] = `
Operation {
"api": {},
"callbackExamples": undefined,
Expand Down
6 changes: 3 additions & 3 deletions __tests__/__snapshots__/operation.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`#getParametersAsJSONSchema() should return json schema 1`] = `
exports[`#getParametersAsJSONSchema() > should return json schema 1`] = `
[
{
"description": "Pet object that needs to be added to the store",
Expand Down Expand Up @@ -89,7 +89,7 @@ exports[`#getParametersAsJSONSchema() should return json schema 1`] = `
]
`;

exports[`#prepareSecurity() should work for petstore 1`] = `
exports[`#prepareSecurity() > should work for petstore 1`] = `
{
"OAuth2": [
{
Expand Down
4 changes: 2 additions & 2 deletions __tests__/analyzer/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`analyzer should should analyzer an OpenAPI definition 1`] = `
exports[`analyzer > should should analyzer an OpenAPI definition 1`] = `
{
"general": {
"mediaTypes": {
Expand Down
2 changes: 2 additions & 0 deletions __tests__/analyzer/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { OASDocument } from '../../src/rmoas.types';

import { describe, beforeAll, it, expect } from 'vitest';

import analyzer from '../../src/analyzer';

let petstore: OASDocument;
Expand Down
6 changes: 4 additions & 2 deletions __tests__/analyzer/queries/openapi.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { OASDocument } from '../../../src/rmoas.types';

import { describe, beforeAll, expect, it } from 'vitest';

import * as QUERIES from '../../../src/analyzer/queries/openapi';

function loadSpec(r: any) {
Expand All @@ -22,7 +24,7 @@ describe('analyzer queries (OpenAPI)', () => {

beforeAll(async () => {
additionalProperties = await import('@readme/oas-examples/3.0/json/schema-additional-properties.json').then(
loadSpec
loadSpec,
);
complexNesting = await import('@readme/oas-examples/3.0/json/complex-nesting.json').then(loadSpec);
callbacks = await import('@readme/oas-examples/3.0/json/callbacks.json').then(loadSpec);
Expand Down Expand Up @@ -325,7 +327,7 @@ describe('analyzer queries (OpenAPI)', () => {
},
},
},
} as any)
} as any),
).toStrictEqual(['#/paths/~1anything/get/responses/200/content/text~1plain+xml']);
});

Expand Down
8 changes: 5 additions & 3 deletions __tests__/analyzer/queries/readme.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { OASDocument } from '../../../src/rmoas.types';

import { describe, beforeAll, expect, it } from 'vitest';

import * as QUERIES from '../../../src/analyzer/queries/readme';

function loadSpec(r: any) {
Expand Down Expand Up @@ -55,7 +57,7 @@ describe('analyzer queries (ReadMe)', () => {
},
},
},
} as any)
} as any),
).toStrictEqual(['#/paths/~1anything/get', '#/x-readme/samples-enabled']);
});

Expand Down Expand Up @@ -101,7 +103,7 @@ describe('analyzer queries (ReadMe)', () => {
},
},
},
} as any)
} as any),
).toHaveLength(0);
});

Expand Down Expand Up @@ -151,7 +153,7 @@ describe('analyzer queries (ReadMe)', () => {
'x-readme': {
headers: [],
},
} as any)
} as any),
).toHaveLength(0);
});

Expand Down
Loading

0 comments on commit 190a6c7

Please sign in to comment.