Skip to content

Commit

Permalink
Include a registration script for quicker usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Alhadis committed Sep 18, 2019
1 parent 27083ce commit 4e808a6
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,12 @@
* @example
* import Chinotto from "./lib/index.mjs";
* Chinotto.register();
* @return {Object}
*/
function register(){
for(const [names, fn] of methods) addMethod(names, fn);
for(const [names, fn] of properties) addProperty(names, fn);
return this;
}


Expand Down
1 change: 1 addition & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = karma => {
files: [
"node_modules/chai/chai.js",
"index.js",
"register.js",
"test/dom-spec.js",
],
preprocessors: {
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"repository": "https://github.com/Alhadis/Chinotto",
"license": "ISC",
"engines": {"node": ">=8.0.0"},
"files": ["index.js"],
"files": ["index.js", "register.js"],
"dependencies": {"chai": "*"},
"devDependencies": {
"eslint": "^6.3.0",
Expand All @@ -32,6 +32,9 @@
"all": true,
"clean": false,
"reporter": "text",
"include": ["index.js"]
"include": [
"index.js",
"register.js"
]
}
}
3 changes: 3 additions & 0 deletions register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use strict";
const main = ("object" === typeof global ? global : self);
main.Chinotto = (main.Chinotto || require("./index.js")).register();
2 changes: 1 addition & 1 deletion test/dom-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe("DOM-specific extensions", () => {
};
}

before(() => (isBrowser ? window.Chinotto : require("../index.js")).register());
before(() => isBrowser || require("../register.js"));

afterEach(() => [...document.body.childNodes].forEach(child => {
if(Node.ELEMENT_NODE !== child.nodeType || !child.matches("#mocha"))
Expand Down
2 changes: 1 addition & 1 deletion test/filesystem-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe("Filesystem-related extensions", () => {
const tmp = path.join(__dirname, "tmp");

before("Creating fixture directory", () => fs.existsSync(tmp) || fs.mkdirSync(tmp));
before("Loading extensions", () => require("../index.js").register());
before("Loading extensions", () => require("../register.js"));
after("Emptying fixture directory", () => {
for(const file of fs.readdirSync(tmp))
fs.unlinkSync(path.join(tmp, file));
Expand Down
2 changes: 2 additions & 0 deletions test/utils-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const {AssertionError} = Chai;


describe("Utility functions", () => {
before("Loading extensions", () => require("../register.js"));

describe("addMethod()", () => {
const {addMethod} = Chinotto;

Expand Down

0 comments on commit 4e808a6

Please sign in to comment.