Skip to content

Commit

Permalink
test: Add test to check generated files
Browse files Browse the repository at this point in the history
  • Loading branch information
risan committed Dec 7, 2018
1 parent 994517f commit d4f6364
Show file tree
Hide file tree
Showing 11 changed files with 3,109 additions and 71 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json
tanzil
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
__tests__
scripts
tanzil
.eslintignore
.eslintrc.js
.travis.yml
jest.config.js
yarn.lock
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dist: xenial
language: node_js
node_js:
- 11
cache: npm
notifications:
email:
on_success: never
on_failure: always
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Quran JSON

[![Build Status](https://badgen.net/travis/risan/quran-json)](https://travis-ci.org/risan/quran-json)
[![Greenkeeper](https://badges.greenkeeper.io/risan/quran-json.svg)](https://greenkeeper.io)
[![Latest Version](https://badgen.net/npm/v/quran-json)](https://www.npmjs.com/package/quran-json)

Quran text and translations in JSON format. Both Quran text and the translations are provided by [tanzil.net](http://tanzil.net).

## Quran JSON CDN
## CDN

Check the [json directory](https://github.com/risan/quran-json/tree/master/json) to see all available JSON files. The JSON files are also available through [UNPKG](https://unpkg.com/) CDN.

Expand Down Expand Up @@ -70,9 +74,6 @@ $ cd quran-json

# Install the dependencies
$ npm install

# Or if you use Yarn
$ yarn
```

### 3. Generate the JSON Files
Expand All @@ -81,9 +82,6 @@ Run the following command to generate the JSON files:

```bash
$ npm run build

# Or if you use Yarn
$ yarn build
```

## Related
Expand All @@ -92,7 +90,7 @@ $ yarn build

## License

CC-BY-SA 4.0 · [Risan Bagja Pradana](https://bagja.net)
[CC-BY-SA 4.0](https://github.com/risan/quran-json/blob/master/LICENSE.txt) · [Risan Bagja Pradana](https://bagja.net)

## Legal

Expand Down
59 changes: 59 additions & 0 deletions __tests__/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* global expect:false, test:false */
const fs = require("fs");
const path = require("path");
const range = require("lodash.range");
const util = require("util");

const access = util.promisify(fs.access);

const jsonPath = p => path.resolve(__dirname, `../json`, p);

const isJsonExists = async p => {
await access(jsonPath(p), fs.constants.F_OK);

return true;
};

const allJsonPairExists = async files => {
const pairs = [
...files,
...files.map(file => file.replace(/\.json$/i, ".pretty.json"))
];

const res = await Promise.all(pairs.map(file => isJsonExists(file)));

return !res.includes(false);
};

test("it generate surah json files", async () => {
const res = await allJsonPairExists(["surahs.json"]);
expect(res).toBe(true);
});

test("it generate quran json files", async () => {
const res = await allJsonPairExists([
"quran/en-id.json",
"quran/en.json",
"quran/id.json",
"quran/text.json"
]);

expect(res).toBe(true);
});

test("it generate surah json files", async () => {
const res = await allJsonPairExists(
range(1, 115).map(num => `surahs/${num}.json`)
);

expect(res).toBe(true);
});

test("it generate translations json files", async () => {
const res = await allJsonPairExists([
"translations/en.json",
"translations/id.json"
]);

expect(res).toBe(true);
});
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
testEnvironment: "node",
verbose: true
};
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "quran-json",
"version": "1.0.0",
"description": "Quran text and translations in JSON format",
"version": "1.0.1",
"description": "Quran text and translations in JSON format.",
"keywords": [
"tanzil",
"translations",
Expand All @@ -15,7 +15,7 @@
"author": {
"name": "Risan Bagja Pradana",
"email": "[email protected]",
"url": "https://risan.io"
"url": "https://bagja.net"
},
"main": "json/quran/en-id.pretty.json",
"repository": {
Expand All @@ -26,22 +26,23 @@
"build": "scripts/build.js",
"lint": "eslint ./",
"lint-fix": "eslint ./ --fix",
"prepublishOnly": "npm run lint && npm run build"
"prepublishOnly": "npm run lint && npm run test",
"test": "npm run build && jest"
},
"devDependencies": {
"eslint": "^5.9.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-config-prettier": "^3.3.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-prettier": "^3.0.0",
"prettier": "^1.15.2"
},
"engines": {
"node": ">=8.0.0"
},
"dependencies": {
"jest": "^23.6.0",
"lodash.groupby": "^4.6.0",
"lodash.range": "^3.2.0",
"prettier": "^1.15.2",
"rimraf": "^2.6.2",
"write-to-file": "^1.0.1"
},
"engines": {
"node": ">=8.0.0"
}
}
1 change: 1 addition & 0 deletions scripts/clean-json-dir.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint import/no-extraneous-dependencies: "off" */
const rimraf = require("rimraf");

const cleanJsonDir = () =>
Expand Down
1 change: 1 addition & 0 deletions scripts/group-by-surah.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint import/no-extraneous-dependencies: "off" */
const groupBy = require("lodash.groupby");
const writeJson = require("./write-json");

Expand Down
1 change: 1 addition & 0 deletions scripts/write-json.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint import/no-extraneous-dependencies: "off" */
const writeToFile = require("write-to-file");

const writeJson = (data, path) =>
Expand Down
Loading

0 comments on commit d4f6364

Please sign in to comment.