Skip to content
This repository has been archived by the owner on Mar 28, 2021. It is now read-only.

A very simple set of helper functions for testing yeoman generators

License

Notifications You must be signed in to change notification settings

mablin7/yeoman-test-helpers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 promise
    • withOptions( obj ) Mock command line options for the generator
    • withArguments( obj ) Mock command line arguments for the generator
    • withPrompts( obj ) Mock prompt answers for the generator
    • withLocalConfig( obj ) Mock config for the generator
    • withGenerators( obj ) Mock subgenerators
    • run() 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 promise

  • file( filePath : String ) Returns contents of file (sync) in the generated directory

  • fileJSON( filePath : String ) Same as file but runs results trough JSON.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)

About

A very simple set of helper functions for testing yeoman generators

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published