Skip to content

Commit d07868b

Browse files
committed
Update test & CI scripts
1 parent 2652acf commit d07868b

File tree

8 files changed

+65
-78
lines changed

8 files changed

+65
-78
lines changed

.github/workflows/ci-test.yml

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212

1313
strategy:
1414
matrix:
15-
node_version: [20.x, 22.x, 23.x]
15+
node_version: [20.x, 22.x, 24.x]
1616

1717
steps:
1818
- uses: actions/checkout@v4
@@ -24,38 +24,17 @@ jobs:
2424

2525
- name: run npm scripts
2626
env:
27-
FACEBOOK_APP_ID: ${{ secrets.FACEBOOK_APP_ID }}
28-
FACEBOOK_CLIENT_TOKEN: ${{ secrets.FACEBOOK_CLIENT_TOKEN }}
2927
PROXY_SERVER: ${{ secrets.PROXY_SERVER }}
3028
run: |
3129
npm install
3230
npm run lint
3331
npm run build --if-present
3432
npm run test
3533
36-
- name: Coveralls Parallel
37-
uses: coverallsapp/github-action@v2
38-
with:
39-
flag-name: run-${{ join(matrix.*, '-') }}
40-
parallel: true
41-
github-token: ${{ secrets.GITHUB_TOKEN }}
42-
4334
- name: cache node modules
4435
uses: actions/cache@v4
4536
with:
4637
path: ~/.npm
4738
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
4839
restore-keys: |
4940
${{ runner.os }}-node-
50-
51-
finish:
52-
needs: test
53-
if: ${{ always() }}
54-
runs-on: ubuntu-latest
55-
steps:
56-
- name: Coveralls Finished
57-
uses: coverallsapp/github-action@v2
58-
with:
59-
parallel-finished: true
60-
carryforward: "run-20.x,run-22.x,run-23.x"
61-

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ Extract oEmbed content from given URL.
66
[![NPM](https://badge.fury.io/js/@extractus%2Foembed-extractor.svg)](https://badge.fury.io/js/@extractus%2Foembed-extractor)
77
![CodeQL](https://github.com/extractus/oembed-extractor/workflows/CodeQL/badge.svg)
88
[![CI test](https://github.com/extractus/oembed-extractor/workflows/ci-test/badge.svg)](https://github.com/extractus/oembed-extractor/actions)
9-
[![Coverage Status](https://coveralls.io/repos/github/extractus/oembed-extractor/badge.svg)](https://coveralls.io/github/extractus/oembed-extractor)
109

1110
## Demo
1211

@@ -45,9 +44,6 @@ import { extract } from 'npm:@extractus/oembed-extractor'
4544
import { extract } from "https://esm.sh/@extractus/oembed-extractor@latest"
4645
```
4746

48-
Please check [the examples](examples) for reference.
49-
50-
5147
## APIs
5248

5349
### `.extract()`

src/main.test.js

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
// main
2-
/* eslint-env jest */
1+
// main.test
2+
3+
import { describe, it } from 'node:test'
4+
import assert from 'node:assert'
35

46
import { HttpsProxyAgent } from 'https-proxy-agent'
57

@@ -93,11 +95,11 @@ describe('test extract(bad url)', () => {
9395
]
9496

9597
badSamples.forEach((url) => {
96-
test(`testing extract bad url "${url}"`, async () => {
98+
it(`testing extract bad url "${url}"`, async () => {
9799
try {
98100
await extract(url)
99101
} catch (err) {
100-
expect(err).toBeTruthy()
102+
assert.ok(err)
101103
}
102104
})
103105
})
@@ -168,7 +170,7 @@ describe('test if extract() with some popular providers', () => {
168170

169171
cases.forEach(({ input, expected, checkFn }) => {
170172
const { url, file, params = {} } = input
171-
test(`check fetchEmbed("${url}")`, async () => {
173+
it(`check fetchEmbed("${url}")`, async () => {
172174
const provider = findProvider(url)
173175
const { baseUrl, path } = parseUrl(provider.endpoint)
174176

@@ -190,15 +192,15 @@ describe('test if extract() with some popular providers', () => {
190192
} = params
191193

192194
const result = await extract(url, { maxwidth, maxheight })
193-
expect(result).toBeTruthy()
194-
expect(checkFn(result)).toBe(true)
195-
expect(result.provider_name).toEqual(expected.provider_name)
196-
expect(result.type).toEqual(expected.type)
195+
assert.ok(result)
196+
assert.ok(checkFn(result))
197+
assert.ok(result.provider_name === expected.provider_name)
198+
assert.ok(result.type === expected.type)
197199
if (maxwidth > 0) {
198-
expect(result.width).toBeLessThanOrEqual(expected.maxwidth)
200+
assert.ok(result.width <= expected.maxwidth)
199201
}
200202
if (maxheight > 0) {
201-
expect(result.height).toBeLessThanOrEqual(expected.maxheight)
203+
assert.ok(result.height <= expected.maxheight)
202204
}
203205
nock.cleanAll()
204206
})
@@ -207,23 +209,23 @@ describe('test if extract() with some popular providers', () => {
207209

208210
if (PROXY_SERVER !== '') {
209211
describe('test extract live oembed API via proxy server', () => {
210-
test('check if extract method works with proxy server', async () => {
212+
it('check if extract method works with proxy server', async () => {
211213
const url = 'https://codepen.io/ndaidong/pen/LYmLKBw'
212214
const result = await extract(url, {}, {
213215
agent: new HttpsProxyAgent(PROXY_SERVER),
214216
})
215217
console.log(result)
216-
expect(result.success).toBeTruthy()
218+
assert.ok(result.success)
217219
}, 10000)
218220
})
219221
}
220222

221-
test('test .hasProvider() method', () => {
222-
expect(hasProvider('https://www.youtube.com/watch?v=ciS8aCrX-9s')).toBe(true)
223-
expect(hasProvider('https://trello.com/b/BO3bg7yn/notes')).toBe(false)
223+
it('test .hasProvider() method', () => {
224+
assert.ok(hasProvider('https://www.youtube.com/watch?v=ciS8aCrX-9s'))
225+
assert.ok(!hasProvider('https://trello.com/b/BO3bg7yn/notes'))
224226
})
225227

226-
test('test .setProviderList() method', () => {
228+
it('test .setProviderList() method', () => {
227229
const customProviderOnly = [
228230
{
229231
provider_name: 'Example',
@@ -239,6 +241,6 @@ test('test .setProviderList() method', () => {
239241
},
240242
]
241243
setProviderList(customProviderOnly)
242-
expect(hasProvider('http://www.example.org/media/abcdef')).toBe(true)
243-
expect(hasProvider('https://www.youtube.com/watch?v=ciS8aCrX-9s')).toBe(false)
244+
assert.ok(hasProvider('http://www.example.org/media/abcdef'))
245+
assert.ok(!hasProvider('https://www.youtube.com/watch?v=ciS8aCrX-9s'))
244246
})

src/utils/autoDiscovery.test.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// autoDiscovery.test
2-
/* eslint-env jest */
2+
3+
import { describe, it } from 'node:test'
4+
import assert from 'node:assert'
35

46
import nock from 'nock'
57

@@ -15,7 +17,7 @@ const parseUrl = (url) => {
1517

1618
describe('test if autoDiscovery() works correctly', () => {
1719
const url = 'https://www.bitchute.com/video/8hXWnkvA8Ao/'
18-
test(`check fetchEmbed("${url}")`, async () => {
20+
it(`check fetchEmbed("${url}")`, async () => {
1921
const htmlFile = './test-data/bitchute.html'
2022
const jsonFile = './test-data/bitchute.json'
2123

@@ -47,7 +49,7 @@ describe('test if autoDiscovery() works correctly', () => {
4749
})
4850

4951
const result = await autoDiscovery(url, params)
50-
expect(result).toBeTruthy()
52+
assert.ok(result)
5153
nock.cleanAll()
5254
})
5355
})

src/utils/fetchEmbed.test.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// fetchEmbed.test
2-
/* eslint-env jest */
2+
3+
import { describe, it } from 'node:test'
4+
import assert from 'node:assert'
35

46
import nock from 'nock'
57

@@ -91,7 +93,7 @@ describe('test if fetchEmbed() works correctly', () => {
9193

9294
cases.forEach(({ input, expected }) => {
9395
const { url, file, params = {} } = input
94-
test(`check fetchEmbed("${url}")`, async () => {
96+
it(`check fetchEmbed("${url}")`, async () => {
9597
const endpoint = getEndpoint(url)
9698
const { baseUrl, path } = parseUrl(endpoint)
9799

@@ -113,14 +115,14 @@ describe('test if fetchEmbed() works correctly', () => {
113115
} = params
114116

115117
const result = await fetchEmbed(url, { maxwidth, maxheight }, endpoint)
116-
expect(result).toBeTruthy()
117-
expect(result.provider_name).toEqual(expected.provider_name)
118-
expect(result.type).toEqual(expected.type)
118+
assert.ok(result)
119+
assert.equal(result.provider_name, expected.provider_name)
120+
assert.equal(result.type, expected.type)
119121
if (maxwidth > 0) {
120-
expect(result.width).toBeLessThanOrEqual(expected.maxwidth)
122+
assert.ok(result.width <= expected.maxwidth)
121123
}
122124
if (maxheight > 0) {
123-
expect(result.height).toBeLessThanOrEqual(expected.maxheight)
125+
assert.ok(result.height <= expected.maxheight)
124126
}
125127
nock.cleanAll()
126128
})

src/utils/linker.test.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// linker.test
2-
/* eslint-env jest */
2+
3+
import { describe, it } from 'node:test'
4+
import assert from 'node:assert'
35

46
import { isValid as isValidURL } from './linker.js'
57

@@ -39,9 +41,9 @@ describe('test isValidURL()', () => {
3941
},
4042
]
4143
cases.forEach(({ url, expected }) => {
42-
test(`isValidURL("${url}") must return "${expected}"`, () => {
44+
it(`isValidURL("${url}") must return "${expected}"`, () => {
4345
const result = isValidURL(url)
44-
expect(result).toEqual(expected)
46+
assert.equal(result, expected)
4547
})
4648
})
4749
})

src/utils/provider.test.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// provider.test
2-
/* eslint-env jest */
2+
3+
import { describe, it } from 'node:test'
4+
import assert from 'node:assert'
35

46
import provider from './provider.js'
57

@@ -20,22 +22,22 @@ describe('test if provider.find() works correctly', () => {
2022
]
2123

2224
cases.forEach(({ url, fetchEndpoint }) => {
23-
test(`provider.find("${url}") must return "${fetchEndpoint}"`, () => {
25+
it(`provider.find("${url}") must return "${fetchEndpoint}"`, () => {
2426
const foundedProvider = provider.find(url)
25-
expect(foundedProvider.endpoint).toEqual(fetchEndpoint)
27+
assert.equal(foundedProvider.endpoint, fetchEndpoint)
2628
})
2729
})
2830

29-
test('provider.find("{}") must return null', () => {
30-
expect(provider.find({})).toEqual(null)
31+
it('provider.find("{}") must return null', () => {
32+
assert.equal(provider.find({}), null)
3133
})
3234

33-
test('provider.find("abcdef") must return null', () => {
34-
expect(provider.find('abcdef')).toEqual(null)
35+
it('provider.find("abcdef") must return null', () => {
36+
assert.equal(provider.find('abcdef'), null)
3537
})
3638

37-
test('provider.find("https://somethingdoesnotexist.com") must return null', () => {
38-
expect(provider.find('https://somethingdoesnotexist.com')).toEqual(null)
39+
it('provider.find("https://somethingdoesnotexist.com") must return null', () => {
40+
assert.equal(provider.find('https://somethingdoesnotexist.com'), null)
3941
})
4042
})
4143

@@ -66,10 +68,10 @@ describe('test if provider set/get works correctly', () => {
6668
],
6769
},
6870
]
69-
test('provider.set() & provider.get()', () => {
70-
expect(provider.set(providerList)).toEqual(providerList.length)
71+
it('provider.set() & provider.get()', () => {
72+
assert.equal(provider.set(providerList), providerList.length)
7173
const newList = provider.get()
72-
expect(newList.length).toEqual(providerList.length)
73-
expect(newList[0].schemes[0]).toEqual(/\/\/store.alpha.com\/(.*)/i)
74+
assert.equal(newList.length, providerList.length)
75+
assert.equal((newList[0].schemes[0]).toString(), (/\/\/store.alpha.com\/(.*)/i).toString())
7476
})
7577
})

src/utils/retrieve.test.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// retrieve.test
2-
/* eslint-env jest */
2+
3+
import { describe, it } from 'node:test'
4+
import assert from 'node:assert'
35

46
import nock from 'nock'
57

@@ -14,18 +16,18 @@ const parseUrl = (url) => {
1416
}
1517

1618
describe('test getJson() method', () => {
17-
test('test getJson from good source', async () => {
19+
it('test getJson from good source', async () => {
1820
const url = 'https://some.where/good/source'
1921
const { baseUrl, path } = parseUrl(url)
2022
nock(baseUrl).get(path).reply(200, { data: { name: 'oembed-parser' } }, {
2123
'Content-Type': 'application/json',
2224
})
2325
const result = await getJson(url)
24-
expect(result.data.name).toEqual('oembed-parser')
26+
assert.equal(result.data.name, 'oembed-parser')
2527
nock.cleanAll()
2628
})
2729

28-
test('test getJson using proxy', async () => {
30+
it('test getJson using proxy', async () => {
2931
const url = 'https://some.where/good/source-with-proxy'
3032
const { baseUrl, path } = parseUrl(url)
3133
nock(baseUrl).get(path).reply(200, { data: { name: 'oembed-parser' } }, {
@@ -40,11 +42,11 @@ describe('test getJson() method', () => {
4042
target: 'https://proxy-server.com/api/proxy?url=',
4143
},
4244
})
43-
expect(result.data.name).toEqual('oembed-parser')
45+
assert.equal(result.data.name, 'oembed-parser')
4446
nock.cleanAll()
4547
})
4648

47-
test('test getJson invalid json reponsse', async () => {
49+
it('test getJson invalid json reponsse', async () => {
4850
const url = 'https://some.where/bad/source'
4951
const { baseUrl, path } = parseUrl(url)
5052
nock(baseUrl).get(path).reply(200, 'this is not json string', {
@@ -53,7 +55,7 @@ describe('test getJson() method', () => {
5355
try {
5456
await getJson(url)
5557
} catch (err) {
56-
expect(err).toBeTruthy()
58+
assert.ok(err)
5759
}
5860
nock.cleanAll()
5961
})

0 commit comments

Comments
 (0)