6

何らかの理由proxquireでモジュールが見つかりませんindex.js。私は本当にばかげた、または明白なことをしているに違いなく、それを見ることができません。

エラー:

  invoicer
    good request
      1) "before all" hook


  0 passing (9ms)
  1 failing

  1) invoicer good request "before all" hook:
     Error: Cannot find module '../index.js'
      at Function.Module._resolveFilename (module.js:338:15)
      at Proxyquire._disableModuleCache (/Users/mario/projects/_invoice/print-invoice/node_modules/proxyquire/lib/proxyquire.js:218:19)
      at Proxyquire._disableCache (/Users/mario/projects/_invoice/print-invoice/node_modules/proxyquire/lib/proxyquire.js:203:15)
      at Proxyquire._withoutCache (/Users/mario/projects/_invoice/print-invoice/node_modules/proxyquire/lib/proxyquire.js:173:27)
      at Proxyquire.load (/Users/mario/projects/_invoice/print-invoice/node_modules/proxyquire/lib/proxyquire.js:135:15)
      at getTestedModule (/Users/mario/projects/_invoice/print-invoice/test/test.js:89:12)
      at Context.<anonymous> (/Users/mario/projects/_invoice/print-invoice/test/test.js:69:28)
      at Hook.Runnable.run (/usr/local/lib/node_modules/mocha/lib/runnable.js:218:15)
      at next (/usr/local/lib/node_modules/mocha/lib/runner.js:259:10)
      at Object._onImmediate (/usr/local/lib/node_modules/mocha/lib/runner.js:276:5)
      at processImmediate [as _immediateCallback] (timers.js:345:15)

奇妙なことに、別のアプリのテスト用に同じセットアップがあり、そこでモジュールを見つけるのに問題はありません。の同じバージョンを維持してproxyquireいましたが、最新バージョンに変更しても修正されませんでした。index.js指定したパスのディレクトリに存在します。

これは私のテストコードです:

var chai = require('chai');
var sinonChai = require("sinon-chai");
var sinon = require('sinon');
chai.use(sinonChai);
var nock = require('nock');
var mockfs = require('mock-fs');

var proxyquire = require('proxyquire');

describe('invoicer', function () {

    var expect = chai.expect;

    var ResponseOptions = {
        "username": "Peter Pan",
        "user_address_line_1": "Never Never Land",
        "user_address_line_2": "Tree-house 99",
        "user_post_code": "E4 9BY",
        "delivery_address_line_1": "Hooks Boat",
        "delivery_address_line_2": "Dock 69",
        "delivery_post_code": "SE2 4C",
        "order_number": "234234234",
        "order_date": "20/12/2090",
        "dispatch_date": "20/12/2090",
        "items": [
            {
                "product_name": "Fairy Dust",
                "brand": "Airy fairy",
                "quantity": 5,
                "total": 2000
            }
        ],
        "grand_total": 2000,
        "user_email": "peter@flyaway.com"
    }

    beforeEach(function () {

        var api = nock("http://wherever.com")
            .get("/to/fake/order/55432")
            .reply(200, ResponseOptions);

    });

    describe("good request", function () {

        var createTransport, sendMail, url, testedModule, contextDoneSpy, request;

        before(function (done) {

            createTransport = sinon.spy();
            sendMail = sinon.spy();
            url = "http://wherever.com/to/fake/order/55432";
            constextDoneSpy = sinon.spy();
            mockfs({
                "../email.html": "<span><%= username %></span>"
            });
            request = sinon.spy();

            testedModule = getTestedModule(createTransport, sendMail, request);
            testedModule.Invoicer(url, { done: function () {
                contextDoneSpy.apply(null, arguments);
                done();
            }});
        });

        afterEach(function () {
            mockfs.restore();
        });

        it("context done was called", function () {

            expect(contextDoneSpy).to.have.been.called;
        });
    });

});

function getTestedModule (createTransport, sendMail, request) {
    return proxyquire('../index.js', {
        "nodemailer": function () {
            return {
                createTransport: createTransport,
                sendMail: sendMail
            }
        },
        'request': request
    });
}
4

0 に答える 0