Skip to content

Commit

Permalink
Merge branch 'next' into run-ts-checks-on-bin-scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
kanadgupta authored Nov 6, 2023
2 parents baa0dfc + 6497ca0 commit dc9f808
Show file tree
Hide file tree
Showing 17 changed files with 1,813 additions and 1,174 deletions.
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
}
]
}
]
],

// This rule is only really applicable for OSS libraries and doesn't apply to rdme's case.
"readme/no-dual-exports": "off"
}
}
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ updates:
labels:
- dependencies
groups:
minor-developent-deps:
minor-development-deps:
dependency-type: 'development'
update-types:
- minor
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: npm
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
fetch-depth: 0
token: ${{ secrets.RELEASE_GH_TOKEN }}

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 18
cache: 'npm'
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<!-- prettier-ignore-start -->
> [!WARNING]
> **These docs are for [the forthcoming `v9` release](https://github.com/readmeio/rdme/issues/801).** You can view the docs for the current release (`v8`) [here](https://github.com/readmeio/rdme/tree/v8#readme).
<!-- prettier-ignore-end -->
[![rdme](https://user-images.githubusercontent.com/8854718/195465739-0f0f83d5-2e18-4e6c-96ae-944e3bb6880a.png)](https://readme.com)

<p align="center">
Expand Down
28 changes: 14 additions & 14 deletions __tests__/cmds/openapi/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import fs from 'node:fs';

import chalk from 'chalk';
import { rest } from 'msw';
import { http } from 'msw';
import { setupServer } from 'msw/node';
import nock from 'nock';
import prompts from 'prompts';
Expand Down Expand Up @@ -1361,23 +1361,23 @@ describe('rdme openapi', () => {

server.use(
...[
rest.post(`${config.host}/api/v1/api-registry`, async (req, res, ctx) => {
const body = await req.text();
http.post(`${config.host}/api/v1/api-registry`, async ({ request }) => {
const body = await request.text();
expect(body).toMatch('form-data; name="spec"');
return res(ctx.status(201), ctx.json({ registryUUID }));
return Response.json({ registryUUID }, { status: 201 });
}),
rest.get(spec, (req, res, ctx) => {
return res(ctx.status(200), ctx.json(petstoreWeird));
http.get(spec, () => {
return Response.json(petstoreWeird, { status: 200 });
}),
rest.put(`${config.host}/api/v1/api-specification/${id}`, async (req, res, ctx) => {
expect(req.headers.get('authorization')).toBeBasicAuthApiKey(key);
expect(req.headers.get('x-rdme-ci')).toBe('GitHub Actions (test)');
expect(req.headers.get('x-readme-source')).toBe('cli-gh');
expect(req.headers.get('x-readme-source-url')).toBe(spec);
expect(req.headers.get('x-readme-version')).toBe(version);
const body = await req.json();
http.put(`${config.host}/api/v1/api-specification/${id}`, async ({ request }) => {
expect(request.headers.get('authorization')).toBeBasicAuthApiKey(key);
expect(request.headers.get('x-rdme-ci')).toBe('GitHub Actions (test)');
expect(request.headers.get('x-readme-source')).toBe('cli-gh');
expect(request.headers.get('x-readme-source-url')).toBe(spec);
expect(request.headers.get('x-readme-version')).toBe(version);
const body = await request.json();
expect(body).toStrictEqual({ registryUUID });
return res(ctx.status(201), ctx.set('location', exampleRefLocation), ctx.json({ _id: 1 }));
return Response.json({ _id: 1 }, { status: 201, headers: { location: exampleRefLocation } });
}),
],
);
Expand Down
15 changes: 7 additions & 8 deletions __tests__/helpers/get-api-mock.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { ResponseTransformer } from 'msw';
import type { Headers } from 'node-fetch';

import { rest } from 'msw';
import { http } from 'msw';
import nock from 'nock';

import config from '../../src/lib/config.js';
Expand Down Expand Up @@ -76,17 +75,17 @@ export function getAPIMockMSW(
expectedReqHeaders: ReqHeaders = {},
proxy = '',
) {
return rest.get(`${proxy}${config.host}${path}`, (req, res, ctx) => {
return http.get(`${proxy}${config.host}${path}`, ({ request }) => {
try {
// @ts-expect-error once we move off node-fetch, we can make these types consistent
validateHeaders(req.headers, basicAuthUser, expectedReqHeaders);
let responseTransformer: ResponseTransformer;
validateHeaders(request.headers, basicAuthUser, expectedReqHeaders);
let httpResponse = new Response(null, { status });
if (response?.json) {
responseTransformer = ctx.json(response.json);
httpResponse = Response.json(response.json, { status });
} else if (response?.text) {
responseTransformer = ctx.text(response.text);
httpResponse = new Response(response.text, { status });
}
return res(ctx.status(status), responseTransformer);
return httpResponse;
} catch (e) {
throw new Error(`Error mocking GET request to https://dash.readme.com${path}: ${e.message}`);
}
Expand Down
73 changes: 5 additions & 68 deletions __tests__/helpers/github-workflow-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -363,79 +363,15 @@
"runs-on": {
"$comment": "https://help.github.com/en/github/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#jobsjob_idruns-on",
"description": "The type of machine to run the job on. The machine can be either a GitHub-hosted runner, or a self-hosted runner.",
"oneOf": [
"anyOf": [
{
"$comment": "https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#github-hosted-runners",
"type": "string",
"enum": [
"macos-10.15",
"macos-11",
"macos-12",
"macos-12-xl",
"macos-13",
"macos-13-xl",
"macos-latest",
"macos-latest-xl",
"self-hosted",
"ubuntu-18.04",
"ubuntu-20.04",
"ubuntu-22.04",
"ubuntu-latest",
"ubuntu-latest-4-cores",
"ubuntu-latest-8-cores",
"ubuntu-latest-16-cores",
"windows-2019",
"windows-2022",
"windows-latest",
"windows-latest-8-cores"
]
"type": "string"
},
{
"$comment": "https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#self-hosted-runners",
"type": "array",
"anyOf": [
{ "items": [{ "const": "self-hosted" }], "minItems": 1, "additionalItems": { "type": "string" } },
{
"items": [{ "const": "self-hosted" }, { "$ref": "#/definitions/machine" }],
"minItems": 2,
"additionalItems": { "type": "string" }
},
{
"items": [{ "const": "self-hosted" }, { "$ref": "#/definitions/architecture" }],
"minItems": 2,
"additionalItems": { "type": "string" }
},
{
"items": [
{ "const": "self-hosted" },
{ "$ref": "#/definitions/machine" },
{ "$ref": "#/definitions/architecture" }
],
"minItems": 3,
"additionalItems": { "type": "string" }
},
{
"items": [
{ "const": "self-hosted" },
{ "$ref": "#/definitions/architecture" },
{ "$ref": "#/definitions/machine" }
],
"minItems": 3,
"additionalItems": { "type": "string" }
},
{
"items": [{ "const": "linux" }],
"minItems": 2,
"maxItems": 2,
"additionalItems": { "type": "string" }
},
{
"items": [{ "const": "windows" }],
"minItems": 2,
"maxItems": 2,
"additionalItems": { "type": "string" }
}
]
"anyOf": [{ "items": [{ "type": "string" }], "minItems": 1 }]
},
{
"$comment": "https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#choosing-runners-in-a-group",
Expand All @@ -445,7 +381,8 @@
"labels": { "oneOf": [{ "type": "string" }, { "type": "array", "items": { "type": "string" } }] }
}
},
{ "$ref": "#/definitions/stringContainingExpressionSyntax" }
{ "$ref": "#/definitions/stringContainingExpressionSyntax" },
{ "$ref": "#/definitions/expressionSyntax" }
]
},
"environment": {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/lib/analyzeOas.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { OASDocument } from 'oas/rmoas.types';
import type { OASDocument } from 'oas/types';

import petstore from '@readme/oas-examples/3.0/json/petstore.json' assert { type: 'json' };
import { describe, it, expect } from 'vitest';
Expand Down
72 changes: 36 additions & 36 deletions __tests__/single-threaded/openapi/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import fs from 'node:fs';

import chalk from 'chalk';
import { rest } from 'msw';
import { http } from 'msw';
import { setupServer } from 'msw/node';
import prompts from 'prompts';
import { describe, beforeAll, beforeEach, afterEach, it, expect, vi, afterAll } from 'vitest';
Expand Down Expand Up @@ -73,17 +73,17 @@ describe('rdme openapi (single-threaded)', () => {
server.use(
...[
getAPIMockMSW(`/api/v1/version/${version}`, 200, { json: { version } }, key),
rest.post(`${config.host}/api/v1/api-registry`, async (req, res, ctx) => {
const body = await req.text();
http.post(`${config.host}/api/v1/api-registry`, async ({ request }) => {
const body = await request.text();
expect(body).toMatch('form-data; name="spec"');
return res(ctx.status(201), ctx.json({ registryUUID, spec: { openapi: '3.0.0' } }));
return Response.json({ registryUUID, spec: { openapi: '3.0.0' } }, { status: 201 });
}),
getAPIMockMSW('/api/v1/api-specification', 200, { json: [] }, key, { 'x-readme-version': version }),
rest.post(`${config.host}/api/v1/api-specification`, async (req, res, ctx) => {
const body = await req.json();
http.post(`${config.host}/api/v1/api-specification`, async ({ request }) => {
const body = await request.json();
expect(body).toStrictEqual({ registryUUID });
expect(req.headers.get('authorization')).toBeBasicAuthApiKey(key);
return res(ctx.status(201), ctx.set('location', exampleRefLocation), ctx.json({ _id: 1 }));
expect(request.headers.get('authorization')).toBeBasicAuthApiKey(key);
return Response.json({ _id: 1 }, { status: 201, headers: { location: exampleRefLocation } });
}),
],
);
Expand Down Expand Up @@ -112,19 +112,19 @@ describe('rdme openapi (single-threaded)', () => {
server.use(
...[
getAPIMockMSW(`/api/v1/version/${version}`, 200, { json: { version } }, key),
rest.post(`${config.host}/api/v1/api-registry`, async (req, res, ctx) => {
const body = await req.text();
http.post(`${config.host}/api/v1/api-registry`, async ({ request }) => {
const body = await request.text();
requestBody = body.substring(body.indexOf('{'), body.lastIndexOf('}') + 1);
requestBody = JSON.parse(requestBody);
expect(body).toMatch('form-data; name="spec"');
return res(ctx.status(201), ctx.json({ registryUUID, spec: { openapi: '3.0.0' } }));
return Response.json({ registryUUID, spec: { openapi: '3.0.0' } }, { status: 201 });
}),
getAPIMockMSW('/api/v1/api-specification', 200, { json: [] }, key, { 'x-readme-version': version }),
rest.post(`${config.host}/api/v1/api-specification`, async (req, res, ctx) => {
const body = await req.json();
http.post(`${config.host}/api/v1/api-specification`, async ({ request }) => {
const body = await request.json();
expect(body).toStrictEqual({ registryUUID });
expect(req.headers.get('authorization')).toBeBasicAuthApiKey(key);
return res(ctx.status(201), ctx.set('location', exampleRefLocation), ctx.json({ _id: 1 }));
expect(request.headers.get('authorization')).toBeBasicAuthApiKey(key);
return Response.json({ _id: 1 }, { status: 201, headers: { location: exampleRefLocation } });
}),
],
);
Expand Down Expand Up @@ -152,10 +152,10 @@ describe('rdme openapi (single-threaded)', () => {
server.use(
...[
getAPIMockMSW(`/api/v1/version/${version}`, 200, { json: { version } }, key),
rest.post(`${config.host}/api/v1/api-registry`, async (req, res, ctx) => {
const body = await req.text();
http.post(`${config.host}/api/v1/api-registry`, async ({ request }) => {
const body = await request.text();
expect(body).toMatch('form-data; name="spec"');
return res(ctx.status(201), ctx.json({ registryUUID, spec: { openapi: '3.0.0' } }));
return Response.json({ registryUUID, spec: { openapi: '3.0.0' } }, { status: 201 });
}),
getAPIMockMSW('/api/v1/api-specification', 200, { json: [] }, key, { 'x-readme-version': version }),
],
Expand Down Expand Up @@ -211,17 +211,17 @@ describe('rdme openapi (single-threaded)', () => {
server.use(
...[
getAPIMockMSW(`/api/v1/version/${version}`, 200, { json: { version } }, key),
rest.post(`${config.host}/api/v1/api-registry`, async (req, res, ctx) => {
const body = await req.text();
http.post(`${config.host}/api/v1/api-registry`, async ({ request }) => {
const body = await request.text();
expect(body).toMatch('form-data; name="spec"');
return res(ctx.status(201), ctx.json({ registryUUID, spec: { openapi: '3.0.0' } }));
return Response.json({ registryUUID, spec: { openapi: '3.0.0' } }, { status: 201 });
}),
getAPIMockMSW('/api/v1/api-specification', 200, { json: [] }, key, { 'x-readme-version': version }),
rest.post(`${config.host}/api/v1/api-specification`, async (req, res, ctx) => {
expect(req.headers.get('authorization')).toBeBasicAuthApiKey(key);
const body = await req.json();
http.post(`${config.host}/api/v1/api-specification`, async ({ request }) => {
expect(request.headers.get('authorization')).toBeBasicAuthApiKey(key);
const body = await request.json();
expect(body).toStrictEqual({ registryUUID });
return res(ctx.status(201), ctx.set('location', exampleRefLocation), ctx.json({ _id: 1 }));
return Response.json({ _id: 1 }, { status: 201, headers: { location: exampleRefLocation } });
}),
],
);
Expand Down Expand Up @@ -260,23 +260,23 @@ describe('rdme openapi (single-threaded)', () => {
server.use(
...[
getAPIMockMSW(`/api/v1/version/${version}`, 200, { json: { version } }, key),
rest.post(`${config.host}/api/v1/api-registry`, async (req, res, ctx) => {
const body = await req.text();
http.post(`${config.host}/api/v1/api-registry`, async ({ request }) => {
const body = await request.text();
expect(body).toMatch('form-data; name="spec"');
return res(ctx.status(201), ctx.json({ registryUUID, spec: { openapi: '3.0.0' } }));
return Response.json({ registryUUID, spec: { openapi: '3.0.0' } }, { status: 201 });
}),
getAPIMockMSW('/api/v1/api-specification', 200, { json: [] }, key, { 'x-readme-version': version }),
rest.post(`${config.host}/api/v1/api-specification`, async (req, res, ctx) => {
expect(req.headers.get('authorization')).toBeBasicAuthApiKey(key);
expect(req.headers.get('x-rdme-ci')).toBe('GitHub Actions (test)');
expect(req.headers.get('x-readme-source')).toBe('cli-gh');
expect(req.headers.get('x-readme-source-url')).toBe(
http.post(`${config.host}/api/v1/api-specification`, async ({ request }) => {
expect(request.headers.get('authorization')).toBeBasicAuthApiKey(key);
expect(request.headers.get('x-rdme-ci')).toBe('GitHub Actions (test)');
expect(request.headers.get('x-readme-source')).toBe('cli-gh');
expect(request.headers.get('x-readme-source-url')).toBe(
'https://github.com/octocat/Hello-World/blob/ffac537e6cbbf934b08745a378932722df287a53/__tests__/__fixtures__/relative-ref-oas/petstore.json',
);
expect(req.headers.get('x-readme-version')).toBe(version);
const body = await req.json();
expect(request.headers.get('x-readme-version')).toBe(version);
const body = await request.json();
expect(body).toStrictEqual({ registryUUID });
return res(ctx.status(201), ctx.set('location', exampleRefLocation), ctx.json({ _id: 1 }));
return Response.json({ _id: 1 }, { status: 201, headers: { location: exampleRefLocation } });
}),
],
);
Expand Down
Loading

0 comments on commit dc9f808

Please sign in to comment.