Skip to content

Commit eafa37e

Browse files
authored
Merge pull request #109 from radiovisual/misc-updates
feat!: fix cjs export; return undefined instead of null
2 parents 71d3fbb + 92407c8 commit eafa37e

27 files changed

+11113
-10846
lines changed

.github/workflows/main.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ jobs:
1111
matrix:
1212
node-version:
1313
- 16
14-
- 14
14+
- 18
15+
- latest
1516
steps:
16-
- uses: actions/checkout@v2
17-
- uses: actions/setup-node@v2
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-node@v4
1819
with:
1920
node-version: ${{ matrix.node-version }}
2021
- run: npm install
2122
- run: npm test
22-
- uses: codecov/codecov-action@v1
23-
if: matrix.node-version == 14
23+
- uses: codecov/codecov-action@v3
2424
with:
25-
fail_ci_if_error: true
25+
token: ${{ secrets.CODECOV_TOKEN }}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* istanbul ignore file */
2+
/* eslint-disable unicorn/prefer-module */
3+
const getVideoId = require('../../dist/get-video-id.js');
4+
5+
describe('bundled CJS module', () => {
6+
test('has the expected API', () => {
7+
expect(typeof getVideoId).toBe('function');
8+
expect(getVideoId('https://www.youtube.com/watch?v=1234').id).toBe('1234');
9+
});
10+
});

__tests__/builds/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<span id="video-id"></span>
1515

1616
<!-- Load getVideoId UMD module -->
17-
<script src="../../dist/get-video-id.js"></script>
17+
<script src="../../dist/get-video-id.umd.js"></script>
1818

1919
<!-- Now we are free to use getVideoId in the browser -->
2020
<script>

__tests__/builds/umd-module.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* istanbul ignore file */
22
/* eslint-disable unicorn/prefer-module */
3-
const getVideoId = require('../../dist/get-video-id.js');
3+
const getVideoId = require('../../dist/get-video-id.umd.js');
44

55
describe('bundled umd module', () => {
66
test('has the expected API', () => {

__tests__/dailymotion.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ describe('Dailymotion', () => {
2828

2929
test('Dailymotion returns the service', () => {
3030
expect(fn('http://www.dailymotion.com/video/1234').service).toBe('dailymotion');
31-
expect(fn('http://www.dailymotion.com/video/1234').id).toBe('1234');
3231
});
3332

3433
test('Dailymotion short link', () => {
3534
expect(fn('http://dai.ly/x2no31b').id).toBe('x2no31b');
35+
expect(fn('http://dai.ly/x2no31b').service).toBe('dailymotion');
3636
});
3737

3838
test('Dailymotion dynamic id', () => {

__tests__/google-redirect.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ describe('Google Redirects', () => {
4343
expect(fn(url).service).toBe('microsoftstream');
4444
});
4545

46-
test('google link returns null as id and service if missing url parameter', () => {
46+
test('google link returns undefined as id and service if missing url parameter', () => {
4747
const url = 'https://www.google.cz/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&ved=0ahUKEwiz9P3Aw5DVAhUDZVAKHcegCi8QuAIINDAB&usg=AFQjCNG0kTPdL8nC6zCi2QoZ1KVeTXH-pw';
48-
expect(fn(url).id).toBe(null);
49-
expect(fn(url).service).toBe(null);
48+
expect(fn(url).id).toBeUndefined();
49+
expect(fn(url).service).toBeUndefined();
5050
});
5151
});

__tests__/index.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ test('expects a string', () => {
77
}).toThrow(/get-video-id expects a string/);
88
});
99

10-
test('returns null as id and service', () => {
10+
test('returns undefined as id and service', () => {
1111
const expected = {
12-
id: null,
13-
service: null,
12+
id: undefined,
13+
service: undefined,
1414
};
1515
expect(fn('foo')).toMatchObject(expected);
1616
expect(fn('<iframe')).toMatchObject(expected);

__tests__/microsoft-stream.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('Microsoft Stream', () => {
3030

3131
test('microsoft stream links returns undefined id if id missing', () => {
3232
const object = fn('https://web.microsoftstream.com/video');
33-
expect(object.id).toBe(undefined);
33+
expect(object.id).toBeUndefined();
3434
expect(object.service).toBe('microsoftstream');
3535
});
3636
});

__tests__/tiktok.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('TikTok', () => {
2020

2121
test('returns undefined for unknown video ids', () => {
2222
const actual = fn('http://www.tiktok.com');
23-
expect(actual.id).toBe(undefined);
23+
expect(actual.id).toBeUndefined();
2424
expect(actual.service).toBe('tiktok');
2525
});
2626
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import extractGoogleRedirectionUrl from '../../src/utils/extract-google-redirection-url.js';
2+
3+
describe('extractGoogleRedirectionUrl', () => {
4+
test('throws TypeError if input is not a string', () => {
5+
expect(() => extractGoogleRedirectionUrl(123)).toThrow(TypeError);
6+
expect(() => extractGoogleRedirectionUrl({})).toThrow(TypeError);
7+
expect(() => extractGoogleRedirectionUrl([])).toThrow(TypeError);
8+
});
9+
10+
test('returns input as is if it does not contain Google redirect URL', () => {
11+
const nonGoogleUrl = 'https://www.example.com';
12+
expect(extractGoogleRedirectionUrl(nonGoogleUrl)).toBe(nonGoogleUrl);
13+
});
14+
15+
test('extracts and decodes URL from a Google redirect URL', () => {
16+
const expectedUrl = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
17+
const googleRedirectUrl = `https://www.google.cz/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=123&url=${encodeURIComponent(expectedUrl)}`;
18+
expect(extractGoogleRedirectionUrl(googleRedirectUrl)).toBe(expectedUrl);
19+
});
20+
21+
test('returns trimmed input if it does not match Google redirect pattern', () => {
22+
const nonMatchingUrl = ' https://www.google.com/search?q=openai ';
23+
expect(extractGoogleRedirectionUrl(nonMatchingUrl)).toBe(nonMatchingUrl.trim());
24+
});
25+
26+
test('returns input as-is if the value is not a URL', () => {
27+
const nonMatchingUrl = 'lorem ipsum';
28+
expect(extractGoogleRedirectionUrl(nonMatchingUrl)).toBe(nonMatchingUrl);
29+
});
30+
});

0 commit comments

Comments
 (0)