Giter Site home page Giter Site logo

psmodule / test-psmodule Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 100 KB

Test PowerShell modules with Pester and PSScriptAnalyzer.

Home Page: https://psmodule.io

License: MIT License

PowerShell 100.00%
powershell powershell-module pester psscriptanalyzer testing github-action

test-psmodule's Introduction

Test-PSModule

Test PowerShell modules with Pester and PSScriptAnalyzer.

This GitHub Action is a part of the PSModule framework. It is recommended to use the Process-PSModule workflow to automate the whole process of managing the PowerShell module.

Specifications and practices

Test-PSModule enables:

How it works

The action runs the following the Pester test framework:

  • PSScriptAnalyzer tests
  • PSModule framework tests
  • If TestType is set to Module:
    • The module manifest is tested using Test-ModuleManifest.
    • The module is imported.
    • Custom module tests from the tests directory in the module repository are run.
    • CodeCoverage is calculated.
  • If TestType is set to SourceCode:
    • The source code is tested with:
      • PSScriptAnalyzer for best practices, using custom settings.
      • PSModule.SourceCode for other PSModule standards.
  • The action returns a passed output that is true if all tests pass, else false.
  • The following reports are calculated and uploaded as artifacts:
    • Test suite results.
    • Code coverage results.

The action fails if any of the tests fail or it fails to run the tests. This is mitigated by the continue-on-error option in the workflow.

How to use it

To use the action, create a new file in the .github/workflows directory of the module repository and add the following content.

Workflow suggestion - before module is built
name: Test-PSModule

on: [push]

jobs:
  Test-PSModule:
    name: Test-PSModule
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repo
        uses: actions/checkout@v4

      - name: Initialize environment
        uses: PSModule/Initialize-PSModule@main

      - name: Test-PSModule
        uses: PSModule/Test-PSModule@main
        with:
          Path: src
          TestType: SourceCode
Workflow suggestion - after module is built
name: Test-PSModule

on: [push]

jobs:
  Test-PSModule:
    name: Test-PSModule
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repo
        uses: actions/checkout@v4

      - name: Initialize environment
        uses: PSModule/Initialize-PSModule@main

      - name: Test-PSModule
        uses: PSModule/Test-PSModule@main
        with:
          Path: outputs/modules
          TestType: Module

Usage

Inputs

Name Description Required Default
Path The path to the code to test. true
TestType The type of tests to run. Can be either Module or SourceCode. true
Name The name of the module to test. The name of the repository is used if not specified. false
TestsPath The path to the tests to run. false tests
StackTraceVerbosity Verbosity level of the stack trace. Allowed values: None, FirstLine, Filtered, Full. false None
Verbosity Verbosity level of the test output. Allowed values: None, Normal, Detailed, Diagnostic. false Detailed

Outputs

Name Description Possible values
passed If the tests passed. true, false

PSModule tests

The PSModule framework tests verifies the following coding practices that the framework enforces:

  • Script filename and function/filter name should match.

Tools

test-psmodule's People

Contributors

mariusstorhaug avatar

Stargazers

 avatar

Watchers

 avatar

test-psmodule's Issues

[New test]: Check that params have examples

Description

When writing params, ensure that every [PARAMETER()] description has a Example set.

params(
   # This is a description
   # Example: 'This is an example of a description'
   [Parameter()]
   $Description
)

[New Test] Compatability warning: Use of ternary

Description

Use of ternary operator limits use of module to 7.0 and newer.

Use of ternary should set required PowerShellVersion to be Core and atleast 7.0

Should assure we dont get the alias ? for Where-Object.

[New test] All the required module are specified in the script header

All scripts should be using a #Required if it is relying on external PS modules.

For each file

  • Collect the #Requires modules
  • Search the file for all the commands
  • list the modules they belong to
  • see if they are apart of the Get-PSResource module list
  • for each of the modules found, verify they are defines in the #Required list
  • If it is missing, then fail the test.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.