Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.

Commit

Permalink
refactor(test): moving tests over to vitest (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
erunion authored Aug 13, 2023
1 parent ce018d6 commit b53dc45
Show file tree
Hide file tree
Showing 9 changed files with 7,575 additions and 12,767 deletions.
9 changes: 0 additions & 9 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
{
"extends": [
"@readme/eslint-config",
"@readme/eslint-config/docs",
"@readme/eslint-config/typescript"
],
"plugins": ["jsdoc"],
"root": true,
"rules": {
"@typescript-eslint/no-explicit-any": "off",

"camelcase": ["error", { "allow": ["OpenAPIV3_1"] }],

"jsdoc/require-jsdoc": "error",
"jsdoc/require-param": "off",
"jsdoc/require-param-type": "off",
"jsdoc/require-returns": "off",
"jsdoc/require-returns-type": "off",
"jsdoc/tag-lines": "off",

"no-case-declarations": "off"
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import OASNormalize from 'oas-normalize';
// const { default: OASNormalize } = require('oas-normalize'); // If you're using CJS.

const oas = new OASNormalize(
'https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore-expanded.yaml'
'https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore-expanded.yaml',
// ...or a string, path, JSON blob, whatever you've got.
);

Expand Down
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": {
"jsdoc/require-jsdoc": "off"
}
"extends": "@readme/eslint-config/testing/vitest"
}
30 changes: 15 additions & 15 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[`#validate OpenAPI 3.0 support should validate a JSON path as expected 1`] = `
exports[`#validate > OpenAPI 3.0 support > should validate a JSON path as expected 1`] = `
{
"components": {
"requestBodies": {
Expand Down Expand Up @@ -1072,7 +1072,7 @@ exports[`#validate OpenAPI 3.0 support should validate a JSON path as expected 1
}
`;

exports[`#validate OpenAPI 3.0 support should validate a URL hosting JSON as expected 1`] = `
exports[`#validate > OpenAPI 3.0 support > should validate a URL hosting JSON as expected 1`] = `
{
"components": {
"requestBodies": {
Expand Down Expand Up @@ -2144,7 +2144,7 @@ exports[`#validate OpenAPI 3.0 support should validate a URL hosting JSON as exp
}
`;

exports[`#validate OpenAPI 3.0 support should validate a URL hosting YAML as expected 1`] = `
exports[`#validate > OpenAPI 3.0 support > should validate a URL hosting YAML as expected 1`] = `
{
"components": {
"requestBodies": {
Expand Down Expand Up @@ -3216,7 +3216,7 @@ exports[`#validate OpenAPI 3.0 support should validate a URL hosting YAML as exp
}
`;

exports[`#validate OpenAPI 3.0 support should validate a YAML path as expected 1`] = `
exports[`#validate > OpenAPI 3.0 support > should validate a YAML path as expected 1`] = `
{
"components": {
"requestBodies": {
Expand Down Expand Up @@ -4288,7 +4288,7 @@ exports[`#validate OpenAPI 3.0 support should validate a YAML path as expected 1
}
`;

exports[`#validate OpenAPI 3.1 support should validate a JSON path as expected 1`] = `
exports[`#validate > OpenAPI 3.1 support > should validate a JSON path as expected 1`] = `
{
"components": {
"requestBodies": {
Expand Down Expand Up @@ -5355,7 +5355,7 @@ exports[`#validate OpenAPI 3.1 support should validate a JSON path as expected 1
}
`;

exports[`#validate OpenAPI 3.1 support should validate a URL hosting JSON as expected 1`] = `
exports[`#validate > OpenAPI 3.1 support > should validate a URL hosting JSON as expected 1`] = `
{
"components": {
"requestBodies": {
Expand Down Expand Up @@ -6422,7 +6422,7 @@ exports[`#validate OpenAPI 3.1 support should validate a URL hosting JSON as exp
}
`;

exports[`#validate OpenAPI 3.1 support should validate a URL hosting YAML as expected 1`] = `
exports[`#validate > OpenAPI 3.1 support > should validate a URL hosting YAML as expected 1`] = `
{
"components": {
"requestBodies": {
Expand Down Expand Up @@ -7489,7 +7489,7 @@ exports[`#validate OpenAPI 3.1 support should validate a URL hosting YAML as exp
}
`;

exports[`#validate OpenAPI 3.1 support should validate a YAML path as expected 1`] = `
exports[`#validate > OpenAPI 3.1 support > should validate a YAML path as expected 1`] = `
{
"components": {
"requestBodies": {
Expand Down Expand Up @@ -8556,7 +8556,7 @@ exports[`#validate OpenAPI 3.1 support should validate a YAML path as expected 1
}
`;

exports[`#validate Postman support should support converting a Postman collection to OpenAPI (validating it in the process) 1`] = `
exports[`#validate > Postman support > should support converting a Postman collection to OpenAPI (validating it in the process) 1`] = `
{
"components": {
"securitySchemes": {
Expand Down Expand Up @@ -10252,7 +10252,7 @@ Contact Support:
}
`;

exports[`#validate Swagger 2.0 support should validate a JSON path as expected 1`] = `
exports[`#validate > Swagger 2.0 support > should validate a JSON path as expected 1`] = `
{
"components": {
"requestBodies": {
Expand Down Expand Up @@ -11317,7 +11317,7 @@ exports[`#validate Swagger 2.0 support should validate a JSON path as expected 1
}
`;

exports[`#validate Swagger 2.0 support should validate a URL hosting JSON as expected 1`] = `
exports[`#validate > Swagger 2.0 support > should validate a URL hosting JSON as expected 1`] = `
{
"components": {
"requestBodies": {
Expand Down Expand Up @@ -12382,7 +12382,7 @@ exports[`#validate Swagger 2.0 support should validate a URL hosting JSON as exp
}
`;

exports[`#validate Swagger 2.0 support should validate a URL hosting YAML as expected 1`] = `
exports[`#validate > Swagger 2.0 support > should validate a URL hosting YAML as expected 1`] = `
{
"components": {
"requestBodies": {
Expand Down Expand Up @@ -13447,7 +13447,7 @@ exports[`#validate Swagger 2.0 support should validate a URL hosting YAML as exp
}
`;

exports[`#validate Swagger 2.0 support should validate a YAML path as expected 1`] = `
exports[`#validate > Swagger 2.0 support > should validate a YAML path as expected 1`] = `
{
"components": {
"requestBodies": {
Expand Down Expand Up @@ -14512,7 +14512,7 @@ exports[`#validate Swagger 2.0 support should validate a YAML path as expected 1
}
`;

exports[`#validate should error out, and show all errors, when a definition has lots of problems 1`] = `
exports[`#validate > should error out, and show all errors, when a definition has lots of problems 1`] = `
[SyntaxError: OpenAPI schema validation failed.
REQUIRED must have required property 'url'
Expand Down
13 changes: 7 additions & 6 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import fs from 'fs';
import path from 'path';

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

import OASNormalize, { getAPIDefinitionType, isAPIDefinition } from '../src';
import { isOpenAPI, isPostman, isSwagger } from '../src/lib/utils';
Expand Down Expand Up @@ -103,7 +104,7 @@ describe('#load', () => {
// eslint-disable-next-line camelcase
_postman_id: '0b2e8577-2899-4229-bb1c-4cb031108c2f',
}),
})
}),
);
});
});
Expand Down Expand Up @@ -246,7 +247,7 @@ describe('#validate', () => {
expect.objectContaining({
message: expect.stringContaining("REQUIRED must have required property 'name'"),
details: expect.any(Array),
})
}),
);
});

Expand Down Expand Up @@ -332,14 +333,14 @@ describe('#validate', () => {
describe('#version', () => {
it('should detect an OpenAPI definition', async () => {
await expect(
new OASNormalize(require.resolve('@readme/oas-examples/3.0/json/petstore.json'), { enablePaths: true }).version()
new OASNormalize(require.resolve('@readme/oas-examples/3.0/json/petstore.json'), { enablePaths: true }).version(),
).resolves.toStrictEqual({
specification: 'openapi',
version: '3.0.0',
});

await expect(
new OASNormalize(require.resolve('@readme/oas-examples/3.1/json/petstore.json'), { enablePaths: true }).version()
new OASNormalize(require.resolve('@readme/oas-examples/3.1/json/petstore.json'), { enablePaths: true }).version(),
).resolves.toStrictEqual({
specification: 'openapi',
version: '3.1.0',
Expand All @@ -350,7 +351,7 @@ describe('#version', () => {
await expect(
new OASNormalize(require.resolve('./__fixtures__/postman/petstore.collection.json'), {
enablePaths: true,
}).version()
}).version(),
).resolves.toStrictEqual({
specification: 'postman',
version: '2.1.0',
Expand All @@ -359,7 +360,7 @@ describe('#version', () => {

it('should detect a Swagger definition', async () => {
await expect(
new OASNormalize(require.resolve('@readme/oas-examples/2.0/json/petstore.json'), { enablePaths: true }).version()
new OASNormalize(require.resolve('@readme/oas-examples/2.0/json/petstore.json'), { enablePaths: true }).version(),
).resolves.toStrictEqual({
specification: 'swagger',
version: '2.0',
Expand Down
17 changes: 0 additions & 17 deletions jest.config.js

This file was deleted.

Loading

0 comments on commit b53dc45

Please sign in to comment.