I must have some fundamental problem understanding of how proxyquire works or doing something wrong.
For a proof of concept I have this original code connecting to neo4j graphnedb in node.js:
// I am lib/neo4j.js
var neo4j = require('neo4j-driver').v1;
var graphenedbURL = process.env.GRAPHENEDB_BOLT_URL;
var graphenedbUser = process.env.GRAPHENEDB_BOLT_USER;
var graphenedbPass = process.env.GRAPHENEDB_BOLT_PASSWORD;
var driver = neo4j.driver(graphenedbURL, neo4j.auth.basic(graphenedbUser, graphenedbPass));
Then I have this test:
// I am test/neo4j.test.js
'use strict';
const test = require('tap').test;
const proxy = require('proxyquire');
const sinon = require('sinon');
test('Testing connection to Neo4j', (assert) => {
const driverStub = sinon.stub();
const testedModule = proxy('../lib/neo4j', {
'neo4j': {
'driver': driverStub,
},
});
});
Test is run as npm tap test/*.test.js --conv
Because npm does not provide access to .env for heroku graphnedb the driver won't have any process.env connection variables which should be ok since my expectation is that proxyquire will replace the driver with above defined stub but that's not happening and the test fails on neo4j.driver missing graphnedebURL. What am I doing wrong please?
Aucun commentaire:
Enregistrer un commentaire