Skip to content

Instantly share code, notes, and snippets.

@javascripto
Created March 8, 2022 12:46
Show Gist options
  • Select an option

  • Save javascripto/9528b3f77e7915f75b81e503dcd0a8e5 to your computer and use it in GitHub Desktop.

Select an option

Save javascripto/9528b3f77e7915f75b81e503dcd0a8e5 to your computer and use it in GitHub Desktop.
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