git.iko.soy/rowtype-yoga/purescript-playwright
on main help sign in
Fix waitForFunction
commit45efc5947d6db6f9169aedc39af7c0b0b75b0d53 authorVladimir Kalnitsky <klntsky@gmail.com> dateSat 7 Nov 2020, 14:02 (6 years ago) parentcb5b440
4 files changed+9−26
spago.dhall+1 src/Playwright.purs+5−3 src/Playwright/Data.purs−2 test/Main.purs+3−21
spago.dhall+1
@@ -9,6 +9,7 @@
99 , "untagged-union"
1010 , "node-buffer"
1111 , "node-fs-aff"
12+ , "undefined"
1213 ]
1314, packages = ./packages.dhall
1415, sources = [ "src/**/*.purs", "test/**/*.purs" ]
src/Playwright.purs+5−3
@@ -47,7 +47,7 @@ where
4747import Data.String.Regex (Regex)
4848import Effect (Effect)
4949import Effect.Aff (Aff)
50−import Foreign (Foreign)
50+import Foreign (Foreign, unsafeToForeign)
5151import Literals.Null (Null)
5252import Node.Buffer (Buffer)
5353import Playwright.Data
@@ -56,6 +56,7 @@ import Playwright.Options
5656import Prelude (Unit)
5757import Untagged.Coercible (class Coercible)
5858import Untagged.Union (type (|+|), UndefinedOr)
59+import Undefined (undefined)
5960
6061launch
6162 :: forall o
@@ -315,10 +316,11 @@ waitForFunction
315316 => x
316317 -> String
317318 -- ^ Function to be evaluated in browser context
318− -> EvaluationArgument
319319 -> o
320320 -> Aff JSHandle
321−waitForFunction = affCall "waitForFunction" \_ -> waitForFunction
321+waitForFunction x s o = waitForFunction' x s (unsafeToForeign undefined) o
322+ where
323+ waitForFunction' = affCall "waitForFunction" \_ -> waitForFunction'
322324
323325waitForLoadState
324326 :: forall x o
src/Playwright/Data.purs−2
@@ -67,5 +67,3 @@ foreign import hidden :: ElementState
6767
6868foreign import data Raf :: Type
6969foreign import raf :: Raf
70−
71−type EvaluationArgument = Foreign
test/Main.purs+3−21
@@ -6,7 +6,6 @@ import Data.Maybe (Maybe(..))
66import Effect (Effect)
77import Effect.Class (liftEffect)
88import Effect.Ref as Ref
9−import Foreign (unsafeToForeign)
109import Node.FS.Aff as FS
1110import Playwright
1211import Playwright.ConsoleMessage as ConsoleMessage
@@ -79,12 +78,11 @@ main = runTest do
7978 withBrowserPage hello
8079 \page -> do
8180 void $ evaluate page
82− "setTimeout(() => document.body.textContent += 'test', 200)"
81+ "setTimeout(() => document.body.textContent += 'uniqstring', 1)"
8382 void $ waitForFunction
8483 page
85− "x => document.body.textContent.includes(x)"
86− (unsafeToForeign "test")
87− { timeout: 3000 }
84+ "document.body.textContent.includes('uniqstring')"
85+ { timeout: 5000, polling: 100 }
8886 suite "events" do
8987 test "console" do
9088 withBrowserPage hello
@@ -96,15 +94,7 @@ main = runTest do
9694 void $ evaluate page
9795 """
9896 console.log('hi');
99− setTimeout(() => {
100− document.body.textContent += 'test';
101− }, 100)
10297 """
103− void $ waitForFunction
104− page
105− "x => document.body.textContent.includes(x)"
106− (unsafeToForeign "test")
107− { timeout: 3000 }
10898 realMessage <- liftEffect $ Ref.read messageRef
10999 Assert.equal (Just "hi") realMessage
110100 test "console: ConsoleMessageType" do
@@ -117,14 +107,6 @@ main = runTest do
117107 void $ evaluate page
118108 """
119109 console.debug('hi');
120− setTimeout(() => {
121− document.body.textContent += 'test';
122− }, 100)
123110 """
124− void $ waitForFunction
125− page
126− "x => document.body.textContent.includes(x)"
127− (unsafeToForeign "test")
128− { timeout: 3000 }
129111 realType <- liftEffect $ Ref.read typeRef
130112 Assert.equal (Just ConsoleMessage.Debug) realType