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

Commit

Permalink
feat: dropping support for node 14 and 16 (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
erunion authored Sep 12, 2023
1 parent e983c3f commit 5e0933f
Show file tree
Hide file tree
Showing 7 changed files with 557 additions and 147 deletions.
4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

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

"no-case-declarations": "off"
"no-case-declarations": "off",

"unicorn/prefer-node-protocol": "error"
}
}
5 changes: 0 additions & 5 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,3 @@ updates:
update-types:
- minor
- patch
ignore:
# node-fetch is now an ESM package and can't be used here without a rewrite.
- dependency-name: node-fetch
versions:
- ">= 3"
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ jobs:
strategy:
matrix:
node-version:
- 16
- 18
- 20

Expand Down
33 changes: 17 additions & 16 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { OpenAPIV3 } from 'openapi-types';

import fs from 'fs';
import path from 'path';
import fs from 'node:fs';
import path from 'node:path';

import nock from 'nock';
import { describe, beforeAll, beforeEach, it, expect } from 'vitest';
import fetchMock from 'fetch-mock';
import { describe, afterEach, beforeAll, beforeEach, it, expect } from 'vitest';

import OASNormalize, { getAPIDefinitionType, isAPIDefinition } from '../src';
import { isOpenAPI, isPostman, isSwagger } from '../src/lib/utils';
Expand Down Expand Up @@ -54,30 +54,29 @@ describe('#load', () => {
});

describe('urls', () => {
afterEach(() => {
fetchMock.restore();
});

it('should support URLs', async () => {
const mock = nock('http://example.com').get(`/api-${version}.json`).reply(200, json);
fetchMock.get(`http://example.com/api-${version}.json`, json);
const o = new OASNormalize(`http://example.com/api-${version}.json`);

await expect(o.load()).resolves.toStrictEqual(json);
mock.done();
});

it('should support HTTPS URLs', async () => {
const mock = nock('https://example.com').get(`/api-${version}.json`).reply(200, json);
fetchMock.get(`https://example.com/api-${version}.json`, json);
const o = new OASNormalize(`https://example.com/api-${version}.json`);

await expect(o.load()).resolves.toStrictEqual(json);
mock.done();
});

it('should convert GitHub repo URLs to raw URLs', async () => {
const mock = nock('https://raw.githubusercontent.com')
.get('/readmeio/oas-examples/main/3.0/json/petstore.json')
.reply(200, json);
fetchMock.get('https://raw.githubusercontent.com/readmeio/oas-examples/main/3.0/json/petstore.json', json);
const o = new OASNormalize('https://github.com/readmeio/oas-examples/blob/main/3.0/json/petstore.json');

await expect(o.load()).resolves.toStrictEqual(json);
mock.done();
});
});

Expand Down Expand Up @@ -284,14 +283,17 @@ describe('#validate', () => {
['OpenAPI 3.0', '3.0'],
['OpenAPI 3.1', '3.1'],
])('%s support', (_, version) => {
afterEach(() => {
fetchMock.restore();
});

it('should validate a URL hosting JSON as expected', async () => {
const json = await import(`@readme/oas-examples/${version}/json/petstore.json`).then(r => r.default);

const mock = nock('http://example.com').get(`/api-${version}.json`).reply(200, cloneObject(json));
fetchMock.get(`http://example.com/api-${version}.json`, cloneObject(json));
const o = new OASNormalize(`http://example.com/api-${version}.json`);

await expect(o.validate({ convertToLatest: true })).resolves.toMatchSnapshot();
mock.done();
});

it('should validate a JSON path as expected', async () => {
Expand All @@ -304,11 +306,10 @@ describe('#validate', () => {

it('should validate a URL hosting YAML as expected', async () => {
const yaml = fs.readFileSync(require.resolve(`@readme/oas-examples/${version}/yaml/petstore.yaml`), 'utf8');
const mock = nock('http://example.com').get(`/api-${version}.yaml`).reply(200, yaml);
fetchMock.get(`http://example.com/api-${version}.yaml`, yaml);
const o = new OASNormalize(`http://example.com/api-${version}.yaml`);

await expect(o.validate({ convertToLatest: true })).resolves.toMatchSnapshot();
mock.done();
});

it('should validate a YAML path as expected', async () => {
Expand Down
Loading

0 comments on commit 5e0933f

Please sign in to comment.