-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: switch from tap to node:test and Borp #39
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
To do this, I: - Uninstalled `tap` and replaced it with `borp` - Wrote a [jscodeshift] codemod (below) - Updated `instanbul` references to `c8`, which Borp uses internally - Dropped Node 16 support, which `node:test` requires - Made a few small manual tweaks Here's the jscodeshift transformer: ```typescript import type { Transform, Expression, FunctionExpression, ArrowFunctionExpression, } from 'jscodeshift' const isFunctionExpression = ( expression: Readonly<Expression> ): expression is FunctionExpression | ArrowFunctionExpression => expression.type === 'FunctionExpression' || expression.type === 'ArrowFunctionExpression' const transform: Transform = (fileInfo, api) => { const { j } = api const root = j(fileInfo.source) // Update imports { const commonJsImport = (varName: string, moduleName: string) => j.variableDeclaration('const', [ j.variableDeclarator( j.identifier(varName), j.callExpression(j.identifier('require'), [ j.stringLiteral(moduleName), ]) ), ]) const tapImport = root.find(j.VariableDeclaration, { declarations: [ { init: { callee: { name: 'require' }, arguments: [ { value: 'tap', }, ], }, }, ], }) tapImport.insertBefore(commonJsImport('test', 'node:test')) tapImport.insertBefore(commonJsImport('assert', 'node:assert/strict')) tapImport.remove() } // Drop args from test callback root .find(j.CallExpression, { callee: { name: 'test' } }) .forEach((callExpression) => { for (const arg of callExpression.value.arguments) { if (!isFunctionExpression(arg)) continue arg.params = [] } }) // Drop t.pass root .find(j.ExpressionStatement, { expression: { callee: { type: 'MemberExpression', object: { name: 't' }, property: { name: 'pass' }, }, }, }) .remove() // Simple replacements of various calls { const toReplace: Map<string, string> = new Map([ ['comment', 'console.log'], ['equal', 'assert.equal'], ['fail', 'assert.fail'], ['not', 'assert.notEqual'], ['ok', 'assert.ok'], ['same', 'assert.deepEqual'], ]) for (const [tMethod, memberExpressionString] of toReplace) { const [newObj, newProp] = memberExpressionString.split('.') root .find(j.MemberExpression, { object: { name: 't' }, property: { name: tMethod }, }) .forEach((memberExpression) => { memberExpression.value.object = j.identifier(newObj) memberExpression.value.property = j.identifier(newProp) }) } } // Replace `t.notOk(x)` with `assert.equal(x, false)`. // Doesn't always work, but works how we use it. root .find(j.CallExpression, { callee: { type: 'MemberExpression', object: { name: 't' }, property: { name: 'notOk' }, }, }) .forEach((callExpression) => { callExpression.value.callee = j.memberExpression( j.identifier('assert'), j.identifier('equal') ) callExpression.value.arguments = [ callExpression.value.arguments[0], j.booleanLiteral(false), ...callExpression.value.arguments.slice(1), ] }) // All done! return root.toSource() } export default transform ``` [jscodeshift]: https://github.com/facebook/jscodeshift
EvanHahn
force-pushed
the
tap-2-nodetest
branch
from
February 28, 2024 22:28
487487b
to
82b2869
Compare
gmaclennan
approved these changes
Mar 12, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, looks good to me
EvanHahn
added a commit
to digidem/mapeo-sqlite-indexer
that referenced
this pull request
Mar 20, 2024
This was a pretty mechanical change. To do this, I: * Uninstalled `tap` and replaced it with `borp` * Manually rewrote tests to use `node:assert` and `t.after` for cleanup See [multi-core-indexer#39] for a similar patch on another repo. [multi-core-indexer#39]: digidem/multi-core-indexer#39
EvanHahn
added a commit
to digidem/comapeo-schema
that referenced
this pull request
Mar 28, 2024
This was a pretty mechanical change. To do this, I: * Uninstalled `tap` and replaced it with `node --test` * Manually rewrote assertions to use `node:assert` See [multi-core-indexer#39] and [mapeo-sqlite-indexer#27] for similar patches on other repos. [multi-core-indexer#39]: digidem/multi-core-indexer#39 [mapeo-sqlite-indexer#27]: digidem/mapeo-sqlite-indexer#27
EvanHahn
added a commit
to digidem/comapeo-schema
that referenced
this pull request
Mar 28, 2024
This was a pretty mechanical change. To do this, I: * Uninstalled `tap` and replaced it with `node --test` * Manually rewrote assertions to use `node:assert` See [multi-core-indexer#39] and [mapeo-sqlite-indexer#27] for similar patches on other repos. [multi-core-indexer#39]: digidem/multi-core-indexer#39 [mapeo-sqlite-indexer#27]: digidem/mapeo-sqlite-indexer#27
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
To do this, I:
tap
and replaced it withborp
c8
for test coverage??=
operator, so I had to write an additional unit testnode:test
requiresHere's the jscodeshift transformer: