mercredi 28 décembre 2016

testing yeoman generator file creation with mocha AssertionError

have a problem testing yeoman generator.

This is my app,js file for testing. When i just pass 'package.json' in assert.file() it works and pass the test

var path = require('path');
var assert = require('yeoman-assert');
var helpers = require('yeoman-test');

describe('generator:app', function(){
  before(function(){
    helpers.run(path.join(__dirname, '../generators/app/src'))
      .toPromise();
  });

  it('creates files', function(){
    assert.file([
      'package.json'
    ])
  })
})

The coverage is:

------------|----------|----------|----------|----------|----------------|
File        |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
------------|----------|----------|----------|----------|----------------|
 app\       |        0 |      100 |        0 |        0 |                |
  index.js  |        0 |      100 |        0 |        0 |... 18,22,26,30 |
------------|----------|----------|----------|----------|----------------|
All files   |        0 |      100 |        0 |        0 |                |
------------|----------|----------|----------|----------|----------------|

But the problem comes when i pass a second file. When i pass 'index.html' or another path (whatever path) it brokes.

  AssertionError: index.html, no such file or directory
  + expected - actual

  -false
  +true

  at node_modules\yeoman-assert\index.js:46:12
  at Array.forEach (native)
  at Function.assert.file (node_modules\yeoman-assert\index.js:44:8)
  at Context.<anonymous> (test\app.js:13:12)

And here is something that i don't understant. What is the right file path that i have to pass to assert.file([]).

My writing method for my app generator looks like:

writing(){
  this.fs.copyTpl(
      this.templatePath('_package.json'),
      this.destinationPath('package.json'), {
        appName: this.appName,
        appDescription: this.appDescription,
        authorName: this.authorName
      }
    );

    this.fs.copy(
      this.templatePath('config/'),
      this.destinationRoot()
    );

    this.fs.copy(
      this.templatePath('src/'),
      this.destinationPath('src/')
    );

    that.fs.copyTpl(
      that.templatePath('_index.html'),
      that.destinationPath('src/index.html'),
      {
        appName: _.startCase(that.appName),
      }
    );

    this.fs.copy(
      this.templatePath('app/'),
      this.destinationPath('src/app')
    );
}

I wish somebody can help me. Thank you in advance!

Aucun commentaire:

Enregistrer un commentaire