Skip to content

Commit

Permalink
Fix linting and add jest (JMPerez#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
JMPerez authored Oct 16, 2016
1 parent cf03ee4 commit dfea461
Show file tree
Hide file tree
Showing 67 changed files with 16,801 additions and 16,939 deletions.
2 changes: 2 additions & 0 deletions .coveralls
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
service_name: travis-ci
repo_token: 4i5ziqSIpZOQF4fp1EjzJjkTGoeg0lZhC
13 changes: 6 additions & 7 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ env:
rules:
brace-style: [2, "1tbs"]
comma-style: [2, "last"]
camelcase: 0
camelcase: 2
curly: 2
default-case: 2
eqeqeq: 2
global-strict: [2, "always"]
guard-for-in: 2
indent: [2, 2]
keyword-spacing: ["error", { "before": true }]
new-cap: 0
no-console: 0
no-debugger: 2
Expand All @@ -21,11 +21,10 @@ rules:
no-underscore-dangle: 0
no-unreachable: 2
radix: 2
quotes: 'single'
space-after-function-name: [2, "never"]
space-after-keywords: [2, "always"]
quotes: [2, "single"]
space-before-function-paren: [2, "never"]
space-before-blocks: 2
spaced-line-comment: [2, "always", { exceptions: ["-"]}]
spaced-comment: [2, "always", { exceptions: ["-"]}]
strict: [2, "global"]
valid-jsdoc: [2]
wrap-iife: [2, "any"]
wrap-iife: [2, "any"]
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
coverage
node_modules
23 changes: 0 additions & 23 deletions .jshintrc

This file was deleted.

8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- "0.11"
- "0.10"
before_script:
- npm install -g grunt-cli
- "6"
- "6.1"
- "5.11"
script: npm run travis
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Follow these steps:

1. Fork the repository.
2. Make the changes. Follow the coding standards define in the ESLint configuration
file. You can check your code running `eslint src` from the main folder.
3. Remember to add tests. Have a look at the _tests_ folder to see the test
suite covering the code. Want to run the tests? Run `npm test`. What about code coverage? Run `grunt coverage`.
file.
3. Remember to add tests. Have a look at the `__tests__` folder to see the test
suite covering the code. Want to run the tests? Run `npm test`. You will also get a code coverage report for free.
4. Send a Pull Request.

Releasing a new version
Expand Down
52 changes: 0 additions & 52 deletions Gruntfile.js

This file was deleted.

17 changes: 6 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Spotify Web API JS [![Build Status](https://travis-ci.org/JMPerez/spotify-web-api-js.svg?branch=master)](https://travis-ci.org/JMPerez/spotify-web-api-js)
==================

This is a lightweight wrapper for the [Spotify Web API](https://developer.spotify.com/web-api/) (1.7kB gzipped + compressed). It includes helper functions for **all Spotify's endpoints**, such as fetching metadata (search and look-up of albums, artists, tracks, playlists, new releases) and user's information (follow users, artists and playlists, and saved tracks management).
This is a lightweight wrapper for the [Spotify Web API](https://developer.spotify.com/web-api/) (2kB gzipped + compressed). It includes helper functions for **all Spotify's endpoints**, such as fetching metadata (search and look-up of albums, artists, tracks, playlists, new releases) and user's information (follow users, artists and playlists, and saved tracks management).

It doesn't have any dependencies and supports callbacks and promises. It is intended to be run on a browser, but if you want to use Node.JS to make the requests, please check [spotify-web-api-node](https://github.com/thelinmichael/spotify-web-api-node).

Expand Down Expand Up @@ -77,7 +77,7 @@ or by making a copy of the `src/spotify-web-api.js` file

## Usage

We recommend you have a look at the [documentation](https://jmperezperez.com/spotify-web-api-js/) to get an overview of the supported
We recommend you have a look at the [documentation](https://jmperezperez.com/spotify-web-api-js/) to get an overview of the supported
.

The wrapper supports callback functions, as well as [Promises](http://www.html5rocks.com/en/tutorials/es6/promises/) (you can also use [a polyfill](https://github.com/jakearchibald/es6-promise)), and Promises/A+ libraries such as [Q](https://github.com/kriskowal/q) and [when](https://github.com/cujojs/when).
Expand Down Expand Up @@ -300,29 +300,24 @@ spotifyApi.getUserPlaylists() // note that we don't pass a user id

Get typings for this package and all responses from Spotify API endpoints from the DefinitelyTyped repository by installing the typescript definition manager ```tsd``` from npm like so:

```
npm install -g tsd
```
$ npm install -g tsd

Then in the directory in which you want the typings directory, run this command to install both the definitions for this library and the definitions for The Spotify Web API.

```
tsd install spotify-web-api-js
```
$ tsd install spotify-web-api-js

Then reference the typings from the top of your main .ts file with

```
/// <reference path="../typings/spotify-web-api-js/spotify-web-api-js.d.ts"/>
```


## Running tests

In order to run the tests, run:

npm test
$ npm test

If you want to check out the coverage, run:

grunt coverage
$ npm run test:coverage
49 changes: 49 additions & 0 deletions __test__/fixtures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
var fs = require('fs');
var path = require('path');

function loadFixture(fixtureName) {
return fs.readFileSync(path.join(__dirname, 'fixtures/' + fixtureName + '.json'), 'UTF8');
};

module.exports = {
track: loadFixture('track'),
tracks: loadFixture('tracks'),
track_audio_features: loadFixture('track_audio_features'),
tracks_audio_features: loadFixture('tracks_audio_features'),
track_audio_analysis: loadFixture('track_audio_analysis'),
album: loadFixture('album'),
album_tracks: loadFixture('album_tracks'),
albums: loadFixture('albums'),
artist: loadFixture('artist'),
artists: loadFixture('artists'),
artist_albums: loadFixture('artist_albums'),
artist_albums_limit_2: loadFixture('artist_albums_limit_2'),
artist_related_artists: loadFixture('artist_related_artists'),
artist_top_tracks: loadFixture('artist_top_tracks'),
search: loadFixture('search'),
search_album: loadFixture('search_album'),
search_artist: loadFixture('search_artist'),
search_track: loadFixture('search_track'),
search_playlist: loadFixture('search_playlist'),
user: loadFixture('user'),
me: loadFixture('me'),
user_playlists: loadFixture('user_playlists'),
user_new_playlist: loadFixture('user_new_playlist'),
user_saved_tracks: loadFixture('user_saved_tracks'),
user_saved_albums: loadFixture('user_saved_albums'),
user_top_artists: loadFixture('user_top_artists'),
user_top_tracks: loadFixture('user_top_tracks'),
playlist: loadFixture('playlist'),
playlist_tracks: loadFixture('playlist_tracks'),
featured_playlists: loadFixture('featured_playlists'),
browse_categories: loadFixture('browse_categories'),
category: loadFixture('category'),
category_playlists: loadFixture('category_playlists'),
new_releases: loadFixture('new_releases'),
follow_is_following_users: loadFixture('follow_is_following_users'),
follow_is_following_artists: loadFixture('follow_is_following_artists'),
follow_are_following_playlist: loadFixture('follow_are_following_playlist'),
followed_artists: loadFixture('followed_artists'),
recommendations: loadFixture('recommendations'),
genre_seeds: loadFixture('genre_seeds')
};
1 change: 0 additions & 1 deletion tests/fixtures/album.json → __test__/fixtures/album.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"album_type" : "album",
"artists" : [ {
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions tests/fixtures/artist.json → __test__/fixtures/artist.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
module.exports = {
"external_urls" : {
"spotify" : "https://open.spotify.com/artist/0LcJLqbBmaGUft1e9Mm8HV"
},
Expand Down Expand Up @@ -26,4 +26,4 @@
"popularity" : 66,
"type" : "artist",
"uri" : "spotify:artist:0LcJLqbBmaGUft1e9Mm8HV"
}
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
module.exports = {
"href" : "https://api.spotify.com/v1/artists/5YyScSZOuBHpoFhGvHFedc/albums?offset=0&limit=20&album_type=single,album,compilation,appears_on",
"items" : [ {
"album_type" : "album",
Expand Down Expand Up @@ -466,4 +466,4 @@
"offset" : 0,
"previous" : null,
"total" : 31
}
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
module.exports = {
"href" : "https://api.spotify.com/v1/artists/5YyScSZOuBHpoFhGvHFedc/albums?offset=0&limit=2&album_type=single,album,compilation,appears_on",
"items" : [ {
"album_type" : "album",
Expand Down Expand Up @@ -54,4 +54,4 @@
"offset" : 0,
"previous" : null,
"total" : 33
}
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

{
module.exports = {
"artists" : [ {
"external_urls" : {
"spotify" : "https://open.spotify.com/artist/2hazSY4Ef3aB9ATXW7F5w3"
Expand Down Expand Up @@ -525,4 +524,4 @@
"type" : "artist",
"uri" : "spotify:artist:4eBTqTx5ssOK5YwmijmfU4"
} ]
}
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
module.exports = {
"tracks" : [ {
"album" : {
"album_type" : "album",
Expand Down Expand Up @@ -530,4 +530,4 @@
"type" : "track",
"uri" : "spotify:track:2FpyAQLrwqHbvtw6KXx5qu"
} ]
}
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
module.exports = {
"external_urls" : {
"spotify" : "https://open.spotify.com/artist/0oSGxfWSnnOXhD2fKuz2Gy"
},
Expand Down Expand Up @@ -26,4 +26,4 @@
"popularity" : 77,
"type" : "artist",
"uri" : "spotify:artist:0oSGxfWSnnOXhD2fKuz2Gy"
}
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
module.exports = {
"categories" : {
"href" : "https://api.spotify.com/v1/browse/categories?country=SE&locale=sv_SE&offset=0&limit=20",
"items" : [ {
Expand Down Expand Up @@ -188,4 +188,4 @@
"previous" : null,
"total" : 31
}
}
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
module.exports = {
"href" : "https://api.spotify.com/v1/browse/categories/dinner",
"icons" : [ {
"height" : 274,
Expand All @@ -7,4 +7,4 @@
} ],
"id" : "dinner",
"name" : "Middag"
}
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
module.exports = {
"playlists" : {
"href" : "https://api.spotify.com/v1/browse/categories/dinner/playlists?country=SE&offset=0&limit=20",
"items" : [ {
Expand Down Expand Up @@ -588,4 +588,4 @@
"previous" : null,
"total" : 42
}
}
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
module.exports = {
"error": {
"type": "not_found",
"description": "non existing id"
}
}
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
module.exports = {
"message" : "Feeling nostalgic this afternoon?",
"playlists" : {
"href" : "https://api.spotify.com/v1/browse/featured-playlists?timestamp=2014-10-23T15:37:39&offset=0&limit=20",
Expand Down Expand Up @@ -333,4 +333,4 @@
"previous" : null,
"total" : 12
}
}
};
1 change: 1 addition & 0 deletions __test__/fixtures/follow_are_following_playlist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = [ true, false ];
1 change: 1 addition & 0 deletions __test__/fixtures/follow_is_following_artists.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = [ true ];
1 change: 1 addition & 0 deletions __test__/fixtures/follow_is_following_users.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = [ true, false ];
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
module.exports = {
"artists" : {
"items" : [ {
"external_urls" : {
Expand Down Expand Up @@ -617,4 +617,4 @@
"limit" : 20,
"href" : "https://api.spotify.com/v1/users/jmperezperez/following?type=artist&limit=20"
}
}
};
Loading

0 comments on commit dfea461

Please sign in to comment.