diff --git a/.gitignore b/.gitignore index 25c8fdb..a3fef53 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules +coverage package-lock.json \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index e98b981..72c5182 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,9 +3,8 @@ language: node_js cache: npm node_js: - "10" -before_script: - - npm install eslint --global - - npm install standard --global script: - - ./runcheckendline.sh - - standard \ No newline at end of file + - ./scripts/runcheckendline.sh + - npm run validate +after_success: + - ./scripts/report-coverage.sh diff --git a/README.md b/README.md index 559c88d..befa5b2 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,10 @@ memory.secret.min.js - 2.4kb (obfuscated) [![JavaScript Style Guide](https://cdn.rawgit.com/standard/standard/master/badge.svg)](https://github.com/standard/standard) -[![License](https://img.shields.io/github/license/unsuitable001/memoryJS.svg?style=popout)](https://raw.githubusercontent.com/unsuitable001/memoryJS/master/LICENSE) [![Build Status](https://travis-ci.org/unsuitable001/memoryJS.svg?branch=master)](https://travis-ci.org/unsuitable001/memoryJS) [![codebeat badge](https://codebeat.co/badges/9a04c2ff-0e70-4290-a340-67f37d41e162)](https://codebeat.co/projects/github-com-unsuitable001-memoryjs-master) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/392b5ccd3b854df8bc0988e359872afb)](https://www.codacy.com/app/unsuitable001/memoryJS?utm_source=github.com&utm_medium=referral&utm_content=unsuitable001/memoryJS&utm_campaign=Badge_Grade) +[![License](https://img.shields.io/github/license/unsuitable001/memoryJS.svg?style=popout)](https://raw.githubusercontent.com/unsuitable001/memoryJS/master/LICENSE) +[![Build Status](https://travis-ci.org/unsuitable001/memoryJS.svg?branch=master)](https://travis-ci.org/unsuitable001/memoryJS) +![Codecov](https://img.shields.io/codecov/c/github/unsuitable001/memoryJS) +[![codebeat badge](https://codebeat.co/badges/9a04c2ff-0e70-4290-a340-67f37d41e162)](https://codebeat.co/projects/github-com-unsuitable001-memoryjs-master) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/392b5ccd3b854df8bc0988e359872afb)](https://www.codacy.com/app/unsuitable001/memoryJS?utm_source=github.com&utm_medium=referral&utm_content=unsuitable001/memoryJS&utm_campaign=Badge_Grade) **Preliminary work is done. Testing in progress. Feature Requests, Bug Reports & Contributions are welcomed. Node Package Coming Soon** @@ -31,50 +34,51 @@ memory.secret.min.js - 2.4kb (obfuscated) ### Creating New Object in Memory ```javascript -var ptr = memoryJS.publicMemoryObj.newobj(55) // this method returns a pointer object +var ptr = memoryJS.publicMemoryObj.newobj(55); // this method returns a pointer object ``` ### Getting The Memory Address Of The Object ```javascript -console.log(ptr.value()) +console.log(ptr.value()); ``` ### Accessing The Stored Object from Memory ```javascript -console.log(ptr.pointedTo()) // output : 55 -console.log(ptr.point) // output : 55 -console.log(memoryJS.publicMemoryObj.valueOf(ptr.value())) // output : 55 +console.log(ptr.pointedTo()); // output : 55 +console.log(ptr.point); // output : 55 +console.log(memoryJS.publicMemoryObj.valueOf(ptr.value())); // output : 55 ``` ### Changing The Stored Object in Memory ```javascript -ptr.changeValue(96) +ptr.changeValue(96); // or -ptr.point = 96 +ptr.point = 96; // or -memoryJS.publicMemoryObj.changeValue(ptr.value(), 96) +memoryJS.publicMemoryObj.changeValue(ptr.value(), 96); ``` ### Deleting An Object From Memory ```javascript -ptr.free() // returns null object +ptr.free(); // returns null object // or -memoryJS.publicMemoryObj.free() // returns zero +memoryJS.publicMemoryObj.free(); // returns zero ``` ### Creating Custom Pointer Object ```javascript -var newptr = new Pointer('05f9') // where 05f9 is the memory address (i.e value of the pointer) +var newptr = new Pointer("05f9"); // where 05f9 is the memory address (i.e value of the pointer) ``` + ### Trying to access the whole memory object ```javascript -console.log(memoryJS.publicMemoryObj) // try yourself. it will not display any of the contents. Will only print the available methods. +console.log(memoryJS.publicMemoryObj); // try yourself. it will not display any of the contents. Will only print the available methods. ``` ## Donate diff --git a/memory.js b/memory.js index c72813b..2907080 100644 --- a/memory.js +++ b/memory.js @@ -90,3 +90,8 @@ class Memory { } memoryJS.publicMemoryObj = new Memory(true) + +if (typeof window === 'undefined') { + module.exports = memoryJS +} + diff --git a/memory.test.js b/memory.test.js new file mode 100644 index 0000000..01d1fa6 --- /dev/null +++ b/memory.test.js @@ -0,0 +1,56 @@ +const memoryJS = require('./memory') + +test('creates new object in memory', () => { + const values = [5, 2, 6, 9, 7, 80] + + values.forEach((value, index) => { + const ptr = memoryJS.publicMemoryObj.newobj(value) + + expect(ptr.value()).toBe((index + 1).toString()) + }) +}) + +test('accesses the stored object from memory', () => { + const values = [5, 2, 6, 9, 7, 80] + + values.forEach((value) => { + const ptr = memoryJS.publicMemoryObj.newobj(value) + + expect(ptr.pointedTo()).toBe(value) + expect(ptr.point).toBe(value) + expect(memoryJS.publicMemoryObj.valueOf(ptr.value())).toBe(value) + }) +}) + +test('changes the stored object in memory', () => { + const values = [5, 2, 6, 9, 7, 80] + const changeValues = values.reverse() + + values.forEach((value, index) => { + const ptr = memoryJS.publicMemoryObj.newobj(value) + ptr.changeValue(changeValues[index]) + + expect(ptr.point).toBe(changeValues[index]) + }) + + values.forEach((value, index) => { + const ptr = memoryJS.publicMemoryObj.newobj(value) + memoryJS.publicMemoryObj.changeValue(ptr.value(), changeValues[index]) + + expect(ptr.point).toBe(changeValues[index]) + }) +}) + +test('deletes an object from memory', () => { + const ptr = memoryJS.publicMemoryObj.newobj(55) + + expect(ptr.free()).toBe(null) +}) + +test('encapsulates object content', () => { + const ptr = memoryJS.publicMemoryObj.newobj(55) + + Object.keys(ptr).forEach((key) => { + expect(typeof ptr[key]).toBe('function') + }) +}) diff --git a/package.json b/package.json index c87d06f..31208dc 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,10 @@ "example": "examples" }, "scripts": { - "test": "standard memory.js" + "test": "jest", + "test:coverage": "jest --coverage", + "standard": "standard --fix", + "validate": "npm run standard && npm run test" }, "repository": { "type": "git", @@ -21,9 +24,28 @@ "memoryjs" ], "author": "unsuitable001", - "license": "ISC", + "license": "MIT", "bugs": { "url": "https://github.com/unsuitable001/memoryJS/issues" }, - "homepage": "https://github.com/unsuitable001/memoryJS#readme" + "homepage": "https://github.com/unsuitable001/memoryJS#readme", + "devDependencies": { + "husky": "^3.0.9", + "jest": "^24.9.0", + "lint-staged": "^9.4.2", + "standard": "^14.3.1" + }, + "standard": { + "env": [ + "jest" + ] + }, + "jest": { + "testEnvironment": "node" + }, + "husky": { + "hooks": { + "pre-commit": "npm run validate" + } + } } diff --git a/scripts/report-coverage.sh b/scripts/report-coverage.sh new file mode 100755 index 0000000..09228ab --- /dev/null +++ b/scripts/report-coverage.sh @@ -0,0 +1,6 @@ +#!/bin/bash +if [ "$TRAVIS_BRANCH" == "master" ]; then + npm install -g codecov + npm run test:coverage + codecov +fi diff --git a/runcheckendline.sh b/scripts/runcheckendline.sh similarity index 90% rename from runcheckendline.sh rename to scripts/runcheckendline.sh index d999f5c..97d3eac 100755 --- a/runcheckendline.sh +++ b/scripts/runcheckendline.sh @@ -3,6 +3,7 @@ flag=0 for i in $(find . -type f ! -path "*/*.egg-info/*"\ ! -path "./.*"\ ! -path "*.min.*"\ + ! -path "./node_modules/*"\ ! -path "*.svg" -exec grep -Iq . {} \; -and -print); do if [ "$(tail -c 1 $i)" != "" ]; then echo "$i needs newline at the end"