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

feat(test): moving unit testing over to vitest #789

Merged
merged 6 commits into from
Aug 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 9 additions & 2 deletions __tests__/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"extends": "@readme/eslint-config/testing",
"extends": [
"plugin:vitest/all"
],
"rules": {
"testing-library/prefer-presence-queries": "off"
"vitest/no-conditional-in-test": "off",
"vitest/no-conditional-tests": "off",
"vitest/no-hooks": "off",
"vitest/prefer-to-be-falsy": "off",
"vitest/prefer-to-be-truthy": "off",
"vitest/require-top-level-describe": "off"
}
}
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
erunion marked this conversation as resolved.
Show resolved Hide resolved

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';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vitest offers a globals option1 for automatically adding these methods to every unit test but I kind of prefer the explicitness of not doing that.

Footnotes

  1. https://vitest.dev/config/#globals


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

let petstore: OASDocument;
Expand Down
2 changes: 2 additions & 0 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 Down
2 changes: 2 additions & 0 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
5 changes: 3 additions & 2 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type * as RMOAS from '../src/rmoas.types';

import petstoreSpec from '@readme/oas-examples/3.0/json/petstore.json';
import { beforeAll, describe, test, it, expect, vi } from 'vitest';

import Oas, { Operation, Webhook, utils } from '../src';

