Skip to content

Commit 0f9c464

Browse files
Merge pull request #3 from it-shark-pro/fs-module
FS module tasks
2 parents 566cbec + 71141f2 commit 0f9c464

17 files changed

+653
-54
lines changed

.editorconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# EditorConfig helps developers define and maintain consistent
2+
# coding styles between different editors and IDEs
3+
# editorconfig.org
4+
5+
root = true
6+
7+
[*]
8+
end_of_line = lf
9+
charset = utf-8
10+
trim_trailing_whitespace = true
11+
insert_final_newline = true
12+
indent_style = space
13+
indent_size = 2
14+
15+
[*.md]
16+
trim_trailing_whitespace = false

.eslintrc

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"parserOptions": {
3+
"sourceType": "module"
4+
},
5+
"env": {
6+
"es6": true,
7+
"node": true,
8+
"mocha": true
9+
},
10+
"extends": ["eslint:recommended"],
11+
"rules": {
12+
"array-bracket-spacing": 0,
13+
"arrow-parens": [2, "as-needed"],
14+
"comma-dangle": [2, "never"],
15+
"comma-spacing": [2, {"after": true}],
16+
"curly": [2, "multi-line"],
17+
"eqeqeq": 2,
18+
"func-names": 0,
19+
"indent": [2, 2],
20+
"max-len": 0,
21+
"no-console": [ 1, {"allow": ["info", "error", "warn"]}],
22+
"no-new-wrappers": 0,
23+
"no-proto": 0,
24+
"no-prototype-builtins": 0,
25+
"no-restricted-syntax": 1,
26+
"no-sparse-arrays": 0,
27+
"no-unreachable": 2,
28+
"no-unused-expressions": 2,
29+
"no-unused-vars": [2, {"args": "none"}],
30+
"semi": 2,
31+
"quotes": [
32+
2,
33+
"single",
34+
{
35+
"avoidEscape": true,
36+
"allowTemplateLiterals": true
37+
}
38+
],
39+
"require-yield": 1
40+
}
41+
}

.eslintrc.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,3 @@ typings/
5656

5757
# dotenv environment variables file
5858
.env
59-

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
language: node_js
22
node_js:
3-
- "lts/*"
3+
- "lts/*"
4+
5+
script:
6+
- yarn run lint
7+
- yarn run test

README.md

