1.0.0 • Published 7 years ago
yeoman-test-helpers v1.0.0
yeoman-test-helpers
A thin wrapper on top of yeoman-test, deigned to work with jest.
Docs
initGenerator( generatorPath : String )Initializes the generator for testing Returns an object with the following props:setupDir( callback : ( dir : String, cb : () ) )Used for setting up files in the directory the generator will be working on. For async operations call cb when done, or return promisewithOptions( obj )Mock command line options for the generatorwithArguments( obj )Mock command line arguments for the generatorwithPrompts( obj )Mock prompt answers for the generatorwithLocalConfig( obj )Mock config for the generatorwithGenerators( obj )Mock subgeneratorsrun()Starts the generator. Returns a promise that resolves when the generator is done
cleanupGenerator()Cleans up after testing. Should be called when you are donw testing the generator Returns a promisefile( filePath : String )Returns contents of file (sync) in the generated directoryfileJSON( filePath : String )Same asfilebut runs results troughJSON.parse
Example
const path = require('path')
const {
initGenerator,
cleanupGenerator,
file,
fileJSON
} = require('yeoman-test-helpers')
describe('generator-example:app', () => {
beforeAll(() => {
return initGenerator(path.join(__dirname, '../generators/app')).run()
})
afterAll(() => {
return cleanupGenerator()
})
it('produces package.json', () => {
expect(file('package.json')).toBeTruthy()
})
it('produces correct package.json', () => {
expect(fileJSON('package.json')).toMatchSnapshot()
})
})Any issues are likely related to yeoman-test, since this is a really simple wrapper. Also refer to that repo for further questions about inner working of the resting functions.
License
Released under MIT(c)
1.0.0
7 years ago