Skip to content

Commit

Permalink
fix: update deps
Browse files Browse the repository at this point in the history
BREAKING CHANGE: drop old node versions
  • Loading branch information
kentcdodds committed May 22, 2024
1 parent ebeecb4 commit 6bbad29
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 92 deletions.
24 changes: 11 additions & 13 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,24 @@ on:
- 'alpha'
- '!all-contributors/**'
pull_request: {}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
main:
# ignore all-contributors PRs
if: ${{ !contains(github.head_ref, 'all-contributors') }}
strategy:
matrix:
node: [12, 14, 16, 17]
node: [18, 20, 22]
runs-on: ubuntu-latest
steps:
- name: 🛑 Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.11.0

- name: ⬇️ Checkout repo
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: ⎔ Setup node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}

Expand All @@ -49,16 +50,13 @@ jobs:
contains('refs/heads/main,refs/heads/beta,refs/heads/next,refs/heads/alpha',
github.ref) && github.event_name == 'push' }}
steps:
- name: 🛑 Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.11.0

- name: ⬇️ Checkout repo
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: ⎔ Setup node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 16
node-version: 20

- name: 📥 Download deps
uses: bahmutov/npm-install@v1
Expand All @@ -69,7 +67,7 @@ jobs:
run: npm run build

- name: 🚀 Release
uses: cycjimmy/semantic-release-action@v3
uses: cycjimmy/semantic-release-action@v4
with:
semantic_version: 17
branches: |
Expand Down
6 changes: 0 additions & 6 deletions jest.config.js

This file was deleted.

