npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

fake-spotify-api

v0.3.2

Published

Fake version of the Spotify API for testing against

Readme

Fake Spotify API

A fake version of the Spotify API to allow:

  • Testing without logging in to a real Spotify account (e.g. Automated testing as part of a CI/CD pipeline)
  • Testing error cases easily (e.g. User no longer exists, token expired)

Usage

Install

You'll need npm installed. Run npm install.

Use in Chai tests

Run npm install chai --save-dev and npm install chai-http --save dev. You can then run the app as part of your tests using:

import chai from 'chai';
import chaiHttp from 'chai-http';

import { fakeSpotifyApi } from 'fake-spotify-api'; 

chai.use(chaiHttp);
const request = chai.request;

describe('Some API', () => {
  let server: ChaiHttp.Agent;

  beforeEach(async () => {
    // Startup a server using the Fake Spotify API. Use the agent so that we can use the sp_ac cookie created in signup to automatically authorize
    server = request.agent(fakeSpotifyApi).keepOpen();
    // Create a user. Note that this is not possible with the real Spotify API - you'd have to go through the signup process on the website.
    await server.post('/signup').type('form').send({
        display_name: 'Test',
        email: '[email protected]',
        password: 'secret',
    }); // You can use the response to this to get the user ID
    // Call the authorize endpoint, which replies with a redirect to the supplied location, adding a the token details.
    await server.get(`/authorize`).query({
      client_id: '1',
      redirect_uri: encodeURIComponent('http://localhost/'),
      response_type: 'token',
    }).redirects(0); // You can use the headers.location property of the response to get the token_type and access_token
  });

  // ...Add your tests here

  afterEach(async () => {
    // Shutdown the server so that we don't leave lots of these lying around
    server.close();
  });
});

See the end2end tests folder for examples.

As an application

Run npm start.

For environment variables see .env

Endpoints

There are two types of endpoint:

  • Spotify - Ones that the real Spotify API provides (e.g. GET /v1/me/playlists)
  • Helper - Ones that the real Spotify API does not provide (e.g. POST /signup). These make it easier to test edge cases and create standalone tests.

You should be careful not use the helper endpoints outside of your tests.

Isn't there already a mock of the Spotify API?

All I've found is:

  • https://github.com/0xNF/mockify - This doesn't yet implement any of the Spotify API.

Is it a mock, stub, spy, dummy, service virtualisation, fake, etc?

There are lots of different definitions for these. I've used the one from https://martinfowler.com/articles/mocksArentStubs.html

Limitations

Alot.

  • Only implements the authorize endpoint and some of the playlist and user APIs.
  • Does not use scopes provided in /authorize
  • Unable to set default token expiry time for a user
  • Unable to say a user will reject a authorization request
  • Does not persist data outside of memory

Development

IDE

I've used vscode with the following plugins:

  • DotENV
  • Git History
  • Mocha sidebar
  • npm
  • Prettier
  • Switch to test
  • TSLint
  • TypeScript Hero

And the following in my User Settings json:

  "createTest.srcFolder": "src",
  "createTest.testFolder": "tests/unit",
  "createTest.testFileExtension": ".spec.ts",
  "createTest.testFileTemplate": [
    "import ${moduleName} from '${modulePath}';",
    "import { expect } from 'chai';",
    "",
    "describe('${moduleName}', () => {",
    "  it('does something', () => {",
    "  ",
    "  });",
    "});"
  ],
  "mocha.requires": ["ts-node/register"],
  "mocha.files.glob": "./tests/**/*.spec.ts",
    "javascript.preferences.quoteStyle": "single",
  "prettier.singleQuote": true,
  "prettier.tabWidth": 2,
  "prettier.trailingComma": "es5",
  "prettier.tslintIntegration": true,
  "typescript.preferences.quoteStyle": "single",
  "typescriptHero.imports.organizeOnSave": true,
  "editor.tabSize": 2

Dependencies

Dev and production

Dev-only

  • chai - Testing library
  • chai-http - Plugin for Chai to allow a server to be started and tested against.
  • env-test - Automatically make tests run with process.env.NODE_ENV = "test"
  • mocha - Testing framework
  • mocha-parallel-tests - Allow each test file to be run in parallel to lower total test time.
  • nodemon - Monitor files for changes and automatically rebuild the project
  • ts-lint - Make sure Typescript is formatted correctly for good readability and code that is less error prone.
  • ts-node - Run node without having to compile to JS each time (works well with nodemon)
  • tslint - See ts-lint above. Can't remember why I've installed both of these
  • typescript - Add types to Javascript. Less error-prone and easier to work with (helps the IDE out with auto-completion)

Getting started

The best place to start is in the src/controllers folder. This is where incoming requests are handled.

Testing

Run npm run test to run all the tests

Watch

Run npm run watch to run the application and watch for changes in source files, which will be automatically built in to the application.

Notes