Last active
June 14, 2023 09:43
-
-
Save holgerd77/10d48e073ed8971e8c1adf693a762dcb to your computer and use it in GitHub Desktop.
JavaScript Tape -> Vitest Test Runner Transition - RegEx Cheat Sheet
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
Tape -> Vitest Regex Expressions | |
-------------------------------- | |
import * as tape from 'tape' // No regex | |
import { assert, describe, it } from 'vitest' | |
import type * as tape from 'tape' // No regex | |
import { assert, describe, it } from 'vitest' | |
********************************** | |
Outer tape keyword conversion | |
********************************** | |
Note: async tape function mostly indicates the lack | |
of an inner t.test() usage, in this inter t.test() | |
should be added and async from tape call removed. | |
Otherwise async should be kept. | |
tape\('([^']+)', async \([^']+\) => \{ // Regex | |
describe('$1', () => { | |
tape\('([^']+)', async function \([^']+\) \{ | |
describe('$1', () => { | |
All without async as well (not that for describe async should be removed in both cases). | |
********************************** | |
Inner test keyword conversion | |
********************************** | |
[ts]+\.test\(`([^`]+)`, async \([^']+\) => \{ // t.test(`should not crash on an invalid rlp - ${index}`, async (st) => { | |
it(`$1`, async () => { // it(`should not crash on an invalid rlp - ${index}`, () => { | |
[ts]+\.test\('([^`]+)', async \([^']+\) => \{ | |
it('$1', async () => { | |
[ts]+\.test\('([^`]+)', async function \([^']+\) \{ | |
it('$1', async () => { | |
[ts]+\.test\(`([^`]+)`, async function \([^']+\) \{ | |
it('$1', async () => { | |
Then do a run without async. | |
Generic replace: | |
tape( // No Regex | |
describe( | |
[st]+\.test\( // Regex | |
it( | |
function \([ts]{1,2}\) \{ // Regex | |
() => { | |
\([ts]{1,2}\) => \{ // Regex | |
() => { | |
Consistency searches: | |
tape // No regex | |
function \([ts]+[^']+\) \{ // Regex | |
\([ts]{1,2}[^']+\) => \{ // Regex | |
Do a final "tape" consistency search. | |
********************************** | |
Assertion transitions | |
********************************** | |
[st]+\.pass\( // Regex | |
"assert.ok(true, " (keep the space) | |
[st]+\.ok\(false\) // Regex | |
assert.fail() | |
[st]+\.end\(\) // Regex, add line break with CTRL + enter | |
Do document reformatting or linting | |
These should be done separately: | |
[st]+\.true -> assert.isTrue // Regex | |
[st]+\.false -> assert.isFalse // Regex | |
Preparatory replacements: | |
.equals( // No regex | |
.equal( | |
.deepEquals( // No regex | |
.deepEqual( | |
Now this should be safe (nevertheless control search results): | |
\b(?!assert)[st]+\.\b((?:equal|deepEqual|notEqual|notDeepEqual|isEquivalent|ok|notOk|doesNotThrow|fail|throws))\b | |
assert.$1 | |
Do another assert.throws search and adjust API: | |
old: (function, msg) (non-matcher case) | |
new: (function, undefined, undefined, msg) | |
old: (function, matcher, msg) (matcher case) | |
new: (function, matcher, undefined, msg) | |
Consistency Check Searches: | |
\b(?!assert)[st]+\. // Regex | |
\([ts]+ // Regex | |
***************************** | |
JSON require Transformations | |
***************************** | |
Either manually file-by-file or at once (this will produce fixable errors likely): | |
const ([^=]+)= require\('([^']+)'\) // Regex | |
import $1from '$2' | |
Then do linting. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment