Created
March 8, 2022 12:46
-
-
Save javascripto/9528b3f77e7915f75b81e503dcd0a8e5 to your computer and use it in GitHub Desktop.
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
| export function openTestingPlayground() { | |
| const exec = require("util").promisify(require("child_process").exec); | |
| const originalLogFn = console.log.bind(console); | |
| console.log = function (...args) { | |
| const url = args[0].match(/http.*/)[0]; | |
| const commandsForEachPlatform = { | |
| linux: `xdg-open ${url}`, | |
| win32: `start chrome "${url}"`, | |
| darwin: `open ${url}`, | |
| }; | |
| const openUrlCommand = commandsForEachPlatform[process.platform]; | |
| return exec(openUrlCommand).finally(() => { | |
| console.log = originalLogFn; | |
| }); | |
| }; | |
| require("@testing-library/react").screen.logTestingPlaygroundURL(); | |
| console.log = originalLogFn; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment