A module for testing an npm package in a near real environment.
The module provides the command package-test. Running command will:
- Copy the package files as they would be by npm to a testing directory
- install the dependencies of the package (using
npm install --production) - copy over any testing files
- run the test command in the testing directory
The testing files and the test command to run can be specified in a JSON file
named .package-test.json.
The module itself can also be used within another script to copy of the files to the test directory (steps 1 and 3 above).
var packageTest = require('package-test');
// Get a promise of setting up the test directory
packageTest().then(function() {
// Do some stuff after the files have been copied over
});Sets up a package test environment (a folder) by copying the package as it
would be exported by NPM, installing any dependencies (by running
npm install --production in the module folder) and then copying any
additional testing files.
Parameters
optionsobject package-test optionsoptions.testFolder[string] The path to the test folder to create. If not given, it will default to the name of the packageoptions.testFiles[string or Array<string> or Array<Object>] A glob string to match the test files to copy over to the test folder, an Array of globs string match test files to copy over or an Array of Objects with afilesparameter, specyfing the glob or array of globs to match the files to copy, adestinationparameter, specifying where to copy the files to, and abaseparameter, specifying a part of the path to remove from the test files when copyingoptions.testCommand[string or boolean] Test command that should be run instead of the one specified in the package.json fileoptions.noDeleteFolder[boolean] Whether or not to not delete the test folder (and fail) if it already exists. IftestFolderis not set, this must be set tofalseto delete the existing folder
Returns Promise A promise of setting up the package test folder that will
resolve to an Object containing the testFolder and the
packageFolder in node_modules of the test folder
Retrieve the package.json in the working folder
Parameters
ignoreMissingstring Whether to ignore a file does not exist error and instead resolve to undefined
Returns Promise A promise that will resolve to the Object contained in the package.json file
Retrieve the .package-test.json file in the working folder
Parameters
ignoreMissingstring Whether to ignore a file does not exist error and instead resolve to undefined
Returns Promise A promise that will resolve to the Object contained in the .package-test.json file