<commit_before>use strict;
use warnings;
use Test::More;
use Test::Warn;
use Data::Dumper;

BEGIN {
    $ENV{SGN_SKIP_CGI} = 1; #< don't need to compile all the CGIs
    use_ok 'Catalyst::Test', 'SGN';
    use_ok 'SGN::Controller::JavaScript';
}

my $controller = SGN->controller('JavaScript');

my ($res, $c) = ctx_request('/');

{ # test serving a JS package
    my $test_uri = $c->uri_for( $controller->action_for_js_package([ 'sgn.js', 'jquery.js', 'Text.Markup' ]));
    like( $test_uri, qr! js/pack/[a-z\d]+$ !x, 'got a kosher-looking pack URI' );

    ($res, $c) = ctx_request( $test_uri );
    cmp_ok( length($res->content), '>', 8000, 'got a big-looking response' )
        or diag "response was actually:\n", explain $res;

    like( $res->content, qr/jQuery/, 'there is some jquery in it' );
    like( $res->content, qr/Text\.Markup/, 'there is some Text.Markup in it' );
}

{ # test serving a single JS file

    like( get( '/js/Text/Markup.js' ), qr/function\s*\(/,
          'served a single JS file',
         );


    warning_like {
        $res = request( $c->uri_for( '/js/Nonexistent.js' ));
    } qr/Can't open .+Nonexistent.js/, 'got a warning about the missing file';
    like( $res->content,
          qr/not found/i,
          'nonexistent js says not found',
       );
    #die "$res";
    is( $res->code, 404, 'gives a 404' );

}

done_testing();
<commit_msg>used new test level functions to divide javascript controller tests into remote and local sections<commit_after>use strict;
use warnings;
use Test::More;
use Test::Warn;
use Data::Dumper;

use lib 't/lib';

use SGN::Test::WWW::Mechanize;
use Catalyst::Test 'SGN';

BEGIN { $ENV{SGN_SKIP_CGI} = 1 } #< don't need to compile all the CGIs

use_ok 'SGN::Controller::JavaScript';

my $mech = SGN::Test::WWW::Mechanize->new;

$mech->with_test_level( process => sub {
   my $controller = SGN->controller('JavaScript');
   my ($res, $c) = ctx_request('/');

   # test serving a JS package
   my $test_uri = $c->uri_for( $controller->action_for_js_package([ 'sgn.js', 'jquery.js', 'Text.Markup' ]));
   like( $test_uri, qr! js/pack/[a-z\d]+$ !x, 'got a kosher-looking pack URI' );

   ($res, $c) = ctx_request( $test_uri );
   cmp_ok( length($res->content), '>', 8000, 'got a big-looking response' )
       or diag "response was actually:\n", explain $res;

   like( $res->content, qr/jQuery/, 'there is some jquery in it' );
   like( $res->content, qr/Text\.Markup/, 'there is some Text.Markup in it' );
});


{ # test serving a single JS file

    like( get( '/js/Text/Markup.js' ), qr/function\s*\(/,
          'served a single JS file',
         );

    my $res;
    if( $mech->can_test_level('process') ) {
        warning_like {
            $res = request( '/js/Nonexistent.js' );
        } qr/Can't open .+Nonexistent.js/, 'got a warning about the missing file';
    } else {
        $res = request( '/js/Nonexistent.js' );
    }

    like( $res->content, qr/not found/i,
          'nonexistent js says not found',
       );
    #die "$res";
    is( $res->code, 404, 'gives a 404' );

}

done_testing();

{'fraction_non_alphanumeric': 0.17751862649821834, 'fraction_numerical': 0.007126660187884677, 'mean_word_length': 3.073878627968338, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '741845', 'n_tokens_mistral': 1168, 'n_tokens_neox': 1107, 'n_words': 308}