File tree Expand file tree Collapse file tree 5 files changed +80
-0
lines changed Expand file tree Collapse file tree 5 files changed +80
-0
lines changed Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html >
3
+ < head >
4
+ < meta charset ="utf-8 ">
5
+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge ">
6
+ < title > worker-require-module</ title >
7
+ </ head >
8
+ < body >
9
+ < script >
10
+
11
+ function out ( id , msg ) {
12
+ var h1 = document . createElement ( 'h1' ) ;
13
+ h1 . setAttribute ( 'id' , id ) ;
14
+ h1 . innerHTML = msg ;
15
+ document . body . appendChild ( h1 ) ;
16
+ }
17
+
18
+ let buf = global . require ( 'fs' ) . readFileSync ( 'nw.bin' ) ;
19
+ ab = new global . ArrayBuffer ( buf . length ) ;
20
+ buf . copy ( Buffer . from ( ab ) ) ;
21
+
22
+ function tryRequire ( ) {
23
+ w = new Worker ( 'worker.js' ) ;
24
+ w . onmessage = ( e ) => out ( 'result' , e . data ) ;
25
+ w . postMessage ( ab ) ;
26
+ }
27
+
28
+ tryRequire ( ) ;
29
+ </ script >
30
+ </ body >
31
+ </ html >
Original file line number Diff line number Diff line change
1
+ function mytest ( a ) {
2
+ return a * 42 ;
3
+ }
4
+
5
+ mytest ( 10 ) ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " worker-stream-event" ,
3
+ "main" : " index.html"
4
+ }
Original file line number Diff line number Diff line change
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 , "nw.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 , "mytest.js" , "nw.bin" ])
22
+ assert (os .path .isfile (binfile ))
23
+
24
+ driver = webdriver .Chrome (executable_path = os .environ ['CHROMEDRIVER' ], chrome_options = chrome_options )
25
+ try :
26
+ print driver .current_url
27
+ result = driver .find_element_by_id ('result' )
28
+ print result .get_attribute ('innerHTML' )
29
+ assert ("840" == result .get_attribute ('innerHTML' ))
30
+ finally :
31
+ driver .quit ()
Original file line number Diff line number Diff line change
1
+ self . onmessage = function ( e ) {
2
+ var ab = e . data ;
3
+ try {
4
+ importNWBin ( ab ) ;
5
+ postMessage ( mytest ( 20 ) ) ;
6
+ } catch ( e ) {
7
+ postMessage ( e . message ) ;
8
+ }
9
+ }
You can’t perform that action at this time.
0 commit comments