Skip to content

Instantly share code, notes, and snippets.

@Eomm
Last active April 19, 2021 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Eomm/9d923182d47b8f18b7dc580d0e63c196 to your computer and use it in GitHub Desktop.
Save Eomm/9d923182d47b8f18b7dc580d0e63c196 to your computer and use it in GitHub Desktop.
massive was snippet
const fs = require('fs')
const path = require('path')
// massive-wax upgrade -L -R -m 'test(/|\\)?.*\.js$' -t 'chore tap 15' -r repo-list -p ./tap-15.js -K <GITHUB_TOKEN>
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(')
.replace(/tearDown\(/g, 'teardown(')
.replace(/notEqual\(/g, 'not(')
fs.writeFileSync(file, result)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment