-
-
Notifications
You must be signed in to change notification settings - Fork 50
feat(tape-to-node-test): introduce
#296
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
Open
AugustinMauroy
wants to merge
33
commits into
main
Choose a base branch
from
tape-to-node-test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 16 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
0832a90
feat(`tape-to-node-test`): first draft
AugustinMauroy 527acf4
fix: use `workflow` convention
AugustinMauroy c5ca0a5
fix: use `EOL`
AugustinMauroy 59cf844
chore: update readme
AugustinMauroy af14a96
feat(tape-to-node-test): support dynamic import
AugustinMauroy f665ea8
feat(`tape-to-node-test`): support more cases
AugustinMauroy 08e74b0
fix: code format
AugustinMauroy e51e443
feat(tape-to-node-test): support timeout
AugustinMauroy 7cd866b
feat(tape-to-node-test): improve
AugustinMauroy 506db48
fix: linting/issue
AugustinMauroy 256c540
test,fix: handling of timeout
AugustinMauroy a6caff6
Delete index.ts
AugustinMauroy 15c63ec
Merge branch 'main' into tape-to-node-test
AugustinMauroy c0037e1
remove dep
AugustinMauroy 5b9ce43
Apply suggestions from code review
AugustinMauroy 5e5d232
fix: code style
AugustinMauroy 8e0e92c
Update recipes/tape-to-node-test/src/workflow.ts
AugustinMauroy 630c116
better async cb handling
AugustinMauroy 654294a
wip
AugustinMauroy ddf833a
handle `test` and `plan`
AugustinMauroy bfcb5eb
update
AugustinMauroy a44f92e
WIP
AugustinMauroy fc28208
improve async/sync handling
AugustinMauroy 2630241
update
AugustinMauroy f13199b
apply review
AugustinMauroy 39d0797
better t.pass
AugustinMauroy 21a2d7c
Update workflow.ts
AugustinMauroy beb9739
apply suggestion
AugustinMauroy 6da0864
timeout support
AugustinMauroy 2769176
add remove line
AugustinMauroy a7c16f4
Merge branch 'main' into tape-to-node-test
AugustinMauroy a12f72e
Update package-lock.json
AugustinMauroy 56a15b4
fix
AugustinMauroy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| # Tape to Node.js Test Runner Codemod | ||
|
|
||
| This codemod migrates tests written using [`tape`](https://github.com/tape-testing/tape) v5 to the native Node.js test runner ([`node:test`](https://nodejs.org/api/test.html)). | ||
|
|
||
| ## Features | ||
|
|
||
| - Replaces `tape` imports with `node:test` and `node:assert`. | ||
| - Converts `test(name, (t) => ...)` to `test(name, async (t) => ...)`. | ||
| - Maps `tape` assertions to `node:assert` equivalents, including many aliases (e.g., `t.is`, `t.equals`, `t.deepEquals`). | ||
| - Handles `t.plan` (by commenting it out). | ||
| - Handles `t.end` (removes it for async tests, converts to `done` callback for callback-style tests). | ||
| - Handles `t.test` subtests (adds `await`). | ||
| - Converts `t.teardown` to `t.after`. | ||
| - Converts `t.comment` to `t.diagnostic`. | ||
| - Migrates `t.timeoutAfter(ms)` to `{ timeout: ms }` test option. | ||
| - Supports `test.skip` and `test.only`. | ||
| - Handles `test.onFinish` and `test.onFailure` (by commenting them out with a TODO). | ||
| - Supports loose equality assertions (e.g., `t.looseEqual` -> `assert.equal`). | ||
|
|
||
| ## Example | ||
|
|
||
| ### Basic Equality | ||
|
|
||
| ```diff | ||
| - import test from "tape"; | ||
| + import { test } from 'node:test'; | ||
| + import assert from 'node:assert'; | ||
|
|
||
| - test("basic equality", (t) => { | ||
| + test("basic equality", async (t) => { | ||
| - t.plan(4); | ||
| + // t.plan(4); | ||
| - t.equal(1, 1, "equal numbers"); | ||
| + assert.strictEqual(1, 1, "equal numbers"); | ||
| - t.notEqual(1, 2, "not equal numbers"); | ||
| + assert.notStrictEqual(1, 2, "not equal numbers"); | ||
| - t.strictEqual(true, true, "strict equality"); | ||
| + assert.strictEqual(true, true, "strict equality"); | ||
| - t.notStrictEqual("1", 1, "not strict equality"); | ||
| + assert.notStrictEqual("1", 1, "not strict equality"); | ||
| - t.end(); | ||
| + // t.end(); | ||
| }); | ||
| ``` | ||
|
|
||
| ### Async Tests | ||
|
|
||
| ```diff | ||
| - import test from "tape"; | ||
| + import { test } from 'node:test'; | ||
| + import assert from 'node:assert'; | ||
|
|
||
| function someAsyncThing() { | ||
| return new Promise((resolve) => setTimeout(() => resolve(true), 50)); | ||
| } | ||
|
|
||
| - test("async test with promises", async (t) => { | ||
| + test("async test with promises", async (t) => { | ||
| - t.plan(1); | ||
| + // t.plan(1); | ||
| const result = await someAsyncThing(); | ||
| - t.ok(result, "async result is truthy"); | ||
| + assert.ok(result, "async result is truthy"); | ||
| }); | ||
| ``` | ||
|
|
||
| ### Callback Style | ||
|
|
||
| ```diff | ||
| - import test from "tape"; | ||
| + import { test } from 'node:test'; | ||
| + import assert from 'node:assert/strict'; | ||
|
|
||
| - test("callback style", (t) => { | ||
| + test("callback style", (t, done) => { | ||
| setTimeout(() => { | ||
| - t.ok(true); | ||
| + assert.ok(true); | ||
| - t.end(); | ||
| + done(); | ||
| }, 100); | ||
| }); | ||
| ``` | ||
|
|
||
| ### Timeout Handling | ||
|
|
||
| ```diff | ||
| - import test from "tape"; | ||
| + import { test } from 'node:test'; | ||
| + import assert from 'node:assert/strict'; | ||
|
|
||
| - test("timeout test", (t) => { | ||
| + test("timeout test", { timeout: 100 }, async (t) => { | ||
| - t.timeoutAfter(100); | ||
| - t.ok(true); | ||
| + assert.ok(true); | ||
| - t.end(); | ||
| + // t.end(); | ||
| }); | ||
| ``` | ||
|
|
||
| ### Dynamic Import | ||
|
|
||
| ```diff | ||
| async function run() { | ||
| - const test = await import("tape"); | ||
| + const { test } = await import('node:test'); | ||
| + const { default: assert } = await import('node:assert/strict'); | ||
|
|
||
| - test("dynamic import", (t) => { | ||
| + test("dynamic import", async (t) => { | ||
| - t.ok(true); | ||
| + assert.ok(true); | ||
| - t.end(); | ||
| + // t.end(); | ||
|
AugustinMauroy marked this conversation as resolved.
|
||
| }); | ||
| } | ||
| ``` | ||
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| schema_version: "1.0" | ||
| name: "@nodejs/tape-to-node-test" | ||
| version: "1.0.0" | ||
| description: Migrates Tape tests to Node.js native test runner | ||
| author: Node.js | ||
| license: MIT | ||
| workflow: workflow.yaml | ||
| category: migration | ||
|
|
||
| targets: | ||
| languages: | ||
| - javascript | ||
| - typescript | ||
|
|
||
| keywords: | ||
| - transformation | ||
| - migration | ||
| - tape | ||
| - node:test | ||
|
|
||
| capabilities: | ||
| - fs | ||
| - child_process |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "name": "@nodejs/tape-to-node-test", | ||
| "version": "1.0.0", | ||
| "description": "Migrates Tape tests to Node.js native test runner", | ||
| "type": "module", | ||
| "scripts": { | ||
| "test": "npx codemod jssg test -l typescript ./src/workflow.ts" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/nodejs/userland-migrations.git", | ||
| "directory": "recipes/tape-to-node-test", | ||
| "bugs": "https://github.com/nodejs/userland-migrations/issues" | ||
| }, | ||
| "author": "Node.js", | ||
| "license": "MIT", | ||
| "dependencies": { | ||
| "@nodejs/codemod-utils": "*" | ||
| } | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import removeDependencies from '@nodejs/codemod-utils/remove-dependencies'; | ||
|
|
||
| /** | ||
| * Remove tape and @types/tape dependencies from package.json | ||
| */ | ||
| export default function removeTapeDependencies(): string | null { | ||
| return removeDependencies(['tape', '@types/tape']); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.