Skip to content

Commit

Permalink
added test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
0xadada committed Oct 6, 2019
1 parent c238762 commit f9fdca5
Show file tree
Hide file tree
Showing 8 changed files with 3,304 additions and 2 deletions.
28 changes: 28 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: 2
jobs:
build:
docker: # CircleCI tags: https://circleci.com/docs/2.0/docker-image-tags.json
- image: circleci/node:10-browsers # Node tags: https://nodejs.org/en/download/releases/
steps:
- checkout

# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-

- run: yarn

- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "yarn.lock" }}

- run:
name: Lint
command: yarn lint
- run:
name: Test
command: yarn test
26 changes: 26 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 2015,
sourceType: 'module'
},
plugins: ['prettier'],
extends: ['eslint:recommended', 'plugin:prettier/recommended'],
env: {
browser: true,
node: true
},
overrides: [
{
parserOptions: {
sourceType: 'module',
ecmaVersion: 2017
},
env: {
browser: false,
node: true
},
files: ['test*.js', 'tests/**/*.js']
}
]
};
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
/node_modules

# misc
/.env
/.tool-versions
/coverage/*
/libpeerconnection.log
npm-debug.log*
package-lock.json
yarn-error.log

3 changes: 3 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
14 changes: 13 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,17 @@
"repository": "git@github.com:0xadada/random-emoji.git",
"author": "0xADADA <0xadada.pub@0xadada.pub>",
"license": "MIT",
"private": false
"private": false,
"scripts": {
"test": "ava",
"lint": "yarn eslint .",
"lint:fix": "yarn eslint . --fix"
},
"devDependencies": {
"ava": "^2.4.0",
"eslint": "^6.5.1",
"eslint-config-prettier": "^6.3.0",
"eslint-plugin-prettier": "^3.1.1",
"prettier": "^1.18.2"
}
}
2 changes: 1 addition & 1 deletion random-emoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const CHAR_RANGE = {
expressions: [0x1f910, 0x1f92f]
};

function random(range = "emoticons") {
function random(range = 'emoticons') {
let [max, min] = CHAR_RANGE[range];
let codePoint = Math.floor(Math.random() * (max - min) + min);
return String.fromCodePoint(codePoint);
Expand Down
37 changes: 37 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import test from 'ava';
import random from './random-emoji';

test('without arguments it shows an emoticon', t => {
const a = random();
const cp = a.codePointAt();
t.assert(cp >= 0x1f600, 'greater than min');
t.assert(cp <= 0x1f64f, 'less than max');
});

test('with argument "emoticons" it shows an emoticon', t => {
const a = random('emoticons');
const cp = a.codePointAt();
t.assert(cp >= 0x1f600, 'greater than min');
t.assert(cp <= 0x1f64f, 'less than max');
});

test('with argument "food" it shows a food emoji', t => {
const a = random('food');
const cp = a.codePointAt();
t.assert(cp >= 0x1f32d, 'greater than min');
t.assert(cp <= 0x1f37f, 'less than max');
});

test('with argument "animals" it shows an animal friend emoji', t => {
const a = random('animals');
const cp = a.codePointAt();
t.assert(cp >= 0x1f400, 'greater than min');
t.assert(cp <= 0x1f4d3, 'less than max');
});

test('with argument "expressions" it shows an facial expression emoji', t => {
const a = random('expressions');
const cp = a.codePointAt();
t.assert(cp >= 0x1f910, 'greater than min');
t.assert(cp <= 0x1f92f, 'less than max');
});
Loading

0 comments on commit f9fdca5

Please sign in to comment.