Skip to content

Commit

Permalink
chore: Add index.js tests (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rapsssito authored Feb 19, 2020
1 parent 2e05e57 commit ecf2468
Show file tree
Hide file tree
Showing 14 changed files with 1,205 additions and 1,186 deletions.
7 changes: 5 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"plugins": [
"prettier"
"prettier",
"jest"
],
"env": {
"es6": true,
Expand All @@ -12,7 +13,9 @@
},
"extends": [
"eslint:recommended",
"prettier"
"prettier",
"plugin:jest/recommended",
"plugin:jest/style"
],
"rules": {
"prefer-const": ["error", {
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release
name: release

on:
push:
Expand All @@ -18,6 +18,10 @@ jobs:
node-version: 12
- name: Install dependencies
run: yarn ci
- name: ESLint
run: yarn lint
- name: Test
run: yarn test
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: tests

on:
pull_request:
branches:
- master

jobs:
build:
name: CI
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v1
- name: Install dependencies
run: yarn ci

- name: ESLint
run: yarn lint

- name: Test
run: yarn test
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ buck-out/

# Editor config
.vscode

# Tests
coverage
!coverage/coverage-final.json
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ codecov.yml
__tests__/
jest.config.js
jest.setup.js
coverage

# Example
examples/
Expand Down Expand Up @@ -95,3 +96,4 @@ bin/test.js
codorials
.vscode
.nyc_output
CODE_OF_CONDUCT
2 changes: 1 addition & 1 deletion .releaserc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}],
"@semantic-release/npm",
["@semantic-release/git", {
"assets": ["CHANGELOG.md", "package.json"],
"assets": ["CHANGELOG.md", "package.json", "coverage/coverage-final.json"],
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}]
]
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# react-native-tcp-socket
![](https://github.com/Rapsssito/react-native-tcp-socket/workflows/tests/badge.svg)


React Native TCP socket API for Android & iOS. It allows you to create TCP clients and servers sockets, simulating node's [net](https://nodejs.org/api/net.html) API.

## Table of Contents
Expand Down
1 change: 0 additions & 1 deletion __tests__/Sockets.js

This file was deleted.

22 changes: 22 additions & 0 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import TcpSockets from '../src/index';
import TcpServer from '../src/TcpServer';
import TcpSocket from '../src/TcpSocket';

test('create-client', () => {
const options = {
port: 1234,
host: '1.2.3.4',
localAddress: '127.0.0.1',
reuseAddress: true,
// localPort: 20000,
// interface: "wifi"
};

const socket = TcpSockets.createConnection(options, () => {});
expect(socket).toBeInstanceOf(TcpSocket);
});

test('create-server', () => {
const server = TcpSockets.createServer(() => {});
expect(server).toBeInstanceOf(TcpServer);
});
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
};
6 changes: 6 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
module.exports = {
preset: 'react-native',
collectCoverage: true,
testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/examples/'],
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
collectCoverageFrom: ['./src/**/*.{js, ts}'],
globals: {
__DEV__: true,
},
timers: 'fake',
};
21 changes: 21 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
jest.mock('react-native', () => {
// Mock NativeEventEmitter
class NativeEventEmitter {
constructor() {
this.addListener = jest.fn(() => ({ remove: () => {} }));
}
}

return {
NativeModules: {
TcpSockets: {
connect: jest.fn(),
end: jest.fn(),
destroy: jest.fn(),
write: jest.fn(),
listen: jest.fn(),
},
},
NativeEventEmitter: NativeEventEmitter,
};
});
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"description": "React Native TCP socket API for Android & iOS",
"main": "src/index.js",
"scripts": {
"test": "jest ./__tests__",
"ci": "yarn install --frozen-lockfile",
"test": "jest",
"lint": "eslint ."
},
"repository": {
Expand Down Expand Up @@ -36,14 +36,17 @@
},
"devDependencies": {
"@babel/core": "^7.7.7",
"babel-jest": "^24.9.0",
"@semantic-release/changelog": "^5.0.0",
"@semantic-release/git": "^9.0.0",
"@semantic-release/github": "^7.0.0",
"@semantic-release/npm": "^7.0.0",
"eslint": "^6.6.0",
"eslint-config-prettier": "^6.5.0",
"eslint-plugin-jest": "^23.6.0",
"eslint-plugin-prettier": "^3.1.1",
"jest": "^24.9.0",
"metro-react-native-babel-preset": "^0.58.0",
"prettier": "^1.18.2",
"react": "16.9.0",
"react-native": "^0.61.4",
Expand Down
Loading

0 comments on commit ecf2468

Please sign in to comment.