Skip to content

Commit

Permalink
Merge branch 'ansumsingh-unittests'
Browse files Browse the repository at this point in the history
* ansumsingh-unittests:
  Add contribution graph section
  Update all dependencies except webpack things
  Update changelog
  Update the Readme with development instructions
  Update romanized tests to use expect style assertions
  Add test for layouts modules
  Extract keys out to helper files and use js style code for assertion
  Convert tests to use ESM style imports
  Rename and relocate tests similar to src folder structure
  Require tests directly from relative links
  Some formating
  Added new line at the end of the file
  update documentation for building and testing the package.
  Added undefined case as well
  Added test for validating expected output.
  added files for test
  Installed mocha test framework
  • Loading branch information
suvash committed Feb 27, 2021
2 parents 34d20e5 + d993416 commit 4883672
Show file tree
Hide file tree
Showing 9 changed files with 2,207 additions and 720 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"env": {
"browser": true,
"es6": true,
"node": true
"node": true,
"mocha": true
},
"extends": [
"standard",
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/).

## [Unreleased]
- Setup local testing
- Added tests for layouts and romanized module

## [0.4.2] - 2021-02-15
- Update all npm dependencies except webpack
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,24 @@ console.log(nepalify.format(text));
//किंकर्तव्यबिमुढ्
```
## Development
While the library is intended to run in the browser, you'll need to have `node` (and `npm`) installed locally for development.
Most of the npm targets are explained in the `package.json` file itself. The following flow is preferred for contribution.
- `npm install` for installing all the dependencies.
- `npm run test` for running the test suite.
- `npm run dev` to run a local server, serves an html page with the library injected for manual testing.
- `npm run format` to format all the changes before making a PR.
## Changelog
Please check the [CHANGELOG.md](https://github.com/suvash/nepalify/blob/main/CHANGELOG.md) for details.
## Contributors
Please check the [contribution graph](https://github.com/suvash/nepalify/graphs/contributors) graph for now.
## Legacy version
Expand Down
2,694 changes: 1,982 additions & 712 deletions package-lock.json

Large diffs are not rendered by default.

19 changes: 12 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
"build:cjsmin": "npm run webpack -- --env.mode production --env.target=commonjs2",
"build:cleanexample": "rimraf umd/index.html cjs/index.html",
"build": "npm-run-all -s clean build:*",
"format:pretty": "prettier --write src/",
"format:eslint": "eslint --fix src/**/*.js",
"format:pretty": "prettier --write src/ test/",
"format:eslint": "eslint --fix src/**/*.js test/**/*.js",
"format": "npm-run-all --sequential format:*",
"release": "npm-run-all --sequential build np",
"test": "echo \"Error: no test specified\""
"mocha": "mocha --recursive --require esm",
"test": "npm run mocha",
"test:watch": "npm run mocha -- --watch"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -54,19 +56,22 @@
},
"homepage": "https://github.com/suvash/nepalify#readme",
"devDependencies": {
"@babel/core": "^7.12.16",
"@babel/preset-env": "^7.12.16",
"@babel/core": "^7.13.8",
"@babel/preset-env": "^7.13.8",
"babel-loader": "^8.2.2",
"browserslist": "^4.16.3",
"core-js": "^3.8.3",
"chai": "^4.3.0",
"core-js": "^3.9.0",
"eslint": "^7.20.0",
"eslint-config-prettier": "^7.2.0",
"eslint-config-prettier": "^8.1.0",
"eslint-config-standard": "^16.0.2",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.3.1",
"eslint-plugin-standard": "^5.0.0",
"esm": "^3.2.25",
"html-webpack-plugin": "^4.3.0",
"mocha": "^8.3.0",
"np": "^7.4.0",
"npm-check": "^5.9.2",
"npm-run-all": "^4.1.5",
Expand Down
81 changes: 81 additions & 0 deletions test/helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
export const testKeys = [
"+",
".",
"/",
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"<",
"=",
">",
"?",
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
"P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
"X",
"Y",
"Z",
"[",
"\\",
"]",
"^",
"_",
"`",
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
"p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
"x",
"y",
"z",
"{",
"|",
"}",
"~",
];
9 changes: 9 additions & 0 deletions test/layouts.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { expect } from "chai";
import layouts from "../src/layouts";

describe("layouts", () => {
it("should return an object of available layouts", () => {
expect(layouts).to.be.an('object');
expect(layouts).to.have.property('romanized');
});
});
81 changes: 81 additions & 0 deletions test/layouts/romanized.helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
export const expectedKeys = [
"\u200C",
"।",
"्",
"०",
"१",
"२",
"३",
"४",
"५",
"६",
"७",
"८",
"९",
"ङ",
"\u200D",
"॥",
"?",
"आ",
"भ",
"च",
"ध",
"ै",
"ऊ",
"घ",
"अ",
"ी",
"झ",
"ख",
"ळ",
"ं",
"ण",
"ओ",
"फ",
"ठ",
"ृ",
"श",
"थ",
"ू",
"ँ",
"औ",
"ढ",
"ञ",
"ऋ",
"इ",
"ॐ",
"ए",
"^",
"॒",
"ऽ",
"ा",
"ब",
"छ",
"द",
"े",
"उ",
"ग",
"ह",
"ि",
"ज",
"क",
"ल",
"म",
"न",
"ो",
"प",
"ट",
"र",
"स",
"त",
"ु",
"व",
"ौ",
"ड",
"य",
"ष",
"ई",
"ः",
"ऐ",
"़",
];
24 changes: 24 additions & 0 deletions test/layouts/romanized.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { expect } from "chai";
import romanized from "../../src/layouts/romanized";
import { testKeys } from "../helper.js";
import { expectedKeys } from "./romanized.helper.js";

describe("romanized", () => {
describe("formatKey()", () => {
it("should return corresponding romanized Nepali character.", () => {
const receivedKeys = testKeys.map((key) => romanized.formatKey(key));
expect(receivedKeys).to.deep.equal(expectedKeys);
});

it("should return undefined if no mapping exists", () => {
const asciiCodes = [...Array(255 + 1).keys()];
const asciiKeys = asciiCodes.map((key) => String.fromCharCode(key));
const filteredKeys = asciiKeys.filter((key) => testKeys.indexOf(key) < 0);

const receivedKeys = filteredKeys.map((key) => romanized.formatKey(key));
const expectedKeys = [...Array(receivedKeys.length)];

expect(receivedKeys).to.deep.equal(expectedKeys);
});
});
});

0 comments on commit 4883672

Please # to comment.