-
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.
chore(test): coverage for nw.App (#26)
* Add nw.Window.isDevToolsOpen polyfill
- Loading branch information
1 parent
dbbfec2
commit 9619482
Showing
9 changed files
with
378 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,29 @@ | ||
/** | ||
* Query the status of devtools window.. | ||
* | ||
* @function | ||
* @param {(status: boolean) => void} callback - Callback function | ||
* @returns {void} | ||
*/ | ||
function isDevToolsOpen(callback) { | ||
chrome.windows.getAll({ | ||
populate: true, | ||
windowTypes: ['devtools'] | ||
}, | ||
function (wins) { | ||
callback(wins.length > 0); | ||
}) | ||
} | ||
|
||
/** | ||
* Polyfill function for missing NW.js functionality. | ||
* | ||
* The environment is checked before adding the relevant functions. | ||
*/ | ||
export default function polyfill () { | ||
if (process.versions['nw-flavor'] === 'sdk' && typeof nw.Window.isDevToolsOpen !== 'function') { | ||
nw.Window.isDevToolsOpen = isDevToolsOpen; | ||
global.nw.Window.isDevToolsOpen = isDevToolsOpen; | ||
window.nw.Window.isDevToolsOpen = isDevToolsOpen; | ||
} | ||
} |
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,15 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Basic</title> | ||
<script src="./index.js"></script> | ||
</head> | ||
|
||
<body id="test"> | ||
Hello, World! | ||
</body> | ||
|
||
</html> |
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,11 @@ | ||
nw.Window.isDevToolsOpen = isDevToolsOpen; | ||
|
||
function isDevToolsOpen(callback) { | ||
chrome.windows.getAll({ | ||
populate: true, | ||
windowTypes: ['devtools'] | ||
}, | ||
function (wins) { | ||
callback(wins.length > 0); | ||
}) | ||
} |
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,6 @@ | ||
{ | ||
"name": "custom-app", | ||
"main": "index.html", | ||
"description": "Placeholder app to test various things in NW.js", | ||
"type": "module" | ||
} |
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,52 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<script> | ||
document.addEventListener('DOMContentLoaded', () => { | ||
document.getElementById('nw-app-argv').innerText = nw.App.argv; | ||
document.getElementById('nw-app-fullargv').innerText = nw.App.fullArgv; | ||
document.getElementById('nw-app-filteredargv').innerText = nw.App.filteredArgv; | ||
document.getElementById('nw-app-startpath').innerText = nw.App.startPath; | ||
document.getElementById('nw-app-datapath').innerText = nw.App.dataPath; | ||
document.getElementById('nw-app-manifest').innerText = JSON.stringify(nw.App.manifest); | ||
}); | ||
</script> | ||
<title>nw.App fixture</title> | ||
</head> | ||
|
||
<body> | ||
<div> | ||
<span>nw.App.argv: </span> | ||
<span id="nw-app-argv"></span> | ||
</div> | ||
<br> | ||
<div> | ||
<span>nw.App.fullArgv: </span> | ||
<span id="nw-app-fullargv"></span> | ||
</div> | ||
<br> | ||
<div> | ||
<span>nw.App.filteredArgv: </span> | ||
<span id="nw-app-filteredargv"></span> | ||
</div> | ||
<br> | ||
<div> | ||
<span>nw.App.startPath: </span> | ||
<span id="nw-app-startpath"></span> | ||
</div> | ||
<br> | ||
<div> | ||
<span>nw.App.dataPath: </span> | ||
<span id="nw-app-datapath"></span> | ||
</div> | ||
<br> | ||
<div> | ||
<span>nw.App.manifest: </span> | ||
<span id="nw-app-manifest"></span> | ||
</div> | ||
</body> | ||
|
||
</html> |
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,4 @@ | ||
{ | ||
"name": "nw-app", | ||
"main": "index.html" | ||
} |
Oops, something went wrong.