Skip to content

Refer to a script in a parent directory #2416

@erossini

Description

@erossini

Checklist

Summary of the feature request

To organize better the scripts and the relative tests, I created in my pipeline a simple structure: the scripts folder has all the scripts; then the tests folder contains the folder for each script and the necessary files.

image

I have an issue in find the script from the test in the setup. For example, the code is

Describe "Setup" {
    BeforeAll {
        . $PSCommandPath.Replace('.Tests.ps1', '.ps1') -flowJsonPath $flowJsonPath
    }
}

Also, I tried to write the setup like this

Describe "Setup" {
    BeforeAll {
        $scriptName = [System.IO.Path]::GetFileName($PSCommandPath.Replace('.Tests.ps1', '.ps1'))
        $scriptPath = Split-Path -Parent $PSCommandPath.Replace('.Tests.ps1', '.ps1')
        $scriptPath = $scriptPath -replace "Tests\\JsonFiltering", ""
        $script = [System.IO.Path]::Combine($scriptPath, $scriptName)
        . $script -flowJsonPath $flowJsonPath -flowTycheJsonPath $flowTycheJsonPath -outputFilePath $outputFilePath
    }
}

but I still get an error

CommandNotFoundException: The term 'C:\Users\A084\Documents\Projects\MyProject\pipelines\Scripts\Tests\JsonFiltering\JsonFilte
ring.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Is there a way to use a script in the parent directory?

How should it work?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions