Closed danieltigse closed 6 months ago
You need to provide some more context. You can peer into the test/transaction.js and see how it's called. You can look at the Haraka plugins and see how they are also calling those functions and not getting the error you are.
Ok I have a folder tests
and inside of it I have a file with the following:
const fixtures = require('haraka-test-fixtures');
beforeAll(() => {
this.plugin = new fixtures.plugin('queue/criptext_queue');
});
beforeEach(() => {
this.connection = {
transaction: {
message_stream: {}
}
}
});
describe('hook_queue', () => {
it('returns DENY when email size is exceeded', () => {
this.connection.transaction.message_stream.bytes_read = 1024 * 1024 * 50;
this.plugin.hook_queue((action, error) => {
expect(action).toBe(DENY);
expect(error.message).toBe('email size exceeded');
}, this.connection);
});
it('returns OK for a normal email', () => {
this.connection.transaction = fixtures.transaction.createTransaction();
this.plugin.hook_queue((action, error) => {
expect(action).toBe(OK);
}, this.connection);
});
});
As you can see I am calling createTransaction but when I do that, the error TypeError: cfreader._enoent_timer.unref is not a function
appears.
You are using arrow functions which mocha doesn't support. Use traditional function () { ... }
calls.
Your beforeEach
is also not so useful. If should be more like this:
beforeEach(() => {
this.connection = fixtures.connection.createConnection()
this.connection.transaction = fixtures.transaction.createTransaction()
});
Same error, I am not using arrow functions now.
const fixtures = require('haraka-test-fixtures');
beforeAll(function() {
this.plugin = new fixtures.plugin('queue/criptext_queue');
});
beforeEach(function(){
this.connection = fixtures.connection.createConnection()
this.connection.transaction = fixtures.transaction.createTransaction()
});
describe('hook_queue', function() {
it('returns DENY when email size is exceeded', function() {
this.connection.transaction.message_stream.bytes_read = 1024 * 1024 * 50;
this.plugin.hook_queue(function(action, error) {
expect(action).toBe(DENY);
expect(error.message).toBe('email size exceeded');
}, this.connection);
});
it('returns OK for a normal email', function() {
this.plugin.hook_queue(function(action, error){
expect(action).toBe(OK);
}, this.connection);
});
});
I am using jest by the way, no mocha.
the error TypeError: cfreader._enoent_timer.unref is not a function appears
Now at least you're setting up a connection and transaction properly. Your call is hitting this line right here and throwing the error. You'll have to follow the trace and see exactly why.
the error TypeError: cfreader._enoent_timer.unref is not a function appears
Now at least you're setting up a connection and transaction properly. Your call is hitting this line right here and throwing the error. You'll have to follow the trace and see exactly why.
That's right. Thanks for your help but I already knew that, that's why I created the issue :(
This is the stack trace:
at Object.<anonymous>.cfreader.ensure_enoent_timer (node_modules/haraka-config/configfile.js:315:28)
at Object.<anonymous>.cfreader.watch_file (node_modules/haraka-config/configfile.js:160:22)
at Object.<anonymous>.cfreader.read_config (node_modules/haraka-config/configfile.js:220:22)
at Config.get (node_modules/haraka-config/config.js:27:32)
at new ResultStore (node_modules/haraka-results/index.js:18:18)
at new Transaction (node_modules/haraka-test-fixtures/lib/transaction.js:64:24)
at Object.<anonymous>.exports.createTransaction (node_modules/haraka-test-fixtures/lib/transaction.js:214:15)
at Object.it (tests/criptext_queue.test.js:33:60)
Just looked at this again. The error is part of ensure_enoent_timer
, which is in haraka-config and uses node.js support for receiving file update notifications. That unref()
tells node.js that is can nuke the timer if it's the only thing blocking the process from exiting. It appears the timer isn't instantiating in your case. What OS and node.js versions are you using? Does it still do that with mocha instead of jest?
I can think of one possible workaround:
- this._enoent_timer.unref(); // This shouldn't block exit
+ if (this._enoent_timer) this._enoent_timer.unref(); // don't block process exit
Closing as stale. Can be reopened if enough information to reproduce is provided.
at invoking the following functions:
new fixtures.connection.createConnection();
new fixtures.transaction.createTransaction();