test-tube.Test

The base test class. This class can function both as a test-suite and as a test instance. Additionally, this class implements “_main” and will act as the entry point to a test-suite if constructed with atom.o.main. Note, test-suites can be nested.

Instance Properties

_main
Object
Required
Description The entry point for the “run” command”
cmdargs
Object.<string, Object>
(read-only)
Description The cmdargs definition describing the command line interface when a test-suite is executed. See the atom documentation for a description of the format and options available.
description
string
Required
Description A short description of the test or test-suite used for display purposes
errorExpected
boolean | Error
Default false
Description Indicate that an error is expected to be thrown in this test. This can be used as shorthand alternative to using assert.throws. Note, if this is not a boolean, assert.throws will be used to validate the error thrown by the test.
name
string
Required
Description Name of the test. This is used for display and filtering purposes.
parent
(read-only)
Description A pointer to the “parent” test-suite. This is useful when a test needs to access a fixture created by the parent test-suite. It will be initialized by test-tube when the test tree is initialized.
selfBeforeChildren
boolean
Default false
Description A flag to indicate that doTest should be run before executing any tests in tests when an instance of Test acts as both a test and a test-suite (top-down vs. bottom-up execution).
tests
test-tube.Test[]
Required
Description A list of tests to execute as part of a test-suite. Note, these tests can themselves be test-suites.

Methods

_buildTestResult  
Return type TestResult
Description A factory function for test result objects
_checkName  
Arguments
Returns true if the test name is filtered, false otherwise
Return type boolean
Description Checks if the current test is filtered by name (think basename)
_checkPath  
Arguments
  • context (test-tube.TestContext) – A context object
  • useDirname (boolean) – Use path.dirname to grab the parent of the path retrieved from context
Returns true if the test path is filtered, false otherwise
Return type boolean
Description Checks if the current path is filtered where “path” is built using the test names as they appear in the depth-first traversal up to the current test being executed (think dirname)
_errorExpected  
Arguments
  • result (Object) – A test result object (see _buildTestResult)
  • error (Error) – An error object as thrown by the test
Returns An updated test result object
Return type Object
Description Updates test result if an error was expected and encountered
_generateReportHelper  
Arguments
  • result (TestResult) – The result object for this test
  • level (number) – The depth of this test in the overall test tree
Return type undefined
Description Recursively enerates and outputs the report for a test and sub-tests
_generateReportSummary  
Arguments
Return type undefined
Description The result object for the test-suite
_init  
Return type undefined
Description Initialize the test-suite
_initContext  
Arguments
Throws TypeError Thrown if testContextClass is not TestContext or a subclass thereof
Returns An instance of TestContext
Return type test-tube.TestContext
Description Initializes the TestContext object that will be passed down to every test in the tree
_initTest  
Arguments
Return type test-tube.Test
Description Initialize a single test in the test-suite
_initTests  
Return type undefined
Description Initializes all tests in tests
_log  
Arguments
  • msg (string) – A message to be logged
  • level (number) – The number of spaces to indent the message
Return type undefined
Description Logs a message to stdout, indenting each line as appropriate
_postrun  
Arguments
Return type undefined
Description Internal hook that can be extended to perform some teardown after the run method is called
_prerun  
Arguments
Return type undefined
Description Internal hook that can be extended to perform some setup before the run method is called
_runSelf  
Arguments
Return type SelfTestResult
Description Runs doTest and generates a result
generateReport  
Arguments
Return type undefined
Description The top-level test result object
run  
Arguments
  • context (test-tube.TestContext) – A context object
  • done (function) – Errback to call when executing asynchronously
Return type TestResult
Description run description
setup  
Arguments
  • context (test-tube.TestContext) – A context object that can be used to pass data between tests or their methods.
  • done (function) – Errback to call when executing asynchronously. Note, when implementing a test, if this is not included in the parameter list, the test will be called synchronously and you will not be responsible for calling the errback.
Return type undefined
Description Setup any fixtures required for doTest or any test in tests
teardown  
Arguments
  • context (test-tube.TestContext) – A context object that can be used to pass data between tests or their methods.
  • done (function) – Errback to call when executing asynchronously. Note, when implementing a test, if this is not included in the parameter list, the test will be called synchronously and you will not be responsible for calling the errback.
Returns undefined
Return type undefined
Description Teardown (cleanup) any fixtures that may have been created in setup
toJSON  
Return type Object
Description Generates a simplified Object representing the test instance suitable for serializing to JSON

Typedef: SelfTestResult

Properties

passed
boolean
Required
Description A flag indicating the status of a test
skipped
boolean
Required
Description A flag indicating whether a test was skipped
skippedTag
string
Required
Description A tag used to augment the output line for a skipped test (defaults to “SKIPPED”)
filtered
boolean
Required
Description A flag indicating whether a test was filtered
error
Error
Required
Description An error thrown during test execution. Note, this can happen in setup, doTest, or teardown
time
number
Required
Description The execution time of a test (and it’s sub-tests) in milliseconds

Typedef: TestResult

Properties

name
string
Required
Description A test name
description
string
Required
Description A test description
passed
boolean
Required
Description A flag indicating the status of a test
skipped
boolean
Required
Description A flag indicating whether a test was skipped
skippedTag
string
Required
Description A tag used to augment the output line for a skipped test (defaults to “SKIPPED”)
filtered
boolean
Required
Description A flag indicating whether a test was filtered
report
boolean
Required
Description A flag indicating whether a test should be included in the final test-suite report
error
Error
Required
Description An error thrown during test execution. Note, this can happen in setup, doTest, or teardown
self
Required
Description An intermediate test “result” object representing the result of this test’s doTest method
time
number
Required
Description The execution time of a test (and it’s sub-tests) in milliseconds
tests
Required
Description The test result objects for all sub-tests