-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: expose ability to save results of scripts to file. (#48)
* feat: add writeFile, appendFile to exposed functions * fix: await exposed functions * chore: update Readme * chore: add changeset
- Loading branch information
Showing
4 changed files
with
110 additions
and
44 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
"@heymp/scratchpad": minor | ||
--- | ||
|
||
Add `writeFile`, `appendFile` exposed functions. (#44)[https://github.com/heyMP/scratchpad/issues/44] | ||
|
||
```.js | ||
await writeFile('./log.txt', 'hello'); | ||
await appendFile('./log.txt', '\n'); | ||
await appendFile('./log.txt', 'world'); | ||
``` | ||
|
||
Include custom exposed functions example. | ||
|
||
```.js | ||
import { join } from 'node:path' | ||
import fs from 'node:fs/promises'; | ||
|
||
function loadFile(path) { | ||
return fs.readFile(join(process.cwd(), path), 'utf8'); | ||
} | ||
|
||
export default /** @type {import('@heymp/scratchpad/src/config').Config} */ ({ | ||
playwright: async (args) => { | ||
const { context, page } = args; | ||
await context.exposeFunction('loadFile', loadFile) | ||
} | ||
}); | ||
``` |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
declare function log(...args: any[]): void; | ||
declare function clear(): void; | ||
declare function writeFile(string, any): Promise<void>; | ||
declare function appendFile(string, any): Promise<void>; |