فهرست منبع

update unit tests

George S. Baugh 4 سال پیش
والد
کامیت
ffca48316b
1فایلهای تغییر یافته به همراه15 افزوده شده و 40 حذف شده
  1. 15 40
      t/Playwright.t

+ 15 - 40
t/Playwright.t

@@ -63,15 +63,14 @@ subtest "_build_classes" => sub {
 
 subtest "_check_node" => sub {
     my $which = Test::MockModule->new('File::Which');
-    $which->redefine('which', sub { "$path2here/../bin/playwright_server" });
 
-    my $bin = Test::MockFile->file("$path2here/../bin/playwright_server");
-    like( dies { Playwright::_check_node() }, qr/server in/i, "Server not existing throws");
+    my %to_return = (
+        node => '/bogus',
+        npm  => '/hokum',
+        playwright_server => "$path2here/../bin/playwright_server",
+    );
 
-    undef $bin;
-    $bin = Test::MockFile->file("$path2here/../bin/playwright_server",'');
-
-    $which->redefine('which', sub { shift eq 'node' ? '/bogus' : '/hokum' });
+    $which->redefine('which', sub { my $to = shift; $to_return{$to} } );
     my $node = Test::MockFile->file('/bogus', undef, { mode => 0777 } );
     my $npm  = Test::MockFile->file('/hokum', undef, { mode => 0777 } );
 
@@ -79,6 +78,12 @@ subtest "_check_node" => sub {
     undef $node;
     $node = Test::MockFile->file('/bogus', '', { mode => 0777 } );
 
+    my $bin = Test::MockFile->file("$path2here/../bin/playwright_server");
+    like( dies { Playwright::_check_node() }, qr/server in/i, "Server not existing throws");
+
+    undef $bin;
+    $bin = Test::MockFile->file("$path2here/../bin/playwright_server",'');
+
     like( dies { Playwright::_check_node() }, qr/npm must exist/i, "npm not existing throws");
     undef $npm;
     $npm  = Test::MockFile->file('/hokum', '', { mode => 0777 } );
@@ -89,38 +94,6 @@ subtest "_check_node" => sub {
     my $pmock = Test::MockModule->new('File::pushd');
     $pmock->redefine('pushd', sub {shift});
 
-    $qxret = '';
-    like( dies { Playwright::_check_node() }, qr/could not list/i, "package.json not existing throws");
-
-    $qxret = '{
-        "name": "playwright-server-perl",
-          "version": "1.0.0",
-          "problems": [
-            "missing: express@^4.17, required by playwright-server-perl@1.0.0",
-            "missing: playwright@^1.5, required by playwright-server-perl@1.0.0",
-            "missing: yargs@^16.1, required by playwright-server-perl@1.0.0",
-            "missing: uuid@^8.3, required by playwright-server-perl@1.0.0"
-          ],
-          "dependencies": {
-            "express": {
-              "required": "^4.17",
-              "missing": true
-            },
-            "playwright": {
-              "required": "^1.5",
-              "missing": true
-            },
-            "yargs": {
-              "required": "^16.1",
-              "missing": true
-            },
-            "uuid": {
-              "required": "^8.3",
-              "missing": true
-            }
-          }
-    }';
-
     #XXX doesn't look like we can mock $? correctly
     #like( dies { Playwright::_check_node($path2here, $decoder) }, qr/installing node/i, "npm failure throws");
     $fakecapture->redefine('capture_stderr', sub { 'package-lock' });
@@ -148,9 +121,10 @@ subtest "new" => sub {
         parent => $$,
         pid    => 666,
         port   => 420,
+        timeout => 5,
     }, 'Playwright');
 
-    is(Playwright->new( ua => 'whee', debug => 1), $expected, "Constructor functions as expected");
+    is(Playwright->new( timeout => 5, ua => 'whee', debug => 1), $expected, "Constructor functions as expected");
 
     $expected = bless({
         ua     => bless({},'LWP::UserAgent'),
@@ -158,6 +132,7 @@ subtest "new" => sub {
         parent => $$,
         pid    => 666,
         port   => 420,
+        timeout => 30,
     }, 'Playwright');
 
     is(Playwright->new(), $expected, "Constructor defaults expected");