Skip to content

Commit 7ffccbb

Browse files
committed
Coverage badge
1 parent 08f6535 commit 7ffccbb

File tree

9 files changed

+78
-16
lines changed

9 files changed

+78
-16
lines changed

.github/workflows/test.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Test
2+
on: [push, pull_request, workflow_dispatch]
3+
jobs:
4+
test:
5+
runs-on: ubuntu-latest
6+
steps:
7+
# Your original steps
8+
- uses: actions/checkout@v4
9+
- uses: actions/setup-node@v4
10+
- name: Install
11+
run: npm install
12+
- name: Test and Coverage
13+
run: npm run coverage
14+
15+
# Add this
16+
- name: Update Coverage Badge
17+
# GitHub actions: default branch variable
18+
# https://stackoverflow.com/questions/64781462/github-actions-default-branch-variable
19+
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
20+
uses: we-cli/coverage-badge-action@main

.travis.yml

Lines changed: 0 additions & 7 deletions
This file was deleted.

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# yapople
22
Yet another POP3 library
33

4-
[![Build Status](https://travis-ci.org/agsh/yapople.png)](https://travis-ci.org/agsh/yapople)
54
[![Coverage Status](https://coveralls.io/repos/agsh/yapople/badge.svg?branch=master)](https://coveralls.io/r/agsh/yapople?branch=master)
65

76
The design propose of the library is simplicity. A lot of common tasks with you POP3 mailbox doesn't require knowledge of

__mocks__/net.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ class Socket extends EventEmitter {
1010
write() {
1111
this.emit('data', Buffer.from('-ERR POP3 is available only with SSL or TLS connection enabled\r\n'));
1212
}
13+
destroy() {
14+
15+
}
1316
}
1417

1518
module.exports = {

__mocks__/tls.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ class Socket extends EventEmitter {
103103
this.emit('end');
104104
}, 10);
105105
}
106+
destroy() {
107+
108+
}
106109
}
107110

108111
module.exports = {

__tests__/yapople.test.js

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,6 @@ describe('integration tests for callback style', () => {
354354
expect(err).toBe(null);
355355
expect(data).toBeInstanceOf(Array);
356356
expect(data.filter(a => a).length).toBe(3);
357-
console.log(data);
358357
data.forEach(msg => expect(/OK/.test(msg)).toBe(true));
359358
client.rset((err) => {
360359
expect(err).toBe(null);
@@ -479,4 +478,46 @@ describe('integration tests for callback style', () => {
479478
});
480479
});
481480
});
481+
482+
describe('double connect', () => {
483+
it('should not emit an error', (done) => {
484+
const client = new Client(tlsOptions);
485+
client.connect((err) => {
486+
expect(err).toBe(null);
487+
client.connect((err) => {
488+
expect(err).toBe(null);
489+
client.disconnect(done);
490+
});
491+
});
492+
});
493+
});
494+
495+
describe('socket error event', () => {
496+
it('should return an error in the callback function', (done) => {
497+
let notConnected = true;
498+
const error = new Error('error');
499+
const client = new Client(tlsOptions);
500+
client.connect((err) => {
501+
if (notConnected) {
502+
notConnected = false;
503+
expect(err).toBe(null);
504+
client._socket.emit('error', error);
505+
} else {
506+
expect(err).toBe(error);
507+
client.disconnect(done);
508+
}
509+
});
510+
});
511+
});
512+
513+
describe('socket error event', () => {
514+
it('should rejects in promise', async () => {
515+
const error = new Error('error');
516+
const client = new Client(tlsOptions);
517+
client.retrieve = jest.fn((_, cb) => cb(error));
518+
await client.connect();
519+
expect(client.retrieveAndDeleteAll()).rejects.toEqual(error);
520+
client.quit();
521+
});
522+
});
482523
});

jest.config.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
module.exports = {
22
collectCoverageFrom: [
3-
'lib/**/*.js'
3+
'lib/yapople.js'
44
],
55
coverageDirectory: 'coverage',
6-
testEnvironment: 'node',testMatch: [
6+
coverageReporters: ['json', 'json-summary', 'text', 'lcov'],
7+
testEnvironment: 'node',
8+
testMatch: [
79
'**/__tests__/**/*.test.js'
810
],
911
};

lib/yapople.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function onData(data) {
132132
this._socket.once('end', function() {
133133
this.connected = false;
134134
if (this._command.callback) {
135-
this._command.callback.call(this, null);
135+
this._command.callback.call(this, null);
136136
}
137137
if (this._socket.destroy) {
138138
this._socket.destroy(); // socket connection close
@@ -229,7 +229,7 @@ Client.prototype.connect = function(options, callback) {
229229
}
230230
this._socket.on('data', onData.bind(this));
231231
this._socket.on('error', function(err) {
232-
callback(err);
232+
setTimeout(callback, 10, err);
233233
this._queue = [];
234234
}.bind(this));
235235
};

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66
"main": "lib/yapople.js",
77
"typings": "lib/yapople.d.ts",
88
"scripts": {
9-
"test": "jest --coverage",
9+
"test": "jest",
10+
"coverage": "jest --coverage",
1011
"coveralls": "jest --coverage && cat ./coverage/lcov.info | coveralls"
1112
},
1213
"repository": {
1314
"type": "git",
1415
"url": "https://github.com/agsh/yapople.git"
1516
},
1617
"dependencies": {
17-
"mailparser": "^0.5.1"
18+
"mailparser": "^0.6.2"
1819
},
1920
"keywords": [
2021
"email",
@@ -28,7 +29,7 @@
2829
"node": ">=5.10"
2930
},
3031
"devDependencies": {
31-
"coveralls": "^3.1.0",
32+
"coveralls": "^3.1.1",
3233
"eslint": "^7.7.0",
3334
"eslint-config-standard": "^14.1.1",
3435
"eslint-plugin-import": "^2.22.0",

0 commit comments

Comments
 (0)