Are you overwhelmed by tap 15?
Tags: node, tap, release, automation
Published: 2021-04-05 08:50:53

Recently `tap` bumped to v15! :tada:

If you are overwhelmed by all your failing workflows, here a snipped to upgrade them all in once!!

I used the old and dirty [`massive-wax`](https://github.com/Eomm/massive-wax) module that I made some time ago to open PRs like this one:
https://github.com/Eomm/fastify-405/pull/36

You need to:

## Install massive-wax

```
npm i massive-wax -g
```

## Write a processor

A processor is just a set of functions executed to edit the repository's files.

So create a new `tap-15.js` file like this (it is `sync` but `async` is supported too:

```js
const fs = require('fs')
const path = require('path')

module.exports = function factory (args, logger) {
  return {
    onRepo (repo) {
      const repoPath = path.join(repo.owner, repo.repo)

      const pkjPath = path.join(repoPath, './package.json')
      const pkj = JSON.parse(fs.readFileSync(pkjPath, 'utf-8'))
      pkj.devDependencies.tap = '^15.0.1'
      fs.writeFileSync(pkjPath, JSON.stringify(pkj, null, 2))

      const tapRcPath = path.join(repoPath, '.taprc')
      if (fs.existsSync(tapRcPath)) {
        const tapRc = fs.readFileSync(tapRcPath, 'utf-8')
        let newTapRc = tapRc.replace(/esm: (true|false)\n/i, '')

        if (!pkj.scripts.test.includes('100')) {
          newTapRc += '\ncheck-coverage: false'
        }

        fs.writeFileSync(tapRcPath, newTapRc)
      } else {
        fs.writeFileSync(tapRcPath, 'check-coverage: false\n')
      }
    },
    onFile (file) {
      const fileContent = fs.readFileSync(file, 'utf-8')

      const result = fileContent
        .replace(/tearDown/g, 'teardown')
        .replace(/strictEqual/g, 'equal')
        .replace(/deepEqual/g, 'same')
        .replace(/false\(/g, 'notOk(')
        .replace(/notStrictEqual/g, 'not')
        .replace(/similar/g, 'match')
        .replace(/strictDeepEqual/g, 'strictSame')
        .replace(/is\(/g, 'equal(')
        .replace(/throw\(/g, 'throws(')
        .replace(/like\(/g, 'match(')
        .replace(/contains\(/g, 'has(')
        .replace(/equals\(/g, 'equal(')
        .replace(/true\(/g, 'ok(')
        .replace(/notThrow\(/g, 'doesNotThrow(')

      fs.writeFileSync(file, result)
    }
  }
}
```
_This script is [updated here](https://gist.github.com/Eomm/9d923182d47b8f18b7dc580d0e63c196#file-tap15-upgrade-js)_

## Write the repositories list

Create a text file called `repo-list` with the list of the repositories you want to upgrade:

```
https://github.com/fastify/fastify-multipart
https://github.com/fastify/fastify-mysql
https://github.com/fastify/light-my-request
```

## Run the magic

Now, let's run `massive-wax`!!

```
massive-wax upgrade -L -R -m 'test(/|\\).*\.js$' -t 'chore tap 15' -r repo-list -p ./tap-15.js -K <GH-TOKEN>

Cloning https://github.com/fastify/fastify-multipart/ to fastify/fastify-multipart
Cloning https://github.com/fastify/fastify-mysql/ to fastify/fastify-mysql
Cloning https://github.com/fastify/light-my-request/ to fastify/light-my-request
Walking C:\Users\behem\workspace\massive-wax\fastify\fastify-multipart
Commit done for fastify-multipart
Walking C:\Users\behem\workspace\massive-wax\fastify\fastify-mysql
Commit done for fastify-mysql
Walking C:\Users\behem\workspace\massive-wax\fastify\light-my-request
Commit done for light-my-request
Push done for fastify-multipart
Push done for fastify-mysql
Opened PR: https://github.com/fastify/fastify-multipart/pull/218
Opened PR: https://github.com/fastify/fastify-mysql/pull/50
Push done for light-my-request
Opened PR: https://github.com/fastify/light-my-request/pull/129
```

Check out the docs for more options and settings!!

For more content, follow me on [Twitter](https://twitter.com/ManuEomm)!

Thanks to [Matteo Collina](https://twitter.com/matteocollina) for inspiring me this snippet with his [gist](https://gist.github.com/mcollina/e799ebb3fa9260abbe8ea56a8434ef24)

Image credits to [boscdanjou](https://www.flickr.com/photos/boscdanjou/13781877295)