Expand Down Expand Up @@ -1475,7 +1476,7 @@ describe('#dereference()', () => {

it('should only dereference once when called multiple times', async () => {
const oas = new TestOas(petstoreSpec as RMOAS.OASDocument);
const spy = jest.fn();
const spy = vi.fn();

await Promise.all([oas.dereference({ cb: spy }), oas.dereference({ cb: spy }), oas.dereference({ cb: spy })]);

Expand All @@ -1488,7 +1489,7 @@ describe('#dereference()', () => {

it('should only **ever** dereference once', async () => {
const oas = new TestOas(petstoreSpec as RMOAS.OASDocument);
const spy = jest.fn();
const spy = vi.fn();

await oas.dereference({ cb: spy });
expect(oas.getDereferencing()).toStrictEqual({ processing: false, complete: true, circularRefs: [] });
Expand Down
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[`\`allowEmptyValue\` support should support allowEmptyValue 1`] = `
exports[`\`allowEmptyValue\` support > should support allowEmptyValue 1`] = `
{
"properties": {
"allOf:array of primitives:allowEmptyValue[false]default[]": {
Expand Down Expand Up @@ -681,7 +681,7 @@ exports[`\`allowEmptyValue\` support should support allowEmptyValue 1`] = `
}
`;

exports[`\`description\` support should support description 1`] = `
exports[`\`description\` support > should support description 1`] = `
{
"properties": {
"allOf:array of primitives:description[example description]": {
Expand Down Expand Up @@ -1011,7 +1011,7 @@ exports[`\`description\` support should support description 1`] = `
}
`;

exports[`\`description\` support should support description in an \`allOf\` and should prioritize the one from the last schema 1`] = `
exports[`\`description\` support > should support description in an \`allOf\` and should prioritize the one from the last schema 1`] = `
{
"properties": {
"meta": {
Expand Down
1 change: 1 addition & 0 deletions __tests__/lib/find-schema-definition.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import petstore from '@readme/oas-examples/3.0/json/petstore.json';
import { test, expect } from 'vitest';

import findSchemaDefinition from '../../src/lib/find-schema-definition';

Expand Down
2 changes: 2 additions & 0 deletions __tests__/lib/get-auth.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { test, describe, it, expect } from 'vitest';

import Oas from '../../src';
import getAuth, { getByScheme } from '../../src/lib/get-auth';
import multipleSecurities from '../__datasets__/multiple-securities.json';
Expand Down
2 changes: 2 additions & 0 deletions __tests__/lib/get-user-variable.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { test, expect } from 'vitest';

import getUserVariable from '../../src/lib/get-user-variable';

const topLevelUser = { apiKey: '123456', user: 'user', pass: 'pass' };
Expand Down
2 changes: 2 additions & 0 deletions __tests__/lib/matches-mimetype.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, it, expect } from 'vitest';

import matchesMimeType from '../../src/lib/matches-mimetype';

describe('#formUrlEncoded', () => {
Expand Down
2 changes: 2 additions & 0 deletions __tests__/lib/openapi-to-json-schema.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { SchemaObject } from '../../src/rmoas.types';
import type { JSONSchema4, JSONSchema7, JSONSchema7Definition, JSONSchema7TypeName } from 'json-schema';

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

import Oas from '../../src';
import toJSONSchema from '../../src/lib/openapi-to-json-schema';
import createOas from '../__fixtures__/create-oas';
Expand Down
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[`\`default\` support in \`openapi-to-json-schema\` should support a default of \`false\` 1`] = `
exports[`\`default\` support in \`openapi-to-json-schema\` > should support a default of \`false\` 1`] = `
{
"properties": {
"allOf:array of primitives:default[false]": {
Expand Down Expand Up @@ -330,7 +330,7 @@ exports[`\`default\` support in \`openapi-to-json-schema\` should support a defa
}
`;

exports[`\`default\` support in \`openapi-to-json-schema\` should support default 1`] = `
exports[`\`default\` support in \`openapi-to-json-schema\` > should support default 1`] = `
{
"properties": {
"allOf:array of primitives:default[example default]": {
Expand Down
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[`\`required\` support in \`openapi-to-json-schema\` should support complex cases of a nested \`required\` boolean 1`] = `
exports[`\`required\` support in \`openapi-to-json-schema\` > should support complex cases of a nested \`required\` boolean 1`] = `
{
"properties": {
"allOf:array of primitives:required[true]": {
Expand Down
2 changes: 2 additions & 0 deletions __tests__/lib/openapi-to-json-schema/default.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { SchemaObject } from '../../../src/rmoas.types';

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

import toJSONSchema from '../../../src/lib/openapi-to-json-schema';
import generateJSONSchemaFixture from '../../__fixtures__/json-schema';

Expand Down
2 changes: 2 additions & 0 deletions __tests__/lib/openapi-to-json-schema/required.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { SchemaObject } from '../../../src/rmoas.types';

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

import toJSONSchema from '../../../src/lib/openapi-to-json-schema';
import generateJSONSchemaFixture from '../../__fixtures__/json-schema';

Expand Down
1 change: 1 addition & 0 deletions __tests__/lib/reducer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import swagger from '@readme/oas-examples/2.0/json/petstore.json';
import parametersCommon from '@readme/oas-examples/3.0/json/parameters-common.json';
import petstore from '@readme/oas-examples/3.0/json/petstore.json';
import uspto from '@readme/oas-examples/3.0/json/uspto.json';
import { expect, describe, it } from 'vitest';

import reducer from '../../src/lib/reducer';
import complexNesting from '../__datasets__/complex-nesting.json';
Expand Down
1 change: 1 addition & 0 deletions __tests__/operation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type * as RMOAS from '../src/rmoas.types';

import petstoreSpec from '@readme/oas-examples/3.0/json/petstore.json';
import openapiParser from '@readme/openapi-parser';
import { beforeAll, describe, it, expect } from 'vitest';

import Oas, { Operation, Callback } from '../src';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`should return examples for multiple expressions and methods within a callback 1`] = `
[
Expand Down
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[`$ref quirks should retain $ref pointers in the schema even if they're circular 1`] = `
exports[`$ref quirks > should retain $ref pointers in the schema even if they're circular 1`] = `
[
{
"label": "Headers",
Expand Down Expand Up @@ -92,7 +92,7 @@ exports[`$ref quirks should retain $ref pointers in the schema even if they're c
]
`;

exports[`deprecated parameters should create deprecatedProps from body and metadata parameters 1`] = `
exports[`deprecated > parameters > should create deprecatedProps from body and metadata parameters 1`] = `
[
{
"deprecatedProps": {
Expand Down Expand Up @@ -415,7 +415,7 @@ https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-
]
`;

exports[`deprecated polymorphism should be able to merge enums within an allOf schema 1`] = `
exports[`deprecated > polymorphism > should be able to merge enums within an allOf schema 1`] = `
[
{
"label": "Body Params",
Expand Down Expand Up @@ -446,7 +446,7 @@ exports[`deprecated polymorphism should be able to merge enums within an allOf s
]
`;

exports[`deprecated polymorphism should pass through deprecated on a (merged) allOf schema 1`] = `
exports[`deprecated > polymorphism > should pass through deprecated on a (merged) allOf schema 1`] = `
[
{
"deprecatedProps": {
Expand Down Expand Up @@ -481,7 +481,7 @@ exports[`deprecated polymorphism should pass through deprecated on a (merged) al
]
`;

exports[`options mergeIntoBodyAndMetadata retainDeprecatedProperties (default behavior) should support merging \`deprecatedProps\` together 1`] = `
exports[`options > mergeIntoBodyAndMetadata > retainDeprecatedProperties (default behavior) > should support merging \`deprecatedProps\` together 1`] = `
[
{
"deprecatedProps": {
Expand Down Expand Up @@ -518,7 +518,7 @@ exports[`options mergeIntoBodyAndMetadata retainDeprecatedProperties (default be
]
`;

exports[`options mergeIntoBodyAndMetadata should merge params categorized as metadata into a single block 1`] = `
exports[`options > mergeIntoBodyAndMetadata > should merge params categorized as metadata into a single block 1`] = `
[
{
"label": "Metadata",
Expand Down Expand Up @@ -557,7 +557,7 @@ exports[`options mergeIntoBodyAndMetadata should merge params categorized as met
]
`;

exports[`parameters polymorphism should merge allOf schemas together 1`] = `
exports[`parameters > polymorphism > should merge allOf schemas together 1`] = `
[
{
"label": "Body Params",
Expand Down Expand Up @@ -614,7 +614,7 @@ exports[`parameters polymorphism should merge allOf schemas together 1`] = `
]
`;

exports[`parameters should convert parameters to JSON schema 1`] = `
exports[`parameters > should convert parameters to JSON schema 1`] = `
[
{
"label": "Path Params",
Expand Down Expand Up @@ -653,7 +653,7 @@ exports[`parameters should convert parameters to JSON schema 1`] = `
]
`;

exports[`polymorphism / discriminators should retain discriminator \`mapping\` refs when present 1`] = `
exports[`polymorphism / discriminators > should retain discriminator \`mapping\` refs when present 1`] = `
[
{
"label": "Body Params",
Expand Down Expand Up @@ -738,7 +738,7 @@ exports[`polymorphism / discriminators should retain discriminator \`mapping\` r
]
`;

