forked from Mr0grog/google-docs-to-markdown
-
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.
There is now a “download” button alongside the “copy” button for the converted Markdown code. It saves the results to a file named `Converted Text.md`. This also involved some complex additions to the tests in order to create temp directories that the browsers could download files to and be validated. Running tests now creates directories named `temp/chrome/`, `temp/firefox/`, and `temp/safari/` for each browser to work in. Unfortunately, there doesn’t seem to be an obvious way to set the download path for Safaridriver, so the test for this feature is skipped in that browser. :( Co-authored-by: Rob Brackett <[email protected]>
- Loading branch information
Showing
8 changed files
with
197 additions
and
10 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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
.DS_Store | ||
|
||
node_modules | ||
dist | ||
logs | ||
temp | ||
coverage | ||
|
||
scratch.* |
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
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { AssertionError } from 'node:assert'; | ||
import * as fs from 'node:fs/promises'; | ||
import * as path from 'node:path'; | ||
|
||
/** | ||
* Get the absolute path a temporary directory that tests can use for working | ||
* with files and that test browsers are configured to download files to. | ||
* @param {string|{browserName: string}|{capabilities: {browserName: string}}} browser | ||
* The name of the browser/test environment to get a temp directory for, | ||
* or a Webdriver capabilities or browser object identifying the browser. | ||
* @returns {string} | ||
*/ | ||
export function getTestTempDirectory(browser) { | ||
const browserName = browser?.capabilities?.browserName | ||
?? browser?.browserName | ||
?? browser; | ||
if (typeof browserName !== 'string') { | ||
throw new TypeError('The first argument must be a string or browser/capability object'); | ||
} | ||
return path.join(global.tempDirectory, browserName.toLowerCase()); | ||
} | ||
|
||
/** | ||
* Wait for a file to exist, or reject with an error after timing out. | ||
* @param {string} filePath | ||
* @param {number} [timeout] | ||
* @returns {Promise<void>} | ||
*/ | ||
export async function waitForFileExists(filePath, timeout = 5_000) { | ||
const parentPath = path.dirname(filePath); | ||
const basename = path.basename(filePath); | ||
|
||
// Start watching first to eliminate any race conditions. | ||
const aborter = new AbortController(); | ||
const watcher = fs.watch(parentPath, { signal: aborter.signal }); | ||
const timer = setTimeout(() => { | ||
aborter.abort(new AssertionError({ | ||
message: `File did not exist at ${filePath} after ${timeout} ms` | ||
})); | ||
}, timeout); | ||
|
||
// Check whether the file already exists and stop watching if so. | ||
try { | ||
await fs.access(filePath, fs.constants.F_OK); | ||
aborter.abort('File already exists'); | ||
return; | ||
} | ||
catch (_error) { | ||
try { | ||
for await (const { eventType, filename } of watcher) { | ||
if (eventType === 'rename' && filename === basename) { | ||
return; | ||
} | ||
} | ||
} | ||
catch (error) { | ||
// The AbortError you get from watch() is uninformative, so unwrap its | ||
// cause (if present) and throw that instead. | ||
throw error.cause || error; | ||
} | ||
} | ||
finally { | ||
clearTimeout(timer); | ||
} | ||
} |
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