Moved from jest to mocha
This commit is contained in:
parent
b03e38891e
commit
59c6458738
13
package.json
13
package.json
|
|
@ -11,20 +11,19 @@
|
|||
"url": "https://github.com/zS1L3NT/ts-npm-ytmusic-api"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "jest"
|
||||
"test": "ts-mocha --timeout 10000 src/__tests__/**/*.spec.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.25.0",
|
||||
"tough-cookie": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.17.0",
|
||||
"@babel/preset-env": "^7.16.11",
|
||||
"@babel/preset-typescript": "^7.16.7",
|
||||
"@types/jest": "^27.4.0",
|
||||
"@types/mocha": "^9.1.0",
|
||||
"@types/node": "^17.0.23",
|
||||
"@types/tough-cookie": "^4.0.1",
|
||||
"babel-jest": "^27.4.6",
|
||||
"jest": "^27.4.7",
|
||||
"mocha": "^9.2.2",
|
||||
"mocha.parallel": "^0.15.6",
|
||||
"ts-mocha": "^9.0.2",
|
||||
"typescript": "^4.5.5",
|
||||
"validate-any": "1.3.1"
|
||||
},
|
||||
|
|
|
|||
3504
pnpm-lock.yaml
3504
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1 @@
|
|||
declare module "mocha.parallel"
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
import assert from "assert"
|
||||
import describeParallel from "mocha.parallel"
|
||||
import Validator from "validate-any/dist/classes/Validator"
|
||||
import YTMusic from ".."
|
||||
import {
|
||||
|
|
@ -16,190 +18,105 @@ import { iValidationError, LIST, STRING, validate } from "validate-any"
|
|||
|
||||
const issues: iValidationError[][] = []
|
||||
const queries = ["Lilac", "Weekend", "Eill", "Eminem", "Lisa Hannigan"]
|
||||
const _expect = (data: any, validator: Validator<any>) => {
|
||||
const expect = (data: any, validator: Validator<any>) => {
|
||||
const { errors } = validate(data, validator)
|
||||
if (errors.length > 0) {
|
||||
issues.push(errors)
|
||||
}
|
||||
|
||||
expect(errors.length).toBe(0)
|
||||
assert.equal(errors.length, 0)
|
||||
}
|
||||
|
||||
const ytmusic = new YTMusic()
|
||||
|
||||
beforeAll(() => ytmusic.initialize())
|
||||
|
||||
beforeEach(() => jest.setTimeout(10_000))
|
||||
before(() => ytmusic.initialize())
|
||||
|
||||
queries.forEach(query => {
|
||||
describe("Query: " + query, () => {
|
||||
test("Search suggestions", done => {
|
||||
ytmusic
|
||||
.getSearchSuggestions(query)
|
||||
.then(suggestions => {
|
||||
_expect(suggestions, LIST(STRING()))
|
||||
done()
|
||||
})
|
||||
.catch(done)
|
||||
describeParallel("Query: " + query, () => {
|
||||
it("Search suggestions", async () => {
|
||||
const suggestions = await ytmusic.getSearchSuggestions(query)
|
||||
expect(suggestions, LIST(STRING()))
|
||||
})
|
||||
|
||||
test("Search Songs", done => {
|
||||
ytmusic
|
||||
.search(query, "SONG")
|
||||
.then(songs => {
|
||||
_expect(songs, LIST(SONG_DETAILED))
|
||||
done()
|
||||
})
|
||||
.catch(done)
|
||||
it("Search Songs", async () => {
|
||||
const songs = await ytmusic.search(query, "SONG")
|
||||
expect(songs, LIST(SONG_DETAILED))
|
||||
})
|
||||
|
||||
test("Search Videos", done => {
|
||||
ytmusic
|
||||
.search(query, "VIDEO")
|
||||
.then(videos => {
|
||||
_expect(videos, LIST(VIDEO_DETAILED))
|
||||
done()
|
||||
})
|
||||
.catch(done)
|
||||
it("Search Videos", async () => {
|
||||
const videos = await ytmusic.search(query, "VIDEO")
|
||||
expect(videos, LIST(VIDEO_DETAILED))
|
||||
})
|
||||
|
||||
test("Search Artists", done => {
|
||||
ytmusic
|
||||
.search(query, "ARTIST")
|
||||
.then(artists => {
|
||||
_expect(artists, LIST(ARTIST_DETAILED))
|
||||
done()
|
||||
})
|
||||
.catch(done)
|
||||
it("Search Artists", async () => {
|
||||
const artists = await ytmusic.search(query, "ARTIST")
|
||||
expect(artists, LIST(ARTIST_DETAILED))
|
||||
})
|
||||
|
||||
test("Search Albums", done => {
|
||||
ytmusic
|
||||
.search(query, "ALBUM")
|
||||
.then(albums => {
|
||||
_expect(albums, LIST(ALBUM_DETAILED))
|
||||
done()
|
||||
})
|
||||
.catch(done)
|
||||
it("Search Albums", async () => {
|
||||
const albums = await ytmusic.search(query, "ALBUM")
|
||||
expect(albums, LIST(ALBUM_DETAILED))
|
||||
})
|
||||
|
||||
test("Search Playlists", done => {
|
||||
ytmusic
|
||||
.search(query, "PLAYLIST")
|
||||
.then(playlists => {
|
||||
_expect(playlists, LIST(PLAYLIST_FULL))
|
||||
done()
|
||||
})
|
||||
.catch(done)
|
||||
it("Search Playlists", async () => {
|
||||
const playlists = await ytmusic.search(query, "PLAYLIST")
|
||||
expect(playlists, LIST(PLAYLIST_FULL))
|
||||
})
|
||||
|
||||
test("Search All", done => {
|
||||
ytmusic
|
||||
.search(query)
|
||||
.then(results => {
|
||||
_expect(
|
||||
results,
|
||||
LIST(
|
||||
ALBUM_DETAILED,
|
||||
ARTIST_DETAILED,
|
||||
PLAYLIST_FULL,
|
||||
SONG_DETAILED,
|
||||
VIDEO_DETAILED
|
||||
)
|
||||
)
|
||||
done()
|
||||
})
|
||||
.catch(done)
|
||||
it("Search All", async () => {
|
||||
const results = await ytmusic.search(query)
|
||||
expect(
|
||||
results,
|
||||
LIST(ALBUM_DETAILED, ARTIST_DETAILED, PLAYLIST_FULL, SONG_DETAILED, VIDEO_DETAILED)
|
||||
)
|
||||
})
|
||||
|
||||
test("Get details of the first song result", done => {
|
||||
ytmusic
|
||||
.search(query, "SONG")
|
||||
.then(songs => ytmusic.getSong(songs[0]!.videoId!))
|
||||
.then(song => {
|
||||
_expect(song, SONG_FULL)
|
||||
done()
|
||||
})
|
||||
.catch(done)
|
||||
it("Get details of the first song result", async () => {
|
||||
const songs = await ytmusic.search(query, "SONG")
|
||||
const song = await ytmusic.getSong(songs[0]!.videoId)
|
||||
expect(song, SONG_FULL)
|
||||
})
|
||||
|
||||
test("Get details of the first video result", done => {
|
||||
ytmusic
|
||||
.search(query, "VIDEO")
|
||||
.then(videos => ytmusic.getVideo(videos[0]!.videoId!))
|
||||
.then(video => {
|
||||
_expect(video, VIDEO_FULL)
|
||||
done()
|
||||
})
|
||||
.catch(done)
|
||||
it("Get details of the first video result", async () => {
|
||||
const videos = await ytmusic.search(query, "VIDEO")
|
||||
const video = await ytmusic.getVideo(videos[0]!.videoId)
|
||||
expect(video, VIDEO_FULL)
|
||||
})
|
||||
|
||||
test("Get details of the first artist result", done => {
|
||||
ytmusic
|
||||
.search(query, "ARTIST")
|
||||
.then(artists => ytmusic.getArtist(artists[0]!.artistId!))
|
||||
.then(artist => {
|
||||
_expect(artist, ARTIST_FULL)
|
||||
done()
|
||||
})
|
||||
.catch(done)
|
||||
it("Get details of the first artist result", async () => {
|
||||
const artists = await ytmusic.search(query, "ARTIST")
|
||||
const artist = await ytmusic.getArtist(artists[0]!.artistId)
|
||||
expect(artist, ARTIST_FULL)
|
||||
})
|
||||
|
||||
test("Get the songs of the first artist result", done => {
|
||||
ytmusic
|
||||
.search(query, "ARTIST")
|
||||
.then(artists => ytmusic.getArtistSongs(artists[0]!.artistId!))
|
||||
.then(songs => {
|
||||
_expect(songs, LIST(SONG_DETAILED))
|
||||
done()
|
||||
})
|
||||
.catch(done)
|
||||
it("Get the songs of the first artist result", async () => {
|
||||
const artists = await ytmusic.search(query, "ARTIST")
|
||||
const songs = await ytmusic.getArtistSongs(artists[0]!.artistId)
|
||||
expect(songs, LIST(SONG_DETAILED))
|
||||
})
|
||||
|
||||
test("Get the albums of the first artist result", done => {
|
||||
ytmusic
|
||||
.search(query, "ARTIST")
|
||||
.then(artists => ytmusic.getArtistAlbums(artists[0]!.artistId!))
|
||||
.then(albums => {
|
||||
_expect(albums, LIST(ALBUM_DETAILED))
|
||||
done()
|
||||
})
|
||||
.catch(done)
|
||||
it("Get the albums of the first artist result", async () => {
|
||||
const artists = await ytmusic.search(query, "ARTIST")
|
||||
const albums = await ytmusic.getArtistAlbums(artists[0]!.artistId)
|
||||
expect(albums, LIST(ALBUM_DETAILED))
|
||||
})
|
||||
|
||||
test("Get details of the first album result", done => {
|
||||
ytmusic
|
||||
.search(query, "ALBUM")
|
||||
.then(albums => ytmusic.getAlbum(albums[0]!.albumId!))
|
||||
.then(album => {
|
||||
_expect(album, ALBUM_FULL)
|
||||
done()
|
||||
})
|
||||
.catch(done)
|
||||
it("Get details of the first album result", async () => {
|
||||
const albums = await ytmusic.search(query, "ALBUM")
|
||||
const album = await ytmusic.getAlbum(albums[0]!.albumId)
|
||||
expect(album, ALBUM_FULL)
|
||||
})
|
||||
|
||||
test("Get details of the first playlist result", done => {
|
||||
ytmusic
|
||||
.search(query, "PLAYLIST")
|
||||
.then(playlists => ytmusic.getPlaylist(playlists[0]!.playlistId!))
|
||||
.then(playlist => {
|
||||
_expect(playlist, PLAYLIST_FULL)
|
||||
done()
|
||||
})
|
||||
.catch(done)
|
||||
it("Get details of the first playlist result", async () => {
|
||||
const playlists = await ytmusic.search(query, "PLAYLIST")
|
||||
const playlist = await ytmusic.getPlaylist(playlists[0]!.playlistId)
|
||||
expect(playlist, PLAYLIST_FULL)
|
||||
})
|
||||
|
||||
test("Get the videos of the first playlist result", done => {
|
||||
ytmusic
|
||||
.search(query, "PLAYLIST")
|
||||
.then(playlists => ytmusic.getPlaylistVideos(playlists[0]!.playlistId!))
|
||||
.then(videos => {
|
||||
_expect(videos, LIST(PLAYLIST_VIDEO))
|
||||
done()
|
||||
})
|
||||
.catch(done)
|
||||
it("Get the videos of the first playlist result", async () => {
|
||||
const playlists = await ytmusic.search(query, "PLAYLIST")
|
||||
const videos = await ytmusic.getPlaylistVideos(playlists[0]!.playlistId)
|
||||
expect(videos, LIST(PLAYLIST_VIDEO))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
afterAll(() => console.log("Issues:", issues))
|
||||
after(() => console.log("Issues:", issues))
|
||||
|
|
|
|||
Loading…
Reference in New Issue