GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Support test files alongside source like Pester suggests · Issue #108 · PoshCode/ModuleBuilder

Support test files alongside source like Pester suggests #108

New issue
Copy link
New issue
Copy link
Open
Open
Support test files alongside source like Pester suggests#108
Copy link
Labels
20 - Enhancement21 - HacktoberfestThese tickets are particularly easy to do without understanding the whole codebaseThese tickets are particularly easy to do without understanding the whole codebase

Description

@sjwestern
sjwestern
opened on Oct 8, 2021
Issue body actions

Is it possible to have test files next to their source files instead of in a separate directory?
This seems to be pretty standard and is the Pester docs recommended way of doing it.

Activity

  1. Jaykul commented on Oct 9, 2021

    @Jaykul
    Jaykul
    on Oct 9, 2021
    Member
    More actions

    Well, obviously I disagree that it's standard or the best way (and Pester itself certainly doesn't do that) but I would be happy to add support for Exclude. Honestly, I think we could even add a default Exclude = "*.Tests.ps1" although it would technically be a breaking change, so maybe not worth it.

    You can easily hard code that in a fork for yourself though. You would just need to change line 206 of Build-Module.ps1

                # SilentlyContinue because there don't *HAVE* to be functions at all
                $AllScripts = Get-ChildItem -Path @($ModuleInfo.SourceDirectories).ForEach{ Join-Path $ModuleInfo.ModuleBase $_ } -Filter *.ps1 -Recurse -ErrorAction SilentlyContinue

    to add -Exclude *.tests.ps1 like:

                # SilentlyContinue because there don't *HAVE* to be functions at all
                $AllScripts = Get-ChildItem -Path @($ModuleInfo.SourceDirectories).ForEach{ Join-Path $ModuleInfo.ModuleBase $_ } -Filter *.ps1 -Exclude *.tests.ps1 -Recurse -ErrorAction SilentlyContinue
    Reacted by sjwestern
  2. Jaykul commented on Oct 9, 2021

    @Jaykul
    Jaykul
    on Oct 9, 2021
    Member
    More actions

    I filed an issue against the Pester docs, because I can't find anyone who does that. I think they're talking about it from a "my first PowerShell script" practice, not module developers.

    Reacted by gaelcolas
  3. nohwnd commented on Oct 12, 2021

    @nohwnd
    nohwnd
    on Oct 12, 2021
    More actions

    @sjwestern putting test files next to your production files is just one of the ways to structure your projects. Pester suggests it as an option, because it is the simplest way to do it for simple projects. More advanced projects are usually split their code into src and tst / test / tests folder. The guidance in Pester docs was updated to reflect that.

    Reacted by gaelcolas
  4. sjwestern commented on Oct 14, 2021

    @sjwestern
    sjwestern
    on Oct 14, 2021
    Author
    More actions

    Thanks @Jaykul and @nohwnd appreciate your time.
    If that's what most PowerShell module projects do then I'll stick with that.
    I had just noticed the suggestion in Pester docs, which is similar to what Angular does - putting test files for components in the same location as the component files.

    Reacted by Joel Bennett
  5. Jaykul
    added
    20 - Enhancement
    21 - HacktoberfestThese tickets are particularly easy to do without understanding the whole codebaseThese tickets are particularly easy to do without understanding the whole codebase
    on Oct 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    20 - Enhancement21 - HacktoberfestThese tickets are particularly easy to do without understanding the whole codebaseThese tickets are particularly easy to do without understanding the whole codebase

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.