23 changes: 12 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,25 @@
"build": "kcd-scripts build",
"lint": "kcd-scripts lint",
"setup": "npm install && npm run validate -s",
"test": "kcd-scripts test",
"test": "vitest test",
"test:update": "npm test -- --updateSnapshot --coverage",
"typecheck": "kcd-scripts typecheck",
"validate": "kcd-scripts validate"
},
"dependencies": {
"@babel/runtime": "^7.18.9",
"@types/make-fetch-happen": "^10.0.0",
"make-fetch-happen": "^10.2.0"
"@babel/runtime": "^7.24.5",
"@types/make-fetch-happen": "^10.0.4",
"make-fetch-happen": "^13.0.1"
},
"devDependencies": {
"@remark-embedder/core": "^3.0.0",
"@types/jest": "^28.1.6",
"kcd-scripts": "^12.2.0",
"msw": "^0.44.2",
"remark": "^14.0.2",
"remark-html": "^15.0.1",
"typescript": "^4.7.4"
"@remark-embedder/core": "^3.0.3",
"@vitest/coverage-v8": "^1.6.0",
"kcd-scripts": "^15.0.1",
"msw": "^2.3.0",
"remark": "^15.0.1",
"remark-html": "^16.0.1",
"typescript": "^5.4.5",
"vitest": "^1.6.0"
},
"peerDependencies": {
"@remark-embedder/core": "^3.0.0"
Expand Down
113 changes: 53 additions & 60 deletions src/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import remarkEmbedder from '@remark-embedder/core'
import {rest} from 'msw'
import type {RestRequest} from 'msw'
import {http, HttpResponse} from 'msw'
import {setupServer} from 'msw/node'
import {remark} from 'remark'
import remarkHTML from 'remark-html'
import {expect, test, beforeAll, afterEach, afterAll} from 'vitest'

import transformer from '../'
import type {Config} from '../'
import transformer, {type Config} from '../'

// this removes the quotes around strings...
const unquoteSerializer = {
Expand All @@ -17,44 +16,40 @@ const unquoteSerializer = {
expect.addSnapshotSerializer(unquoteSerializer)

const server = setupServer(
rest.get('https://oembed.com/providers.json', (req, res, ctx) =>
res(
ctx.json([
{
provider_name: 'Beautiful.AI',
provider_url: 'https://www.beautiful.ai',
endpoints: [
{
url: 'https://www.beautiful.ai/api/oembed',
// no scheme 😱
discovery: true,
},
],
},
{
provider_name: 'Twitter',
provider_url: 'http://www.twitter.com',
endpoints: [
{
schemes: [
'https://twitter.com/*/status/*',
'https://*.twitter.com/*/status/*',
'https://twitter.com/*/moments/*',
'https://*.twitter.com/*/moments/*',
],
url: 'https://publish.twitter.com/oembed',
},
],
},
]),
),
http.get('http://oembed.com/providers.json', () =>
HttpResponse.json([
{
provider_name: 'Beautiful.AI',
provider_url: 'http://www.beautiful.ai',
endpoints: [
{
url: 'http://www.beautiful.ai/api/oembed',
// no scheme 😱
discovery: true,
},
],
},
{
provider_name: 'Twitter',
provider_url: 'http://www.twitter.com',
endpoints: [
{
schemes: [
'http://twitter.com/*/status/*',
'http://*.twitter.com/*/status/*',
'http://twitter.com/*/moments/*',
'http://*.twitter.com/*/moments/*',
],
url: 'http://publish.twitter.com/oembed',
},
],
},
]),
),
rest.get('https://publish.twitter.com/oembed', (req, res, ctx) =>
res(
ctx.json({
html: '<blockquote class="twitter-tweet" data-dnt="true" data-theme="dark"><p lang="en" dir="ltr">I spent a few minutes working on this, just for you all. I promise, it wont disappoint. Though it may surprise 🎉<br><br>🙏 <a href="https://t.co/wgTJYYHOzD">https://t.co/wgTJYYHOzD</a></p>— Kent C. Dodds (@kentcdodds) <a href="https://twitter.com/kentcdodds/status/783161196945944580?ref_src=twsrc%5Etfw">October 4, 2016</a></blockquote>',
}),
),
http.get('http://publish.twitter.com/oembed', () =>
HttpResponse.json({
html: '<blockquote class="twitter-tweet" data-dnt="true" data-theme="dark"><p lang="en" dir="ltr">I spent a few minutes working on this, just for you all. I promise, it wont disappoint. Though it may surprise 🎉<br><br>🙏 <a href="http://t.co/wgTJYYHOzD">http://t.co/wgTJYYHOzD</a></p>— Kent C. Dodds (@kentcdodds) <a href="http://twitter.com/kentcdodds/status/783161196945944580?ref_src=twsrc%5Etfw">October 4, 2016</a></blockquote>',
}),
),
)

Expand All @@ -79,19 +74,19 @@ test('smoke test', async () => {
`
Here's a great tweet:
https://twitter.com/kentcdodds/status/783161196945944580
http://twitter.com/kentcdodds/status/783161196945944580
And here's an example of no provider:
https://example.com
http://example.com
`.trim(),
)

expect(result.toString()).toMatchInlineSnapshot(`
<p>Here's a great tweet:</p>
<blockquote class="twitter-tweet" data-dnt="true" data-theme="dark"><p lang="en" dir="ltr">I spent a few minutes working on this, just for you all. I promise, it wont disappoint. Though it may surprise 🎉<br><br>🙏 <a href="https://t.co/wgTJYYHOzD">https://t.co/wgTJYYHOzD</a></p>— Kent C. Dodds (@kentcdodds) <a href="https://twitter.com/kentcdodds/status/783161196945944580?ref_src=twsrc%5Etfw">October 4, 2016</a></blockquote>
<blockquote class="twitter-tweet" data-dnt="true" data-theme="dark"><p lang="en" dir="ltr">I spent a few minutes working on this, just for you all. I promise, it wont disappoint. Though it may surprise 🎉<br><br>🙏 <a href="http://t.co/wgTJYYHOzD">http://t.co/wgTJYYHOzD</a></p>— Kent C. Dodds (@kentcdodds) <a href="http://twitter.com/kentcdodds/status/783161196945944580?ref_src=twsrc%5Etfw">October 4, 2016</a></blockquote>
<p>And here's an example of no provider:</p>
<p>https://example.com</p>
<p>http://example.com</p>
`)
})

Expand All @@ -101,10 +96,10 @@ test('no config required', async () => {
transformers: [transformer],
})
.use(remarkHTML, {sanitize: false})
.process(`https://twitter.com/kentcdodds/status/783161196945944580`)
.process(`http://twitter.com/kentcdodds/status/783161196945944580`)

expect(result.toString()).toMatchInlineSnapshot(
`<blockquote class="twitter-tweet" data-dnt="true" data-theme="dark"><p lang="en" dir="ltr">I spent a few minutes working on this, just for you all. I promise, it wont disappoint. Though it may surprise 🎉<br><br>🙏 <a href="https://t.co/wgTJYYHOzD">https://t.co/wgTJYYHOzD</a></p>— Kent C. Dodds (@kentcdodds) <a href="https://twitter.com/kentcdodds/status/783161196945944580?ref_src=twsrc%5Etfw">October 4, 2016</a></blockquote>`,
`<blockquote class="twitter-tweet" data-dnt="true" data-theme="dark"><p lang="en" dir="ltr">I spent a few minutes working on this, just for you all. I promise, it wont disappoint. Though it may surprise 🎉<br><br>🙏 <a href="http://t.co/wgTJYYHOzD">http://t.co/wgTJYYHOzD</a></p>— Kent C. Dodds (@kentcdodds) <a href="http://twitter.com/kentcdodds/status/783161196945944580?ref_src=twsrc%5Etfw">October 4, 2016</a></blockquote>`,
)
})

Expand All @@ -117,10 +112,10 @@ test('config can be a function', async () => {
transformers: [[transformer, config]],
})
.use(remarkHTML, {sanitize: false})
.process(`https://twitter.com/kentcdodds/status/783161196945944580`)
.process(`http://twitter.com/kentcdodds/status/783161196945944580`)

expect(result.toString()).toMatchInlineSnapshot(
`<blockquote class="twitter-tweet" data-dnt="true" data-theme="dark"><p lang="en" dir="ltr">I spent a few minutes working on this, just for you all. I promise, it wont disappoint. Though it may surprise 🎉<br><br>🙏 <a href="https://t.co/wgTJYYHOzD">https://t.co/wgTJYYHOzD</a></p>— Kent C. Dodds (@kentcdodds) <a href="https://twitter.com/kentcdodds/status/783161196945944580?ref_src=twsrc%5Etfw">October 4, 2016</a></blockquote>`,
`<blockquote class="twitter-tweet" data-dnt="true" data-theme="dark"><p lang="en" dir="ltr">I spent a few minutes working on this, just for you all. I promise, it wont disappoint. Though it may surprise 🎉<br><br>🙏 <a href="http://t.co/wgTJYYHOzD">http://t.co/wgTJYYHOzD</a></p>— Kent C. Dodds (@kentcdodds) <a href="http://twitter.com/kentcdodds/status/783161196945944580?ref_src=twsrc%5Etfw">October 4, 2016</a></blockquote>`,
)
})

Expand All @@ -131,24 +126,22 @@ test('config function does not need to return anything', async () => {
transformers: [[transformer, config]],
})
.use(remarkHTML, {sanitize: false})
.process(`https://twitter.com/kentcdodds/status/783161196945944580`)
.process(`http://twitter.com/kentcdodds/status/783161196945944580`)

expect(result.toString()).toMatchInlineSnapshot(
`<blockquote class="twitter-tweet" data-dnt="true" data-theme="dark"><p lang="en" dir="ltr">I spent a few minutes working on this, just for you all. I promise, it wont disappoint. Though it may surprise 🎉<br><br>🙏 <a href="https://t.co/wgTJYYHOzD">https://t.co/wgTJYYHOzD</a></p>— Kent C. Dodds (@kentcdodds) <a href="https://twitter.com/kentcdodds/status/783161196945944580?ref_src=twsrc%5Etfw">October 4, 2016</a></blockquote>`,
`<blockquote class="twitter-tweet" data-dnt="true" data-theme="dark"><p lang="en" dir="ltr">I spent a few minutes working on this, just for you all. I promise, it wont disappoint. Though it may surprise 🎉<br><br>🙏 <a href="http://t.co/wgTJYYHOzD">http://t.co/wgTJYYHOzD</a></p>— Kent C. Dodds (@kentcdodds) <a href="http://twitter.com/kentcdodds/status/783161196945944580?ref_src=twsrc%5Etfw">October 4, 2016</a></blockquote>`,
)
})

test('sends the correct search params', async () => {
let request: RestRequest
let request: Request

server.use(
rest.get('https://publish.twitter.com/oembed', (req, res, ctx) => {
http.get('http://publish.twitter.com/oembed', ({request: req}) => {
request = req
return res(
ctx.json({
html: 'whatever',
}),
)
return HttpResponse.json({
html: 'whatever',
})
}),
)

Expand All @@ -162,10 +155,10 @@ test('sends the correct search params', async () => {
],
})
.use(remarkHTML, {sanitize: false})
.process(`https://twitter.com/kentcdodds/status/783161196945944580`)
.process(`http://twitter.com/kentcdodds/status/783161196945944580`)

// @ts-expect-error it doesn't think request will be assigned by now... But it will!
expect(request.url.toString()).toMatchInlineSnapshot(
`https://publish.twitter.com/oembed?url=https%3A%2F%2Ftwitter.com%2Fkentcdodds%2Fstatus%2F783161196945944580&dnt=true&omit_script=true&theme=dark&format=json`,
`http://publish.twitter.com/oembed?url=http%3A%2F%2Ftwitter.com%2Fkentcdodds%2Fstatus%2F783161196945944580&dnt=true&omit_script=true&theme=dark&format=json`,
)
})
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path'
import {URL} from 'url'
import type {Transformer} from '@remark-embedder/core'
import {type Transformer} from '@remark-embedder/core'
import fetch from 'make-fetch-happen'

fetch.defaults({
Expand Down Expand Up @@ -28,7 +28,7 @@ declare namespace getProviders {

async function getProviders(): Promise<Providers> {
if (!getProviders.cache) {
const res = await fetch('https://oembed.com/providers.json')
const res = await fetch('http://oembed.com/providers.json')
getProviders.cache = (await res.json()) as Providers
}

Expand Down
9 changes: 9 additions & 0 deletions vitest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// <reference types="vitest" />
/// <reference types="vite/client" />

module.exports = {
test: {
include: ['**/__tests__/**.ts'],
environment: 'node',
},
}

0 comments on commit 6bbad29

Please sign in to comment.