Skip to content

Commit

Permalink
Coverage badge
Browse files Browse the repository at this point in the history
  • Loading branch information
agsh committed May 16, 2024
1 parent 08f6535 commit d4a2cf9
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 8 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Test
on: [push, pull_request, workflow_dispatch]
jobs:
test:
runs-on: ubuntu-latest
steps:
# Your original steps
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- name: Install
run: npm install
- name: Test and Coverage
run: npm run coverage

# Add this
- name: Update Coverage Badge
# GitHub actions: default branch variable
# https://stackoverflow.com/questions/64781462/github-actions-default-branch-variable
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
uses: we-cli/coverage-badge-action@main
3 changes: 3 additions & 0 deletions __mocks__/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class Socket extends EventEmitter {
write() {
this.emit('data', Buffer.from('-ERR POP3 is available only with SSL or TLS connection enabled\r\n'));
}
destroy() {

}
}

module.exports = {
Expand Down
3 changes: 3 additions & 0 deletions __mocks__/tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ class Socket extends EventEmitter {
this.emit('end');
}, 10);
}
destroy() {

}
}

module.exports = {
Expand Down
43 changes: 42 additions & 1 deletion __tests__/yapople.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@ describe('integration tests for callback style', () => {
expect(err).toBe(null);
expect(data).toBeInstanceOf(Array);
expect(data.filter(a => a).length).toBe(3);
console.log(data);
data.forEach(msg => expect(/OK/.test(msg)).toBe(true));
client.rset((err) => {
expect(err).toBe(null);
Expand Down Expand Up @@ -479,4 +478,46 @@ describe('integration tests for callback style', () => {
});
});
});

describe('double connect', () => {
it('should not emit an error', (done) => {
const client = new Client(tlsOptions);
client.connect((err) => {
expect(err).toBe(null);
client.connect((err) => {
expect(err).toBe(null);
client.disconnect(done);
});
});
});
});

describe('socket error event', () => {
it('should return an error in the callback function', (done) => {
let notConnected = true;
const error = new Error('error');
const client = new Client(tlsOptions);
client.connect((err) => {
if (notConnected) {
notConnected = false;
expect(err).toBe(null);
client._socket.emit('error', error);
} else {
expect(err).toBe(error);
client.disconnect(done);
}
});
});
});

describe('socket error event', () => {
it('should rejects in promise', async () => {
const error = new Error('error');
const client = new Client(tlsOptions);
client.retrieve = jest.fn((_, cb) => cb(error));
await client.connect();
expect(client.retrieveAndDeleteAll()).rejects.toEqual(error);
client.quit();
});
});
});
6 changes: 4 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
module.exports = {
collectCoverageFrom: [
'lib/**/*.js'
'lib/yapople.js'
],
coverageDirectory: 'coverage',
testEnvironment: 'node',testMatch: [
coverageReporters: ['json', 'json-summary', 'text', 'lcov'],
testEnvironment: 'node',
testMatch: [
'**/__tests__/**/*.test.js'
],
};
4 changes: 2 additions & 2 deletions lib/yapople.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function onData(data) {
this._socket.once('end', function() {
this.connected = false;
if (this._command.callback) {
this._command.callback.call(this, null);
this._command.callback.call(this, null);
}
if (this._socket.destroy) {
this._socket.destroy(); // socket connection close
Expand Down Expand Up @@ -229,7 +229,7 @@ Client.prototype.connect = function(options, callback) {
}
this._socket.on('data', onData.bind(this));
this._socket.on('error', function(err) {
callback(err);
setTimeout(callback, 10, err);
this._queue = [];
}.bind(this));
};
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
"main": "lib/yapople.js",
"typings": "lib/yapople.d.ts",
"scripts": {
"test": "jest --coverage",
"test": "jest",
"coverage": "jest --coverage",
"coveralls": "jest --coverage && cat ./coverage/lcov.info | coveralls"
},
"repository": {
"type": "git",
"url": "https://github.com/agsh/yapople.git"
},
"dependencies": {
"mailparser": "^0.5.1"
"mailparser": "^0.6.2"
},
"keywords": [
"email",
Expand All @@ -28,7 +29,7 @@
"node": ">=5.10"
},
"devDependencies": {
"coveralls": "^3.1.0",
"coveralls": "^3.1.1",
"eslint": "^7.7.0",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-import": "^2.22.0",
Expand Down

0 comments on commit d4a2cf9

Please sign in to comment.