From 05f12210db7047c3c2f061aee3b7cc8d6fa5e812 Mon Sep 17 00:00:00 2001 From: Abdelrahman Ashraf Date: Mon, 14 Oct 2019 01:52:16 +0200 Subject: [PATCH 1/8] =?UTF-8?q?test:=20=F0=9F=92=8D=20add=20unit=20testing?= =?UTF-8?q?=20&&=20coverage=20check=20using=20CODEBEAT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes: #4 --- .gitignore | 1 + .travis.yml | 7 ++++--- memory.js | 2 ++ memory.test.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 21 ++++++++++++++++--- 5 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 memory.test.js 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..ad1f282 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,9 @@ cache: npm node_js: - "10" before_script: - - npm install eslint --global - - npm install standard --global + - npm install -g codeclimate-test-reporter script: - ./runcheckendline.sh - - standard \ No newline at end of file + - npm run validate + - npm run test:coverage + - codeclimate-test-reporter < coverage/lcov.info \ No newline at end of file diff --git a/memory.js b/memory.js index c72813b..87a792b 100644 --- a/memory.js +++ b/memory.js @@ -90,3 +90,5 @@ class Memory { } memoryJS.publicMemoryObj = new Memory(true) + +module.exports = memoryJS \ No newline at end of file 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..7fe609f 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", + "validate":"npm run standard && npm run test" }, "repository": { "type": "git", @@ -21,9 +24,21 @@ "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": { + "jest": "^24.9.0", + "standard": "^14.3.1" + }, + "standard": { + "env": [ + "jest" + ] + }, + "jest": { + "testEnvironment": "node" + } } From ad3090dece5f12261a1d21a8dc575275dd9e17cf Mon Sep 17 00:00:00 2001 From: Abdelrahman Ashraf Date: Mon, 14 Oct 2019 02:11:06 +0200 Subject: [PATCH 2/8] =?UTF-8?q?chore:=20=F0=9F=A4=96=20validate=20code=20o?= =?UTF-8?q?n=20git=20pre-commit=20hook?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- memory.js | 2 +- package.json | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/memory.js b/memory.js index 87a792b..b94ba71 100644 --- a/memory.js +++ b/memory.js @@ -91,4 +91,4 @@ class Memory { memoryJS.publicMemoryObj = new Memory(true) -module.exports = memoryJS \ No newline at end of file +module.exports = memoryJS diff --git a/package.json b/package.json index 7fe609f..31208dc 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,8 @@ "scripts": { "test": "jest", "test:coverage": "jest --coverage", - "standard": "standard", - "validate":"npm run standard && npm run test" + "standard": "standard --fix", + "validate": "npm run standard && npm run test" }, "repository": { "type": "git", @@ -30,7 +30,9 @@ }, "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": { @@ -40,5 +42,10 @@ }, "jest": { "testEnvironment": "node" + }, + "husky": { + "hooks": { + "pre-commit": "npm run validate" + } } } From e6ce2a408a832de0a963f5fefc45f9ec50c2160c Mon Sep 17 00:00:00 2001 From: Abdelrahman Ashraf Date: Mon, 14 Oct 2019 19:23:52 +0200 Subject: [PATCH 3/8] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20module.exports?= =?UTF-8?q?=20memoryJS=20only=20in=20node=20env?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- memory.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/memory.js b/memory.js index b94ba71..3b69adc 100644 --- a/memory.js +++ b/memory.js @@ -91,4 +91,4 @@ class Memory { memoryJS.publicMemoryObj = new Memory(true) -module.exports = memoryJS +if (typeof window === 'undefined') module.exports = memoryJS From 1b49bc249e8660a532be1bc7a387fe22144c3f90 Mon Sep 17 00:00:00 2001 From: Abdelrahman Ashraf Date: Mon, 14 Oct 2019 19:34:28 +0200 Subject: [PATCH 4/8] =?UTF-8?q?chore:=20=F0=9F=A4=96=20exclude=20node=5Fmo?= =?UTF-8?q?dules=20in=20runcheckendline.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- runcheckendline.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/runcheckendline.sh b/runcheckendline.sh index d999f5c..97d3eac 100755 --- a/runcheckendline.sh +++ b/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" From fd710bb11461d1734a93d72d76a42dfdd2f31e90 Mon Sep 17 00:00:00 2001 From: Abdelrahman Ashraf Date: Wed, 16 Oct 2019 06:24:15 +0200 Subject: [PATCH 5/8] =?UTF-8?q?ci:=20=F0=9F=8E=A1=20report=20coverage=20af?= =?UTF-8?q?ter=5Fsuccess=20on=20master=20and=20pull=20requests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 6 ++---- report-coverage.sh | 6 ++++++ 2 files changed, 8 insertions(+), 4 deletions(-) create mode 100755 report-coverage.sh diff --git a/.travis.yml b/.travis.yml index ad1f282..63cbbe0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,10 +3,8 @@ language: node_js cache: npm node_js: - "10" -before_script: - - npm install -g codeclimate-test-reporter script: - ./runcheckendline.sh - npm run validate - - npm run test:coverage - - codeclimate-test-reporter < coverage/lcov.info \ No newline at end of file +after_success: + - ./report-coverage.sh diff --git a/report-coverage.sh b/report-coverage.sh new file mode 100755 index 0000000..3eea41b --- /dev/null +++ b/report-coverage.sh @@ -0,0 +1,6 @@ +#!/bin/bash +if [ "$TRAVIS_BRANCH" == "master" ]; then + npm install -g codeclimate-test-reporter + npm run test:coverage + codeclimate-test-reporter < coverage/lcov.info # report coverage +fi From 1c9ea3a1b660e4df537e65196fc71897e0f452ef Mon Sep 17 00:00:00 2001 From: Abdelrahman Ashraf Date: Wed, 16 Oct 2019 06:38:35 +0200 Subject: [PATCH 6/8] =?UTF-8?q?chore:=20=F0=9F=A4=96=20move=20*.sh=20files?= =?UTF-8?q?=20under=20scripts=20folder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 4 ++-- report-coverage.sh => scripts/report-coverage.sh | 0 runcheckendline.sh => scripts/runcheckendline.sh | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename report-coverage.sh => scripts/report-coverage.sh (100%) rename runcheckendline.sh => scripts/runcheckendline.sh (100%) diff --git a/.travis.yml b/.travis.yml index 63cbbe0..72c5182 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ cache: npm node_js: - "10" script: - - ./runcheckendline.sh + - ./scripts/runcheckendline.sh - npm run validate after_success: - - ./report-coverage.sh + - ./scripts/report-coverage.sh diff --git a/report-coverage.sh b/scripts/report-coverage.sh similarity index 100% rename from report-coverage.sh rename to scripts/report-coverage.sh diff --git a/runcheckendline.sh b/scripts/runcheckendline.sh similarity index 100% rename from runcheckendline.sh rename to scripts/runcheckendline.sh From 97194b0ffc9f64f40c07f59bedc7b55471c9c89c Mon Sep 17 00:00:00 2001 From: Abdelrahman Ashraf Date: Wed, 16 Oct 2019 08:46:18 +0200 Subject: [PATCH 7/8] =?UTF-8?q?chore:=20=F0=9F=A4=96=20move=20coverage=20r?= =?UTF-8?q?eporting=20from=20codebeat=20to=20codecov?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- memory.js | 5 ++++- scripts/report-coverage.sh | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/memory.js b/memory.js index 3b69adc..2907080 100644 --- a/memory.js +++ b/memory.js @@ -91,4 +91,7 @@ class Memory { memoryJS.publicMemoryObj = new Memory(true) -if (typeof window === 'undefined') module.exports = memoryJS +if (typeof window === 'undefined') { + module.exports = memoryJS +} + diff --git a/scripts/report-coverage.sh b/scripts/report-coverage.sh index 3eea41b..09228ab 100755 --- a/scripts/report-coverage.sh +++ b/scripts/report-coverage.sh @@ -1,6 +1,6 @@ #!/bin/bash if [ "$TRAVIS_BRANCH" == "master" ]; then - npm install -g codeclimate-test-reporter + npm install -g codecov npm run test:coverage - codeclimate-test-reporter < coverage/lcov.info # report coverage + codecov fi From 93a5ef5b31e3668cd69fcf5d4c256426e750a4a9 Mon Sep 17 00:00:00 2001 From: Abdelrahman Ashraf Date: Wed, 16 Oct 2019 09:07:57 +0200 Subject: [PATCH 8/8] =?UTF-8?q?docs:=20=E2=9C=8F=EF=B8=8F=20add=20coverage?= =?UTF-8?q?=20badge=20to=20readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) 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