mappersmith-recorder

    0.0.3 • Public • Published

    mappersmith-recorder

    EXPERIMENTAL: This module is in a very early stage and intended to be used in a very specific context. It may or may not be appropriate for your use case. For something more mature and generic, take a look at PollyJS.

    Mappersmith middleware to record requests and responses as HAR files. These files are simple JSON files that can either be read directly or loaded into a HAR viewer or even the browser's own developer tools.

    Note that this middleware currently only works in NodeJS, as it relies on being able to write files to the filesystem. You can implement a custom persistence class that works in a browser environment, but it does not come out of the box.

    Screenshot of HAR viewer

    Installation

    $ yarn add mappersmith-recorder

    Usage

    const path = require('path')
    const forge = require('mappersmith');
    const { RecorderMiddleware, Session, FileSystemPersistence } = require('mappersmith-recorder');
     
    const persistence = new FileSystemPersistence({ path: path.join(__dirname, 'recordings') })
    const session = new Session({ name: 'github', persistence })
     
    const client = forge({
      clientId: 'github',
      middleware: [RecorderMiddleware({ session })],
      host: 'https://status.github.com',
      resources: {
        Status: {
          current: { path: '/api/status.json' }
        }
      }
    });
     
    const main = async () => {
        await client.Status.current()
     
        // Save the session to disk
        await session.save()
     
        await client.Status.current()
     
        // Save session containing both calls
        await session.save()
     
        // Clear the session
        session.reset()
    }
     
    main()

    After running the following, in recordings/ there should be two files called github-${datetime}.har.

    Keywords

    none

    Install

    npm i mappersmith-recorder

    DownloadsWeekly Downloads

    0

    Version

    0.0.3

    License

    MIT

    Unpacked Size

    331 kB

    Total Files

    12

    Last publish

    Collaborators

    • nevon