Developer-Dashboard

 view release on metacpan or  search on metacpan

t/12-legacy-helper-coverage.t  view on Meta::CPAN

ok( Developer::Dashboard::Folder->tmp, 'Folder tmp resolves a temp dir' );
is( Developer::Dashboard::Folder->dd, $paths->runtime_root, 'Folder dd resolves runtime root' );
is( Developer::Dashboard::Folder->runtime_root, $paths->runtime_root, 'Folder AUTOLOAD resolves runtime_root through the legacy runtime alias' );
is( Developer::Dashboard::Folder->bookmarks, $paths->dashboards_root, 'Folder bookmarks resolves dashboards root' );
is( Developer::Dashboard::Folder->bookmarks_root, $paths->dashboards_root, 'Folder AUTOLOAD resolves bookmarks_root through the legacy bookmarks alias' );
is( Developer::Dashboard::Folder->configs, $paths->config_root, 'Folder configs resolves config root' );
is( Developer::Dashboard::Folder->config_root, $paths->config_root, 'Folder AUTOLOAD resolves config_root through the legacy configs alias' );
is_deeply( Developer::Dashboard::Folder->all, $paths->all_paths, 'Folder all returns the full dashboard paths inventory' );
ok( -d Developer::Dashboard::Folder->postman, 'Folder postman creates the neutral postman directory' );

my $cd_result = Developer::Dashboard::Folder->cd(
    alias_demo => sub {
        my ($ctx) = @_;
        $ctx->{stay}->($ctx->{caller});
        return $ctx->{dir};
    }
);
is( $cd_result, $project, 'Folder cd yields the target directory to the callback' );
my @folder_listing = Developer::Dashboard::Folder->ls('alias_demo');
ok( @folder_listing >= 0, 'Folder ls returns entries for a real directory' );
ok( grep( { $_ eq $project } Developer::Dashboard::Folder->locate('demo') ), 'Folder locate finds matching workspace directories' );
is( Developer::Dashboard::Folder->alias_demo, $project, 'Folder AUTOLOAD resolves configured aliases' );
{
    my $repo = File::Spec->catdir( $workspace, 'folder-config-repo' );
    make_path( File::Spec->catdir( $repo, '.git' ) );
    make_path( File::Spec->catdir( $repo, '.developer-dashboard', 'config' ) );
    open my $fh, '>', File::Spec->catfile( $repo, '.developer-dashboard', 'config', 'config.json' ) or die $!;
    print {$fh} <<'JSON';
{
  "path_aliases": {
    "docker": "~/docker-alias"
  }
}
JSON
    close $fh;
    my $docker_alias = File::Spec->catdir( $home, 'docker-alias' );
    make_path($docker_alias);
    local $Developer::Dashboard::Folder::PATHS = undef;
    local %Developer::Dashboard::Folder::ALIASES = ();
    local %Developer::Dashboard::Folder::CONFIG_ALIASES = ();
    local $Developer::Dashboard::Folder::CONFIG_ALIASES_KEY = '';
    my $cwd = Cwd::cwd();
    chdir $repo or die "Unable to chdir to $repo: $!";
    is( Developer::Dashboard::Folder->docker, $docker_alias, 'Folder AUTOLOAD lazily resolves config-backed path aliases in a plain Perl process' );
    chdir $cwd or die "Unable to chdir to $cwd: $!";
}

