1

独自のローカル サブジェネレーター アプリを備えたジェネレーター ジェネレーター アプリがあります。メインの「アプリ」ジェネレーターを実行するときに、事前定義された引数を使用してサブジェネレーターを少なくとも 1 回呼び出すようにしたいという状況です。npm テストが失敗することを除いて、すべて正常に動作します。

メインの「アプリ」ジェネレーター: yo mygen.
サブジェネレーター: yo mygen:foo "lorem ipsum".

ここにtest.jsがあります

/*global describe, beforeEach, it*/
'use strict';

var path = require('path'),
yg = require('yeoman-generator');
var helpers = require('yeoman-generator').test;
var assert = require('yeoman-assert');

describe(' running `yo mygen`', function () {
  before(function (done) {
    var deps = [
      [helpers.createDummyGenerator(), 'mygen:foo', 'blah blah blah']
    ];

    helpers.run(path.join(__dirname, '../app'))
      .inDir(path.join(__dirname, './temp'))  // Clear the directory and set it as the CWD
      .withOptions({ mongoose: 'app', 'skip-install': true })            // Mock options passed in
      .withPrompts({
        'dbName': 'demo',
        'useUserAuth': false
      })
      .withGenerators(deps)
      .on('end', done);
    //done();
  });

  it('can be imported without blowing up', function () {
    var app = require('../app');
    assert(app !== undefined);
  });

  it('creates all required MVC files', function (done) {
    var expected = [
      // add files you expect to exist here.
      'package.json',
      'app.js',
      'bower.json',
      'routes/index.js',
      'public/css/style.css',
      'public/js/script.js',
      'views/index.html',
      'README.md',
      '.editorconfig',
      '.jshintrc'
    ];

    assert.file(expected);
    done();
  });
});

describe('í ¼ running `yo mygen:foo`', function () {
  before(function (done) {
    helpers.run(path.join(__dirname, '../schema'))
      .inDir(path.join(__dirname, './temp'))  // Clear the directory and set it as the CWD
      .withOptions({ mongoose: 'schema' })            // Mock options passed in
      .withArguments(['ha ha ha ha hha'])
      .on('end', done);
    //done();
  });

  describe('foo generator', function () {
    it('foo can be imported without blowing up', function () {
      var app = require('../foo');
      assert(app !== undefined);
    });

    it('created new MVC files for foo', function (done) {
      var expected = [
        // add files you expect to exist here.
        'view/t1.js',
        'models/t1.js',
        'controller/t1.js'
      ];
      assert.file(expected);
      done();
    })
  });
});

app/index.js では、サブジェネレーターを呼び出すために、以下を使用しました。

mygenGenerator.prototype.install = function install(){
  this.installDependencies();
  this.composeWith("mygen:foo", {args: ["humpty dumpty saton a wall"]});
};

stackoverflow およびその他のあらゆる場所で、考えられるすべての回答を検索しました。何をすべきかわかりません。

npm テストが失敗するテスト ケース:

  1. index.js から composeWith 行を削除すると、テストに合格します。
  2. composeWith 行を維持すると、テストは無限に進み、最終的に 2000 ミリ秒のクォータを超えて失敗します。
4

0 に答える 0