From 8efa58ff8d2307719dcc668915db47adcbea520e Mon Sep 17 00:00:00 2001 From: Predrag Josifovic Date: Mon, 27 Nov 2017 15:21:16 -0800 Subject: [PATCH 1/8] Configuring file/folder structure of repo --- .eslintignore | 5 ++ .eslintrc | 26 +++++++++ .gitignore | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 179 insertions(+) create mode 100644 .eslintignore create mode 100644 .eslintrc create mode 100644 .gitignore diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..05b1cf3 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,5 @@ +**/node_modules/* +**/vendor/* +**/*.min.js +**/coverage/* +**/build/* diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..840d336 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,26 @@ +{ + "env": { + "browser": true, + "node": true, + "commonjs": true, + "jest": true, + "es6": true + }, + "globals": { + "err": true, + "req": true, + "res": true, + "next": true + }, + "extends": "eslint:recommended", + "parserOptions": { + "sourceType": "module" + }, + "rules": { + "no-console": "off", + "indent": [ "error", 2 ], + "quotes": ["error", "single", { "allowTemplateLiterals": true }], + "comma-dangle": ["error", "always-multiline"], + "semi": [ "error", "always" ] + } +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8fe2634 --- /dev/null +++ b/.gitignore @@ -0,0 +1,148 @@ +# Created by https://www.gitignore.io/api/osx,vim,node,linux,windows,visualstudiocode + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Typescript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + + +### OSX ### +*.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Vim ### +# swap +[._]*.s[a-v][a-z] +[._]*.sw[a-p] +[._]s[a-v][a-z] +[._]sw[a-p] +# session +Session.vim +# temporary +.netrwhist +# auto-generated tag files +tags + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +.history + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.gitignore.io/api/osx,vim,node,linux,windows,visualstudiocode From f6e0aa76818b7261edca3688333968af77974215 Mon Sep 17 00:00:00 2001 From: Predrag Josifovic Date: Mon, 27 Nov 2017 16:53:55 -0800 Subject: [PATCH 2/8] adding greet.test.js as well as lib/ JS files, creating package.json file --- .eslintrc.json | 26 ++++++++++++++++++++++++++ __test__/greet.test.js | 17 +++++++++++++++++ lib/arithmetic.js | 1 + lib/greet.js | 1 + package.json | 19 +++++++++++++++++++ 5 files changed, 64 insertions(+) create mode 100644 .eslintrc.json create mode 100644 __test__/greet.test.js create mode 100644 lib/arithmetic.js create mode 100644 lib/greet.js create mode 100644 package.json diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..840d336 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,26 @@ +{ + "env": { + "browser": true, + "node": true, + "commonjs": true, + "jest": true, + "es6": true + }, + "globals": { + "err": true, + "req": true, + "res": true, + "next": true + }, + "extends": "eslint:recommended", + "parserOptions": { + "sourceType": "module" + }, + "rules": { + "no-console": "off", + "indent": [ "error", 2 ], + "quotes": ["error", "single", { "allowTemplateLiterals": true }], + "comma-dangle": ["error", "always-multiline"], + "semi": [ "error", "always" ] + } +} diff --git a/__test__/greet.test.js b/__test__/greet.test.js new file mode 100644 index 0000000..7ff5dc1 --- /dev/null +++ b/__test__/greet.test.js @@ -0,0 +1,17 @@ +'use strict'; + +describe('Showcasing basic TDD with JEST', () => { + test('Different ways to use the expect function',() => { + let aNumber = 5; + expect(aNumber).toEqual(5); + + let aNullvalue = null; + expect(aNullvalue).toBeNull(); + + let fifty = 50; + expect(fifty).toBeLessThan(100); + expect(fifty).toBeGreaterThan(25); + expect(fifty).toBeGreaterThanOrEqual(50); + + }); +}); diff --git a/lib/arithmetic.js b/lib/arithmetic.js new file mode 100644 index 0000000..ad9a93a --- /dev/null +++ b/lib/arithmetic.js @@ -0,0 +1 @@ +'use strict'; diff --git a/lib/greet.js b/lib/greet.js new file mode 100644 index 0000000..ad9a93a --- /dev/null +++ b/lib/greet.js @@ -0,0 +1 @@ +'use strict'; diff --git a/package.json b/package.json new file mode 100644 index 0000000..b3e0916 --- /dev/null +++ b/package.json @@ -0,0 +1,19 @@ +{ + "name": "01-node-ecosystem", + "version": "1.0.0", + "description": "Class01_ecosystem", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/pjosifovic/01-node-ecosystem.git" + }, + "author": "Pedja", + "license": "ISC", + "bugs": { + "url": "https://github.com/pjosifovic/01-node-ecosystem/issues" + }, + "homepage": "https://github.com/pjosifovic/01-node-ecosystem#readme" +} From 0b0eee63b8fdd0a4a76d8565b60bab7e1c16e91e Mon Sep 17 00:00:00 2001 From: Predrag Josifovic Date: Mon, 27 Nov 2017 17:28:57 -0800 Subject: [PATCH 3/8] Writing first test for greet.js function --- .eslintrc | 26 -------------------------- __test__/greet.test.js | 19 +++++++++---------- lib/greet.js | 8 ++++++++ package.json | 5 ++++- 4 files changed, 21 insertions(+), 37 deletions(-) delete mode 100644 .eslintrc diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 840d336..0000000 --- a/.eslintrc +++ /dev/null @@ -1,26 +0,0 @@ -{ - "env": { - "browser": true, - "node": true, - "commonjs": true, - "jest": true, - "es6": true - }, - "globals": { - "err": true, - "req": true, - "res": true, - "next": true - }, - "extends": "eslint:recommended", - "parserOptions": { - "sourceType": "module" - }, - "rules": { - "no-console": "off", - "indent": [ "error", 2 ], - "quotes": ["error", "single", { "allowTemplateLiterals": true }], - "comma-dangle": ["error", "always-multiline"], - "semi": [ "error", "always" ] - } -} diff --git a/__test__/greet.test.js b/__test__/greet.test.js index 7ff5dc1..69dbaaa 100644 --- a/__test__/greet.test.js +++ b/__test__/greet.test.js @@ -1,17 +1,16 @@ 'use strict'; -describe('Showcasing basic TDD with JEST', () => { - test('Different ways to use the expect function',() => { - let aNumber = 5; - expect(aNumber).toEqual(5); +const greet = require('../lib/greet'); - let aNullvalue = null; - expect(aNullvalue).toBeNull(); +describe('greet.test.js', () => { - let fifty = 50; - expect(fifty).toBeLessThan(100); - expect(fifty).toBeGreaterThan(25); - expect(fifty).toBeGreaterThanOrEqual(50); + test('greet.hi has single string param and returns "hello ', () => { + expect(greet.hi('Pedja')).toEqual('hello Pedja'); + }); + test('greet.hi returns null if input is not a string', () => { + expect(greet.hi('')).toEqual(null); + expect(greet.hi(1234)).toEqual(null); }); + }); diff --git a/lib/greet.js b/lib/greet.js index ad9a93a..bfc7d31 100644 --- a/lib/greet.js +++ b/lib/greet.js @@ -1 +1,9 @@ 'use strict'; + +const greet = module.exports = {}; + +greet.hi = (name) => { + if(name === '' || typeof name !== 'string') + return null; + return `hello ${name}`; +}; diff --git a/package.json b/package.json index b3e0916..bf5e631 100644 --- a/package.json +++ b/package.json @@ -15,5 +15,8 @@ "bugs": { "url": "https://github.com/pjosifovic/01-node-ecosystem/issues" }, - "homepage": "https://github.com/pjosifovic/01-node-ecosystem#readme" + "homepage": "https://github.com/pjosifovic/01-node-ecosystem#readme", + "devDependencies": { + "jest": "^21.2.1" + } } From def51eacac0c1dc9775edd20ff376617ed3bf54c Mon Sep 17 00:00:00 2001 From: Predrag Josifovic Date: Mon, 27 Nov 2017 18:13:49 -0800 Subject: [PATCH 4/8] adding arithmetic.test.js and arithmetic.js file --- __test__/arithmetic.test.js | 18 ++++++++++++++++++ __test__/greet.test.js | 4 ++-- lib/arithmetic.js | 8 ++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 __test__/arithmetic.test.js diff --git a/__test__/arithmetic.test.js b/__test__/arithmetic.test.js new file mode 100644 index 0000000..c52bf4c --- /dev/null +++ b/__test__/arithmetic.test.js @@ -0,0 +1,18 @@ +'use strict'; + +const arithmetic = require('../lib/arithmetic'); + +describe('arithmetic.test.js', () => { + + test('arithmetic.add has 2 number params and returns sum', () => { + expect(arithmetic.add(1,2)).toBe(3); + }); + + test('arithmetic.add return null is one param is not a number', () => { + expect(arithmetic.add(12, '')).toBeNull(); + expect(arithmetic.add('', 12)).toBeNull(); + expect(arithmetic.add('Pedja', 12)).toBeNull(); + expect(arithmetic.add(12, 'Pedja')).toBeNull(); + }); + +}); diff --git a/__test__/greet.test.js b/__test__/greet.test.js index 69dbaaa..4592071 100644 --- a/__test__/greet.test.js +++ b/__test__/greet.test.js @@ -9,8 +9,8 @@ describe('greet.test.js', () => { }); test('greet.hi returns null if input is not a string', () => { - expect(greet.hi('')).toEqual(null); - expect(greet.hi(1234)).toEqual(null); + expect(greet.hi('')).toBeNull(); + expect(greet.hi(1234)).toBeNull(); }); }); diff --git a/lib/arithmetic.js b/lib/arithmetic.js index ad9a93a..b2ebb86 100644 --- a/lib/arithmetic.js +++ b/lib/arithmetic.js @@ -1 +1,9 @@ 'use strict'; + +const arithmetic = module.exports = {}; + +arithmetic.add = (param1, param2) => { + if(typeof param1 !== 'number' || typeof param2 !== 'number') + return null; + return param1 + param2; +}; From c6ed4c160e0f21acb24cfdf7475a757a4a0764c1 Mon Sep 17 00:00:00 2001 From: Predrag Josifovic Date: Mon, 27 Nov 2017 18:18:28 -0800 Subject: [PATCH 5/8] adding arithmetic.sub function and tests into arithmetic.test.js --- __test__/arithmetic.test.js | 13 ++++++++++++- lib/arithmetic.js | 6 ++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/__test__/arithmetic.test.js b/__test__/arithmetic.test.js index c52bf4c..99ef9c1 100644 --- a/__test__/arithmetic.test.js +++ b/__test__/arithmetic.test.js @@ -4,7 +4,7 @@ const arithmetic = require('../lib/arithmetic'); describe('arithmetic.test.js', () => { - test('arithmetic.add has 2 number params and returns sum', () => { + test('arithmetic.add has 2 number params and returns their sum', () => { expect(arithmetic.add(1,2)).toBe(3); }); @@ -15,4 +15,15 @@ describe('arithmetic.test.js', () => { expect(arithmetic.add(12, 'Pedja')).toBeNull(); }); + test('arithmetic.sub has 2 number params and returns second param subtracted from the first one', () => { + expect(arithmetic.sub(2,1)).toBe(1); + }); + + test('arithmetic.sub return null is one param is not a number', () => { + expect(arithmetic.sub(12, '')).toBeNull(); + expect(arithmetic.sub('', 12)).toBeNull(); + expect(arithmetic.sub('Pedja', 12)).toBeNull(); + expect(arithmetic.sub(12, 'Pedja')).toBeNull(); + }); + }); diff --git a/lib/arithmetic.js b/lib/arithmetic.js index b2ebb86..2bd4856 100644 --- a/lib/arithmetic.js +++ b/lib/arithmetic.js @@ -7,3 +7,9 @@ arithmetic.add = (param1, param2) => { return null; return param1 + param2; }; + +arithmetic.sub = (param1, param2) => { + if(typeof param1 !== 'number' || typeof param2 !== 'number') + return null; + return param1 - param2; +}; From c20d9e3ae779715771204fc61a3e7453e634e2e8 Mon Sep 17 00:00:00 2001 From: Predrag Josifovic Date: Mon, 27 Nov 2017 18:24:16 -0800 Subject: [PATCH 6/8] cleaning up code in test.js files --- __test__/arithmetic.test.js | 8 ++++++-- __test__/greet.test.js | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/__test__/arithmetic.test.js b/__test__/arithmetic.test.js index 99ef9c1..e9c0a45 100644 --- a/__test__/arithmetic.test.js +++ b/__test__/arithmetic.test.js @@ -11,8 +11,10 @@ describe('arithmetic.test.js', () => { test('arithmetic.add return null is one param is not a number', () => { expect(arithmetic.add(12, '')).toBeNull(); expect(arithmetic.add('', 12)).toBeNull(); - expect(arithmetic.add('Pedja', 12)).toBeNull(); - expect(arithmetic.add(12, 'Pedja')).toBeNull(); + expect(arithmetic.add('hello', 12)).toBeNull(); + expect(arithmetic.add(12, 'hello')).toBeNull(); + expect(arithmetic.add('', '')).toBeNull(); + expect(arithmetic.add('hello', 'world')).toBeNull(); }); test('arithmetic.sub has 2 number params and returns second param subtracted from the first one', () => { @@ -24,6 +26,8 @@ describe('arithmetic.test.js', () => { expect(arithmetic.sub('', 12)).toBeNull(); expect(arithmetic.sub('Pedja', 12)).toBeNull(); expect(arithmetic.sub(12, 'Pedja')).toBeNull(); + expect(arithmetic.sub('', '')).toBeNull(); + expect(arithmetic.sub('hello', 'world')).toBeNull(); }); }); diff --git a/__test__/greet.test.js b/__test__/greet.test.js index 4592071..a51d852 100644 --- a/__test__/greet.test.js +++ b/__test__/greet.test.js @@ -5,12 +5,13 @@ const greet = require('../lib/greet'); describe('greet.test.js', () => { test('greet.hi has single string param and returns "hello ', () => { - expect(greet.hi('Pedja')).toEqual('hello Pedja'); + expect(greet.hi('world')).toEqual('hello world'); }); test('greet.hi returns null if input is not a string', () => { expect(greet.hi('')).toBeNull(); expect(greet.hi(1234)).toBeNull(); + expect(greet.hi(true)).toBeNull(); }); }); From 40a40723143762d8adf816df572023e7cc7e686c Mon Sep 17 00:00:00 2001 From: Predrag Josifovic Date: Mon, 27 Nov 2017 21:33:09 -0800 Subject: [PATCH 7/8] updating README.md file --- README.md | 63 ++++++++++++++----------------------------------------- 1 file changed, 16 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index 61783ab..91080d5 100644 --- a/README.md +++ b/README.md @@ -1,53 +1,22 @@ -![CF](https://camo.githubusercontent.com/70edab54bba80edb7493cad3135e9606781cbb6b/687474703a2f2f692e696d6775722e636f6d2f377635415363382e706e67) 01: Node Ecosystem +![CF](https://camo.githubusercontent.com/70edab54bba80edb7493cad3135e9606781cbb6b/687474703a2f2f692e696d6775722e636f6d2f377635415363382e706e67) Lab class 01: Node Ecosystem === -## Submission Instructions -* Work in a fork of this repository. -* Work in a branch on your fork. -* Write all of your code in a directory named `lab-` + `` **e.g.** `lab-susan`. -* Open a pull request to this repository. -* Submit on canvas a question and observation, how long you spent, and a link to your pull request. -* Features without unit tests behind them will not be graded. +#### greet Module +NodeJS module `greet` located in the lib/ directory(`lib/greet.js`) and it exports a single function - `greet.hi`. +* The `greet.hi` function has a single parameter (arity of one) that should expect a string as it's input +* The `greet.hi` function returns the input name, concatenated with "hello ": eg. ("hello world") +* The `greet.hi` function returns `null` if the input is not a string. -## Resources +#### arithmetic Module +NodeJS module `arithmetic` located in the lib/ directory (`lib/arithmetic.js`) and it exports an object. This module has `add` and `sub` methods that implement addition and subtraction. +* The `add` method takes two parameters; + * If either parameter is a non-number the function returns `null` + * Else return the sum of the 2 numbers +* The `sub` method also takes two parameters; + * If either parameter is a non-number the function returns `null` + * Else it return the second parameter subtracted from the first parameter. + +## Used Resources * [Jest Getting Started](https://facebook.github.io/jest/docs/en/getting-started.html) * [Jest Globals](https://facebook.github.io/jest/docs/en/api.html#content) * [Jest Expect](https://facebook.github.io/jest/docs/en/expect.html#content) - -## Configuration -Configure the root of your repository with the following files and directories. Thoughfully name and organize any aditional configuration or module files. -* **README.md** - contains documentation -* **.gitignore** - contains a [robust](http://gitignore.io) `.gitignore` file -* **.eslintrc** - contains the course linter configuratoin -* **.eslintignore** - contains the course linter ignore configuration -* **lib/** - contains module definitions -* **__test__/** - contains unit tests - -## Feature Tasks -#### Greet Module -Create a NodeJS module in the lib/ directory named `greet.js` that exports a single function. -* The `greet` function should have a single parameter (arity of one) that should expect a string as it's input -* The `greet` function should return the input name, concatenated with "hello ": eg. ("hello susan") -* The `greet` function should return `null` if the input is not a string - -#### Arithmetic Module -Create a NodeJS module in the lib/ directory named `arithmetic.js` that exports an object. This module should have `add` and `sub` methods that implament addition and subtraction. -* The `add` method should have an arity of two (define two paramiters) - * If either parameter is a non-number the function should return null - * Else return the sum of the 2 numbers -* The `sub` method should have an arity of two (define two paramiters) - * If either parameter is a non-number the function should return null - * Else return the second paramiter subtracted from the first paramiter - -## Testing -#### Greet Module Tests -* Write a test that expects the greet module to return `null` when you supply non string values -* Write a test the expects the greet module to return `'hello world'` - * This should happen when invoked with `'world'` as the first argument - -#### Arithmetic Module Tests -* Test each method for proper use (invoded with number arguments) -* Test each method for inproper use (invoded with one or more non-numner arguments) - -## Documentation -In your README.md describe the exported values of each module defined in your lib/ directory. Every function description should include it's airty (expected number of paramiters), the expected data for each paramiter (data-type and limitations), and it's behavior (for both valid and invalued use). Feel free to write any additional information in your README.md. From a249535afcd576c3be45009fd4aefa2f889f744e Mon Sep 17 00:00:00 2001 From: Predrag Josifovic Date: Mon, 27 Nov 2017 21:51:15 -0800 Subject: [PATCH 8/8] moving all the code to lab-pedja folder --- .DS_Store | Bin 0 -> 6148 bytes .eslintignore => lab-pedja/.eslintignore | 0 .eslintrc.json => lab-pedja/.eslintrc.json | 0 .gitignore => lab-pedja/.gitignore | 0 README.md => lab-pedja/README.md | 0 .../__test__}/arithmetic.test.js | 0 {__test__ => lab-pedja/__test__}/greet.test.js | 0 {lib => lab-pedja/lib}/arithmetic.js | 0 {lib => lab-pedja/lib}/greet.js | 0 package.json => lab-pedja/package.json | 0 10 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 .DS_Store rename .eslintignore => lab-pedja/.eslintignore (100%) rename .eslintrc.json => lab-pedja/.eslintrc.json (100%) rename .gitignore => lab-pedja/.gitignore (100%) rename README.md => lab-pedja/README.md (100%) rename {__test__ => lab-pedja/__test__}/arithmetic.test.js (100%) rename {__test__ => lab-pedja/__test__}/greet.test.js (100%) rename {lib => lab-pedja/lib}/arithmetic.js (100%) rename {lib => lab-pedja/lib}/greet.js (100%) rename package.json => lab-pedja/package.json (100%) diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0