npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

expect.ahk

v0.1.1

Published

expect.ahk is a testing package to perform and report on tests for AutoHotkey projects. It is Test Anything Protocol (TAP) compliant

Downloads

20

Readme

expect.ahk

A Test Anything Protocol (TAP) compliant unit testing package for AutoHotkey

Installation

In a terminal or command line navigated to your project folder:

npm install expect.ahk

In your code only export.ahk needs to be included:

#Include %A_ScriptDir%\node_modules
#Include expect\export.ahk
expect := new expect()

testVar := 2 + 2
expect.equal(testVar, 4)
expect.fullReport()

You may also review or copy the library from ./export.ahk on GitHub; #Include as you would normally when manually downloading.

Usage

Grants access to a class named expect with the following methods: .equal, .notEqual, .true, .false, .label, .group, .report, .fullReport, and .writeTestResultsToFile

expect := new expect()

; .equal checks and logs whether or not both arguments are the same
expect.label("string comparison")
expect.equal("StringExample", "StringExample")

expect.label("value testing")
expect.equal((1 > 0 ), true)

expect.label("true/false testing")
expect.true((1 == 1))
expect.false((1 != 1))
expect.notEqual(true,false)

expect.report()
expect.fullReport()
expect.writeTestResultsToFile()

API

.equal(actual, expected)

Alias: .test

checks if actual and expected are the same or equal. The comparison is case-insensitive when ahk is inStringCaseSense, Off (default ahk behavior)

Arguments
  1. actual (*): The actual value computed
  2. expected (*): The expected value
Returns

(boolean): returns true if the values were the same, else false

Example
expect.equal("string", "tsring")
; => false

expect.equal((1 > 0 ), true)
; => true

.true(actual)

checks if actual value is true.

Arguments
  1. actual (*): The actual value computed
Returns

(boolean): returns true if the value is true, else false

Example
expect.true((1 == 1))
; => true

expect.true(InStr("String", "S"))
; => true

.false(actual)

checks if actual value is false.

Arguments
  1. actual (*): The actual value computed
Returns

(boolean): returns true if the value is false, else false

Example
expect.false((1 != 1))
; => true

expect.false(InStr("String", "X"))
; => true

.notEqual(actual, expected)

checks if actual and expected are NOT the same or equal. The comparison is case-insensitive when ahk is inStringCaseSense, Off (default ahk behavior)

Arguments
  1. actual (*): The actual value computed
  2. expected (*): The expected value
Returns

(boolean): returns true if the value is false, else false

Example
expect.notEqual((1 != 1))
; => true

expect.notEqual(InStr("String", "X"))
; => true

.undefined(actual)

checks if actual is undefined ("").

Arguments
  1. actual (*): The actual value computed
Returns

(boolean): returns true if the value is "", else false

Example
expect.false((1 != 1))
; => true

expect.false(InStr("String", "X"))
; => true

.label(label)

labels the following tests for logs and readability

Arguments
  1. label (string): A human readable label for the next test(s) in sequence
Example
expect.label("string comparisons")

expect.equal("String", "s")
expect.fullReport()
/*---------------------------
1 tests completed with 0% success (1 failure)
=================================
== string comparisons ==
Test Number: 1
Expected: s
Actual: String
---------------------------*/

.group(label)

appends the label to a group of following tests for logs and readability

This may be useful when one has a lot of tests; and doesn't want to type out a repeatative label

Arguments
  1. label (string): A human readable label prepend for the next test(s) in sequence
Example
expect.group("strings")
expect.label("comparison")
expect.equal("String", "s")

expect.label("length")
expect.equal(strLen("String"), 9)

expect.fullReport()
/*---------------------------
2 tests completed with 0% success (2 failures)
=================================
== strings - comparisons ==
Test Number: 1
Expected: s
Actual: String

== strings - length ==
Test Number: 2
Expected: 99
Actual: 6
---------------------------*/

.report()

Uses msgbox to display the results of all tests

Example
expect.true(InStr("String", "S"))

expect.report()
/*---------------------------
1 test completed with 100% success
---------------------------*/

.fullReport()

Uses msgbox to display the results of all tests with details of any failures

Example
expect.true(InStr("String", "X"))

expect.fullReport()
/*---------------------------
1 tests completed with 0% success (1 failure)
=================================
Test Number: 1
Expected: true
Actual: false
---------------------------*/

.writeResultsToFile([filepath, fileopen])

writes test results to a file

Arguments
  1. filepath (string): Optional, The file path to write all tests results to, the default is A_ScriptDir "\result.tests.log"

  2. fileopen (bool): Optional, Open the file if true. Default: false

Example
expect.true(InStr("String", "X"))

expect.writeTestResultsToFile()
/*
1 test completed with 0% success (1 failure)

Test Number: 1
Expected: true
Actual: false*/