Exported functions to make testing a gulp plugin easy
The main function which all the others call in to
Creates a stream that writes the file argument and pipes through to the transform being tested. Upon end or error will ensure that null files are passed through and for buffer/stream files will ensure they transformed to the same type ( Buffer=>Buffer, Stream=>Stream). If these conditions are not met the promise rejects with GulpRuleError with the type property one of DidNotPassThroughNull,TransformedBufferToStreamOrNull,TransformedStreamToBufferOrNull. If the conditions are met the expectation callback is called. If the expectation throws the Promise is rejected with a PluginTestError.
declare ;
Examples for all functions at the end.
Transform to single file test helper
These tests will throw if there is not a single transformed file. The reason that there is a buffer and stream version is two fold. Firstly, you can pass a string and the appropriate file will be created and if you provide a file it checks that you did indeed provide the appropriate file. If you do not pass the appropriate file the function will reject.
These tests will call the expectation if there is an error, or if there is no error will provide the transformed file contents to the expectation.
Ignores / Filters
The ignoreFileTest function will resolve when the transform calls the callback without error and without changing the file. The filtersFileTest function will resolve when the transform calls the callback without error or file argument.
Transforms with files
This function resolves when resolves and there are transformed files
File contents type
This will pass the plugin a file of the unsupported type, it will resolve if the plugin errors with an Error object.
There is a stronger version of throwsErrorOnUnsupportedContentTypeTest. To resolve your plugin needs to throw a PluginError with a BufferNotSupported property with value equal to the streamNotSupported argument. The module 'th-gulpHelpers' exports the function cbErrorIfContentsTypeNotSupported that can be used for this functionality.
Example usage
Using jest.
describe"My Hello World Gulp Plugin",
File helpers