From 9c1f4a14b9f96208951eecab2e90e5990f749666 Mon Sep 17 00:00:00 2001 From: Lacy Morrow Date: Mon, 28 Nov 2022 22:58:46 -0500 Subject: [PATCH] test --- .gitignore | 27 ++++++++++++++++++++++++- package.json | 28 +++++++++++++++++--------- test.js | 57 ++++++++++++---------------------------------------- 3 files changed, 58 insertions(+), 54 deletions(-) diff --git a/.gitignore b/.gitignore index a6b26a3..30132bb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,28 @@ .fuse* .DS* -*.lock + +# Logs +logs +*.log + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directory +# Deployed apps should consider commenting this line out: +# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git +node_modules diff --git a/package.json b/package.json index 2e7ad29..3181d78 100644 --- a/package.json +++ b/package.json @@ -9,14 +9,25 @@ "type": "git", "url": "git://github.com/lacymorrow/movie-trailer" }, - "bin": { - "movie-trailer": "cli.js" - }, "author": { "name": "Lacy Morrow", "email": "me@lacymorrow.com", "url": "http://lacymorrow.com" }, + "funding": [ + { + "type": "patreon", + "url": "https://patreon.com/lacymorrow" + }, + { + "type": "individual", + "url": "http://lacymorrow.com/donate" + }, + "https://www.buymeacoffee.com/lm" + ], + "bin": { + "movie-trailer": "cli.js" + }, "engines": { "node": ">=7.6.0" }, @@ -39,19 +50,18 @@ "uri", "path" ], - "devDependencies": { - "ava": "^0.25.0" - }, "readmeFilename": "README.md", "bugs": { "url": "https://github.com/lacymorrow/movie-trailer/issues" }, "homepage": "https://github.com/lacymorrow/movie-trailer", + "devDependencies": { + "ava": "^5.1.0" + }, "dependencies": { - "isomorphic-fetch": "^2.2.1", + "isomorphic-fetch": "^3.0.0", "meow": "^4.0.0", - "node-fetch": "^2.1.2", - "np": "^7.2.0", + "np": "^7.6.2", "xo": "^0.37.1" }, "np": { diff --git a/test.js b/test.js index 19367dd..2cec3f6 100644 --- a/test.js +++ b/test.js @@ -1,6 +1,6 @@ 'use strict' -import test from 'ava' -import movieTrailer from './index.js' +const test = require( 'ava' ) +const movieTrailer = require( './index' ) test( 'fetch movie trailer', async t => { @@ -15,11 +15,8 @@ test( 'fetch movie trailer', async t => { test( 'dont fetch empty search', async t => { - // Testing no search quety, should error - const error = await t.throws( movieTrailer( null ) - .catch( error_ => Promise.reject( error_ ) ) - ) - + // Testing no search query, should error + const error = await movieTrailer( null ).catch( error_ => error_ ) t.is( error.message, 'Expected first parameter to be a movie or TMDB ID (string)' ) } ) @@ -62,7 +59,7 @@ test( 'fetch movie trailer with language', async t => { t.plan( 1 ) const trailer = await movieTrailer( 'up' ) - const trailerDE = await movieTrailer( 'up', { language: 'de_DE' } ) + const trailerDE = await movieTrailer( 'up', { language: 'de' } ) t.not( trailer, trailerDE, 'returns a language-specific video' ) @@ -126,83 +123,55 @@ test( 'fetch using a custom api_key', async t => { } ) -test.cb( 'calls the callback', t => { +test( 'calls the callback', async t => { t.plan( 2 ) - movieTrailer( 'oceans eleven', ( error, result ) => { - - if ( error ) { - - return t.end( error ) - - } + await movieTrailer( 'oceans eleven', ( _error, result ) => { t.is( result.indexOf( 'http' ), 0, 'returns a url' ) t.not( result.indexOf( 'youtube' ), -1, 'returns a youtube url' ) - t.end() } ) } ) -test.cb( 'calls the callback with a year', t => { +test( 'calls the callback with a year', async t => { t.plan( 2 ) - movieTrailer( 'oceans eleven', 1960, ( error, result ) => { - - if ( error ) { - - return t.end( error ) - - } + await movieTrailer( 'oceans eleven', 1960, ( _error, result ) => { t.is( result.indexOf( 'http' ), 0, 'returns a url' ) t.not( result.indexOf( 'youtube' ), -1, 'returns a youtube url' ) - t.end() } ) } ) -test.cb( 'calls the callback with multiple trailers', t => { +test( 'calls the callback with multiple trailers', async t => { t.plan( 3 ) - movieTrailer( 'oceans eleven', true, ( error, result ) => { - - if ( error ) { - - return t.end( error ) - - } + await movieTrailer( 'oceans eleven', true, ( _error, result ) => { t.is( typeof result, 'object' ) t.is( result[0].indexOf( 'http' ), 0, 'returns a url' ) t.not( result[0].indexOf( 'youtube' ), -1, 'returns a youtube url' ) - t.end() } ) } ) -test.cb( 'calls the callback with a year and multiple trailers', t => { +test( 'calls the callback with a year and multiple trailers', async t => { t.plan( 3 ) - movieTrailer( 'oceans eleven', { multi: true, year: 1960 }, ( error, result ) => { - - if ( error ) { - - return t.end( error ) - - } + await movieTrailer( 'oceans eleven', { multi: true, year: 1960 }, ( _error, result ) => { t.is( typeof result, 'object' ) t.is( result[0].indexOf( 'http' ), 0, 'returns a url' ) t.not( result[0].indexOf( 'youtube' ), -1, 'returns a youtube url' ) - t.end() } )