Lines changed: 125 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,125 @@
1-
# nodejs-assessment
1+
[![Build Status](https://travis-ci.org/it-shark-pro/nodejs-assignments.svg?branch=master)](https://travis-ci.org/it-shark-pro/nodejs-assignments)
2+
![Hackage-Deps](https://img.shields.io/hackage-deps/v/lens.svg)
3+
[![Greenkeeper badge](https://badges.greenkeeper.io/it-shark-pro/nodejs-assignments.svg)](https://greenkeeper.io/)
4+
[![GitHub release](https://img.shields.io/github/release/it-shark-pro/nodejs-assignments.svg)](https://github.com/it-shark-pro/js-assignments/releases/latest)
5+
6+
7+
# [Brest IT Shark](https://it-shark.pro/)
8+
[![IT Shark](https://avatars2.githubusercontent.com/u/34164782?s=200&v=4)](http://it-shark.pro/)
9+
## Nodejs Assignments
10+
11+
### Docs
12+
* [How to sync your fork from original repo to keep up with their changes](/docs/sync-fork.md)
13+
* [Submit your solution to us for review](https://goo.gl/X6GjMB)
14+
15+
The motivation of this project is to show TDD process in the wild to the beginners. Assingment tests are implemented in various ways to feel a difference and gain the experience what manner is good, what is bad and what is ugly.
16+
17+
Another idea is to prepare assignment to cover main nodejs features, to drilling and mastering skills. Some tasks are practical, but some tasks are rather synthetic.
18+
19+
And the last idea is to inure trainees to work using unit test and feel uncomfortable when programming without tests.
20+
21+
### To start javascript assignments please follow the next steps:
22+
* [Fork this repo](#user-content-how-to-fork-this-repo)
23+
* [Setup travis-ci to test the commits](#user-content-how-to-setup-travis-ci)
24+
* [Setup the work environment](#user-content-how-to-setup-work-environment)
25+
* [Implement assignments using TDD fashion](#user-content-how-to-implement-assignments-using-tdd-fashion)
26+
* [How to debug tasks](#how-to-debug-tasks)
27+
28+
### How to fork this repo
29+
* Click the **Fork** button at the top-right corner of this page and the repository will be copied to your own account.
30+
* Run `git clone https://github.com/<your-account>/nodejs-assignments.git` from command line to download the repo.
31+
32+
### How to setup travis-ci
33+
* Open [https://travis-ci.org/](https://travis-ci.org/) and sign in with your github account.
34+
* Activate your forked repo **nodejs-assignments**.
35+
* Edit local README.md file and update all links (just replace all occurrences of `'it-shark-pro'` with your account name).
36+
* Commit and push updated README.md to github:
37+
```bash
38+
git add README.md
39+
git commit -m "Update the links"
40+
git push origin master
41+
```
42+
* Open https://github.com/it-shark-pro/nodejs-assignments and test the build icon. Now it will run all tests and update status once you push changes to github. Keep this icon green!
43+
44+
45+
### How to setup work environment
46+
* Download and install the latest [Nodejs](https://nodejs.org/en/download/).
47+
* Run `npm install` from you repository folder to download the required modules. All dependent modules will be located in the *node_modules* folder.
48+
* Open your favorite editor and complete tasks.
49+
* Open your terminal and use `npm test` command to run all tests. You can run single file by passing it as argument `npm test ./test/01-strings-tests.js`.
50+
* The local repo folder has the following structure: <pre>
51+
node_modules - app dependences restored by `npm install` command, you can delete this folder and restore later again.
52+
task - folder with tasks modules, it's your main folder.
53+
test - folder with tests modules to verify the tasks completion.
54+
</pre>
55+
56+
### How to implement assignments using TDD fashion
57+
Now you are ready to implement assignments. Tasks modules are located in the **task** folder. Each module consists of several tasks for specified topic. Each task is usually a regular function:
58+
```javascript
59+
/**
60+
* Reads file by given path synchronously and returns file data.
61+
*
62+
* @param {String} path
63+
* @return {String}
64+
*
65+
* @example
66+
* 'filder/file.txt' => 'File content'
67+
*/
68+
function readFileSync(path) {
69+
/* implement your code here */
70+
throw new Error('Not implemented');
71+
}
72+
```
73+
Resolve this task using the following [TDD steps](https://en.wikipedia.org/wiki/Test-driven_development#Test-driven_development_cycle):
74+
* Run unit tests and make sure that everything is OK and there are no failing tests.
75+
* Read the task description in the comment above the function. Try to understand the idea. If you got it you are to write unit test first, but unit tests are already prepared :) Skip step with writing unit tests.
76+
* Remove the throwing error line from function body
77+
```javascript
78+
throw new Error('Not implemented');
79+
```
80+
and run the unit tests again. Find one test failed (red). Now it's time to fix it!
81+
* Implement the function by any way and verify your solution by running tests until the failed test become passed (green).
82+
* Your solution work, but now time to refactor it. Try to make your code as pretty and simple as possible keeping up the test green.
83+
* Once you can't improve your code and tests are passed you can commit your solution.
84+
* Push your updates to github server and check if tests passed on [travis-ci](https://travis-ci.org/it-shark-pro/nodejs-assignments/builds).
85+
* If everything is OK you can try to resolve the next task.
86+
87+
### How to debug tasks
88+
To debug tests you can use **Node inspector**. To install it just run `npm install -g node-inspector` in your terminal. Then follow next steps:
89+
* Add `debugger;` to the first line of your task.
90+
* Run your test file with `npm run test-debug ./test/01-strings-tests.js`.
91+
* In another terminal run `node-inspector` and copy link from the output.
92+
* Open the link in your favorite browser. You should see Chrome Developers Tools like interface where you can debug your tasks.
93+
* When you found and fix your issue, close the browser's tab with the debug tools, stop the node-inspector by pressing Ctrl-C, stop the test runner by pressing Ctrl-C, remove the `debugger;` from your task.
94+
95+
### How to debug (beginner's way)
96+
There is an easier way to debug for beginners with free Visual Studio Code:
97+
* Install VSC from https://code.visualstudio.com/
98+
* Open project folder in VSC and follow the instruction from https://code.visualstudio.com/docs/runtimes/nodejs#_debugging-your-node-application to create a default `launch.json`
99+
* Modify the `launch.json` in the IDE, set the properties "program" and "args" (empty "args" value run all tests, to run particular test specify this test file in "args"):
100+
```
101+
{
102+
"version": "0.2.0",
103+
"configurations": [
104+
{
105+
...
106+
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
107+
...
108+
"args": ["./test/01-file-system-tests.js"],
109+
...
110+
},
111+
...
112+
]
113+
}
114+
```
115+
* Click in the gutter to the left of the line number to set the breakpoint. Press `F5` to run debug.
116+
* NOTE: The `launch.json` is stored in the `.vscode` project folder.
117+
118+
## Contribution
119+
Feel free to contribute into this project. New tasks and katas are welcome.
120+
121+
## ESLint
122+
To fix linting execute:
123+
```
124+
npm run lint -- --fix
125+
```

docs/sync-fork.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
### 1. Add remote from original repository in your forked repository:
2+
3+
`cd path/into/cloned/fork-repo`
4+
`git remote add upstream [email protected]:it-shark-pro/nodejs-assignments.git`
5+
`git fetch upstream`
6+
7+
### 2. Updating your fork from original repo to keep up with their changes:
8+
9+
`git pull upstream master`
10+
11+
### 3. Resolve conflicts if needed and install npm packages
12+
`npm update`

extensions/it-optional.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
1-
module.exports = function testOptional(title, fn) {
2-
it(title, function () {
3-
try {
4-
fn.call(this);
5-
} catch (err) {
6-
if (err.message === 'Not implemented') {
7-
this.test.skip();
8-
} else {
9-
throw err;
10-
}
1+
function testOptional(fn, callback) {
2+
try {
3+
fn.call(this, callback);
4+
} catch (err) {
5+
if (err.message === 'Not implemented') {
6+
this.test.skip();
7+
} else {
8+
throw err;
119
}
10+
}
11+
}
12+
13+
function itSync(title, fn) {
14+
it(title, function () {
15+
testOptional.call(this, fn);
16+
});
17+
}
18+
19+
function itAsync(title, fn) {
20+
it(title, function (done) {
21+
testOptional.call(this, fn, done);
1222
});
23+
}
24+
25+
module.exports = {
26+
itSync,
27+
itAsync
1328
};

package-lock.json

Lines changed: 54 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)