my $zipped = zip('print qq{ok};');
ok( $zipped->{raw}, 'zip returns a raw token' );
is( unzip( $zipped->{raw} ), 'print qq{ok};', 'unzip reverses raw tokens' );
like( __cmdx( perl => 'print 1;' ), qr/base64 -d \| gunzip/, '__cmdx builds a shell decode pipeline' );
my @cmdx = _cmdx( perl => 'print 1;' );
is_deeply( [ @cmdx[ 0, 1 ] ], [ 'perl', '-e' ], '_cmdx returns shell tuple metadata' );
my @cmdp = _cmdp( perl => 'print 1;' );
is( $cmdp[1], 'perl', '_cmdp returns pipeline metadata' );
my $ajax_url = acmdx( type => 'json', code => 'print qq{{}};' );
like( $ajax_url->{url}{tokenised}, qr{^/ajax\?token=}, 'acmdx builds a tokenised ajax url' );
my $ajax_singleton_url = acmdx( type => 'text', code => 'print qq{ok};', singleton => 'TRANSIENT' );
like( $ajax_singleton_url->{url}{tokenised}, qr/[?&]singleton=TRANSIENT/, 'acmdx carries the optional singleton value into transient ajax urls' );
my ( $ajax_stdout, undef, $ajax_result ) = capture {
    return Ajax( jvar => 'configs.coverage.endpoint', code => 'print qq{{}};' );
};
like( $ajax_stdout, qr/set_chain_value/, 'Ajax prints the legacy config-binding script' );
is( $ajax_result, 'HIDE-THIS', 'Ajax returns the legacy hide marker' );
my ( $ajax_singleton_stdout, undef, $ajax_singleton_result ) = capture {
    return Ajax( jvar => 'configs.coverage.endpoint', code => 'print qq{{}};', singleton => 'TRANSIENT' );
};
like( $ajax_singleton_stdout, qr/[?&]singleton=TRANSIENT/, 'Ajax carries the optional singleton value into transient ajax bindings' );
is( $ajax_singleton_result, 'HIDE-THIS', 'Ajax still returns the hide marker when a transient singleton is supplied' );
{
    local $Developer::Dashboard::Zipper::AJAX_CONTEXT = {
        source               => 'saved',
        page_id              => 'coverage-page',
        runtime_root         => $paths->runtime_root,
        allow_transient_urls => 0,
    };
    my ( $saved_ajax_stdout, undef, $saved_ajax_result ) = capture {
        return Ajax(
            jvar      => 'configs.coverage.saved',
            file      => 'coverage.json',
            singleton => 'coverage-stream',
            code      => 'print qq{{"ok":1}};',
        );
    };
    like( $saved_ajax_stdout, qr{/ajax/coverage\.json\?type=text&singleton=coverage-stream}, 'Ajax prints a saved bookmark ajax url with the default text type and singleton when a file name is supplied' );
    is( $saved_ajax_result, 'HIDE-THIS', 'saved bookmark Ajax still returns the hide marker' );
    ok( -f Developer::Dashboard::Zipper::saved_ajax_file_path( runtime_root => $paths->runtime_root, file => 'coverage.json' ), 'saved bookmark Ajax stores the named ajax code file under the dashboards ajax tree' );
    ok( -x Developer::Dashboard::Zipper::saved_ajax_file_path( runtime_root => $paths->runtime_root, file => 'coverage.json' ), 'saved bookmark Ajax marks the stored dashboards ajax tree file executable' );
    is( Developer::Dashboard::Zipper::load_saved_ajax_code( runtime_root => $paths->runtime_root, file => 'coverage.json' ), 'print qq{{"ok":1}};', 'saved bookmark Ajax stored code can be loaded back from the dashboards ajax tree' );
    my $saved_ajax_error = eval {
        Ajax(
            jvar => 'configs.coverage.saved',
            code => 'print qq{{"ok":1}};',
        );
        '';
    } || $@;
    like( $saved_ajax_error, qr/file is required/, 'saved bookmark Ajax requires a file name when transient token urls are disabled' );
}
{
    my $existing_path = Developer::Dashboard::Zipper::saved_ajax_file_path(
        runtime_root => $paths->runtime_root,
        file         => 'existing.sh',
    );
    my $existing_dir = dirname($existing_path);
    make_path($existing_dir);
    open my $fh, '>', $existing_path or die $!;
    print {$fh} "#!/bin/sh\nprintf 'existing coverage\\n'\n";
    close $fh;
    chmod 0700, $existing_path or die $!;

    local $Developer::Dashboard::Zipper::AJAX_CONTEXT = {
        source               => 'saved',
        page_id              => 'coverage-existing',
        runtime_root         => $paths->runtime_root,
        allow_transient_urls => 0,
    };
    my ( $stdout, undef, $result ) = capture {
        return Ajax(
            jvar => 'configs.coverage.existing',
            file => 'existing.sh',
            type => 'text',
        );
    };
    like( $stdout, qr{/ajax/existing\.sh\?type=text}, 'Ajax prints a saved bookmark ajax url when only an existing file name is supplied' );
    is( $result, 'HIDE-THIS', 'saved bookmark Ajax with only a file still returns the hide marker' );
    is( Developer::Dashboard::Zipper::load_saved_ajax_code( runtime_root => $paths->runtime_root, file => 'existing.sh' ), "#!/bin/sh\nprintf 'existing coverage\\n'\n", 'saved bookmark Ajax with only a file leaves the existing executable content unch...



( run in 1.395 second using v1.01-cache-2.11-cpan-524268b4103 )