Skip to content

Commit

Permalink
build: use tsup and node.js test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Dec 12, 2023
1 parent 02cba16 commit d890def
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 91 deletions.
8 changes: 1 addition & 7 deletions .eslintrc.js → .eslintrc.cjs
Expand Up @@ -24,13 +24,7 @@ module.exports = {
},
},
{
files: ['test/*.js'],
parserOptions: {
sourceType: 'script',
},
},
{
files: ['.eslintrc.js', 'rollup.config.js', 'test/*.js'],
files: ['.eslintrc.cjs', 'test/*.js'],
env: {
node: true,
},
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -7,7 +7,7 @@ jobs:
name: Tests
strategy:
matrix:
node-version: [16.x, 18.x, 20.x]
node-version: [18.x, 20.x]
runs-on: ubuntu-latest
steps:
- name: Checkout sources
Expand Down
27 changes: 9 additions & 18 deletions package.json
Expand Up @@ -6,6 +6,7 @@
"contributors": [
"Renée Kooi <renee@kooi.me>"
],
"type": "module",
"dependencies": {
"get-artist-title": "^1.2.0",
"get-youtube-chapters": "^2.0.0",
Expand All @@ -15,7 +16,6 @@
"parse-iso-duration": "^1.1.0"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.0.0",
"@types/http-errors": "^2.0.0",
"@types/node-fetch": "^2.5.4",
"@types/qs": "^6.9.4",
Expand All @@ -24,38 +24,29 @@
"eslint": "^8.5.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.21.2",
"is-builtin-module": "^3.0.0",
"nock": "^13.0.3",
"rollup": "^4.1.4",
"rollup-plugin-typescript2": "^0.36.0",
"tape": "^5.0.0",
"tslib": "^2.0.0",
"tsup": "^8.0.1",
"typescript": "^5.0.2"
},
"engines": {
"node": ">= 10"
"node": ">= 18"
},
"main": "./dist/index.js",
"exports": {
".": [
{
"import": "./dist/u-wave-source-youtube.mjs",
"default": "./dist/u-wave-source-youtube.cjs"
},
"./dist/u-wave-source-youtube.cjs"
]
".": "./dist/index.js",
"./package.json": "./package.json"
},
"keywords": [
"u-wave-source",
"youtube"
],
"license": "MIT",
"main": "./dist/u-wave-source-youtube.cjs",
"repository": "u-wave/u-wave-source-youtube",
"scripts": {
"build": "rollup -c",
"build": "tsup src/index.ts --format esm --dts",
"prepare": "npm run build",
"tape": "tape -r ./test/init.js ./test/test.js",
"test": "npm run build && npm run tape"
"tests-only": "node test/test.js",
"test": "npm run build && npm run tests-only"
},
"typings": "./dist/index.d.ts"
}
36 changes: 0 additions & 36 deletions test/init.js

This file was deleted.

51 changes: 22 additions & 29 deletions test/test.js
@@ -1,26 +1,25 @@
const test = require('tape');
const nock = require('nock');
const path = require('path');
const youTubeSource = require('..').default;
import test from 'node:test';
import * as assert from 'node:assert/strict';
import { fileURLToPath } from 'node:url';
import nock from 'nock';
import youTubeSource from 'u-wave-source-youtube';

const FAKE_KEY = 'AIzaSyVBDlZqp3o65v9zFWv0Qxij1rt3axCWqs9';

const createSource = () => youTubeSource({}, { key: FAKE_KEY });

const API_HOST = 'https://www.googleapis.com';

const fixture = (name) => path.join(__dirname, 'responses', `${name}.json`);
const fixture = (name) => fileURLToPath(new URL(`./responses/${name}.json`, import.meta.url));

test('providing a key is required', (t) => {
t.throws(
test('providing a key is required', () => {
assert.throws(
() => youTubeSource({}),
/Expected a YouTube API key/,
);

t.end();
});

test('searching for videos', async (t) => {
test('searching for videos', async () => {
const src = createSource();

nock(API_HOST).get('/youtube/v3/search')
Expand All @@ -33,21 +32,19 @@ test('searching for videos', async (t) => {
const results = await src.search('Beyoncé');

// Our mocked search only returns 5 items. Actual search would return 50. 🙈
t.is(results.length, 5);
assert.equal(results.length, 5);

results.forEach((item) => {
t.true('artist' in item);
t.true('title' in item);
assert.ok('artist' in item);
assert.ok('title' in item);
});

// Search results should not modify the artist/title.
t.is(results[0].artist, 'beyonceVEVO');
t.is(results[0].title, 'Beyoncé - Hold Up');

t.end();
assert.equal(results[0].artist, 'beyonceVEVO');
assert.equal(results[0].title, 'Beyoncé - Hold Up');
});

test('get videos by id', async (t) => {
test('get videos by id', async () => {
const src = createSource();

nock(API_HOST).get('/youtube/v3/videos')
Expand All @@ -56,15 +53,13 @@ test('get videos by id', async (t) => {

const items = await src.get(['n0gAo8z859U', 'XO4xNQ-pWPQ']);

t.is(items.length, 2);
assert.equal(items.length, 2);

t.is(items[0].artist, 'LAYBACKSOUND');
t.is(items[1].artist, 'KIRARA');

t.end();
assert.equal(items[0].artist, 'LAYBACKSOUND');
assert.equal(items[1].artist, 'KIRARA');
});

test('defaults to using the channel name as the artist name', async (t) => {
test('defaults to using the channel name as the artist name', async () => {
const src = createSource();

nock(API_HOST).get('/youtube/v3/videos')
Expand All @@ -74,9 +69,7 @@ test('defaults to using the channel name as the artist name', async (t) => {

const items = await src.get(['t6gDp9IsBgw']);

t.is(items.length, 1);
t.is(items[0].artist, 'lang lee');
t.is(items[0].title, '신의 놀이 (Playing God)');

t.end();
assert.equal(items.length, 1);
assert.equal(items[0].artist, 'lang lee');
assert.equal(items[0].title, '신의 놀이 (Playing God)');
});

0 comments on commit d890def

Please sign in to comment.