Skip to content

Commit 0e0e15c

Browse files
committed
[test] add module binary test nwjs#6303
1 parent 7e7d468 commit 0e0e15c

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed

test/sanity/module-bin/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<body>
2+
<div id='result'>wait for value</div>
3+
<div id='source'>f.foo source:</div>
4+
<script>
5+
nw.Window.get().evalNWBinModule(null, 'lib.bin', 'lib.js');
6+
</script>
7+
<script type="module" src="testmodule.js"></script>
8+
</body>

test/sanity/module-bin/lib2.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class TestModule {
2+
foo(a) {
3+
return a + 42;
4+
}
5+
}
6+
7+
export {TestModule};

test/sanity/module-bin/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "helloworld",
3+
"main": "index.html",
4+
"dependencies": {}
5+
}

test/sanity/module-bin/test.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import time
2+
import os
3+
import shutil
4+
import subprocess
5+
import platform
6+
from subprocess import Popen, PIPE
7+
8+
from selenium import webdriver
9+
from selenium.webdriver.chrome.options import Options
10+
chrome_options = Options()
11+
testdir = os.path.dirname(os.path.abspath(__file__))
12+
chrome_options.add_argument("nwapp=" + testdir)
13+
binfile = os.path.join(testdir, "lib.bin")
14+
nwjc = os.path.join(os.path.dirname(os.environ['CHROMEDRIVER']), "nwjc.exe" if os.name == "nt" else "nwjc")
15+
os.chdir(testdir)
16+
try:
17+
os.remove(binfile)
18+
except:
19+
pass
20+
assert(False == os.path.isfile(binfile))
21+
subprocess.call([nwjc, "--nw-module", "lib2.js", "lib.bin"])
22+
assert(os.path.isfile(binfile))
23+
24+
if platform.system() == 'Linux':
25+
proc = Popen(['strings', 'lib.bin'], stdout=PIPE, stderr=PIPE)
26+
out, err = proc.communicate()
27+
print out
28+
assert("42" not in out)
29+
assert("foo" not in out)
30+
31+
driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options)
32+
try:
33+
print driver.current_url
34+
result = driver.find_element_by_id('result')
35+
print result.get_attribute('innerHTML')
36+
assert("52" in result.get_attribute('innerHTML'))
37+
result2 = driver.find_element_by_id('source').get_attribute('innerHTML')
38+
print result2
39+
assert("{ [native code] }" in result2)
40+
finally:
41+
driver.quit()

test/sanity/module-bin/testmodule.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {TestModule} from "./lib.js";
2+
3+
var f = new TestModule();
4+
document.getElementById('result').innerHTML = 'result: ' + f.foo(10);
5+
document.getElementById('source').innerHTML = "f.foo source: " + f.foo.toString();

0 commit comments

Comments
 (0)