exports[`request bodies should convert request bodies to JSON schema application/json 1`] = `
exports[`request bodies > should convert request bodies to JSON schema > application/json 1`] = `
[
{
"description": "Pet object that needs to be added to the store",
Expand Down Expand Up @@ -827,7 +827,7 @@ exports[`request bodies should convert request bodies to JSON schema application
]
`;

exports[`request bodies should convert request bodies to JSON schema application/x-www-form-urlencoded 1`] = `
exports[`request bodies > should convert request bodies to JSON schema > application/x-www-form-urlencoded 1`] = `
[
{
"label": "Path Params",
Expand Down Expand Up @@ -870,7 +870,7 @@ exports[`request bodies should convert request bodies to JSON schema application
]
`;

exports[`type sorting should return with a json schema for each parameter type (body instead of formData) 1`] = `
exports[`type sorting > should return with a json schema for each parameter type (body instead of formData) 1`] = `
[
{
"label": "Path Params",
Expand Down Expand Up @@ -945,7 +945,7 @@ exports[`type sorting should return with a json schema for each parameter type (
]
`;

exports[`type sorting should return with a json schema for each parameter type (formData instead of body) 1`] = `
exports[`type sorting > should return with a json schema for each parameter type (formData instead of body) 1`] = `
[
{
"label": "Path Params",
Expand Down
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[`quirks $ref quirks should retain $ref pointers in the schema even if they're circular 1`] = `
exports[`quirks > $ref quirks > should retain $ref pointers in the schema even if they're circular 1`] = `
[
{
"description": "OK",
Expand Down
2 changes: 2 additions & 0 deletions __tests__/operation/get-callback-examples.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { HttpMethods } from '../../src/rmoas.types';

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

import Oas from '../../src';

let operationExamples: Oas;
Expand Down
2 changes: 2 additions & 0 deletions __tests__/operation/get-parameters-as-json-schema.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { OperationObject, RequestBodyObject, SchemaObject } from '../../src/rmoas.types';

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

import Oas from '../../src';
import createOas from '../__fixtures__/create-oas';

Expand Down
2 changes: 2 additions & 0 deletions __tests__/operation/get-requestbody-examples.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { beforeAll, test, expect, it, describe } from 'vitest';

import Oas from '../../src';
import cleanStringify from '../__fixtures__/json-stringify-clean';

Expand Down
Loading