Skip to content

Commit 631786f

Browse files
committed
update for mocha 0.10
1 parent c4d46db commit 631786f

34 files changed

+176
-107
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
A [CodeRoad](https://coderoad.github.io) tutorial for learning Redux.
44

55
<!-- @import('01') -->
6-
<!-- @import('02') -->
76
<!-- @import('03') -->
87
<!-- @import('04') -->
98
<!-- @import('05') -->
109
<!-- @import('06') -->
10+
<!-- @import('07') -->
1111
<!-- @import('08') -->
1212
<!-- @import('09') -->
13+
<!-- @import('10') -->
1314

1415

1516
## CodeRoad
@@ -28,6 +29,10 @@ CodeRoad is an open-sourced interactive tutorial platform for the Atom Editor. L
2829

2930
## Outline
3031

31-
##### File Structure
32+
##### The Store
3233

33-
Refactor your project into different files.
34+
The "single source of truth".
35+
36+
```js
37+
const store = createStore(reducer, initialState);
38+
```

coderoad.json

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,77 @@
11
{
22
"info": {
33
"title": "CodeRoad Redux JS Tutorial",
4-
"description": "A [CodeRoad](https://coderoad.github.io) tutorial for learning Redux.\n\n<!-- @import('01') -->\n<!-- @import('02') -->\n<!-- @import('03') -->\n<!-- @import('04') -->\n<!-- @import('05') -->\n<!-- @import('06') -->\n<!-- @import('08') -->\n<!-- @import('09') -->"
4+
"description": "A [CodeRoad](https://coderoad.github.io) tutorial for learning Redux.\n\n<!-- @import('01') -->\n<!-- @import('03') -->\n<!-- @import('04') -->\n<!-- @import('05') -->\n<!-- @import('06') -->\n<!-- @import('07') -->\n<!-- @import('08') -->\n<!-- @import('09') -->\n<!-- @import('10') -->"
55
},
66
"pages": [
77
{
8-
"title": "File Structure",
9-
"description": "Refactor your project into different files.",
8+
"title": "The Store",
9+
"description": "The \"single source of truth\".\n\n```js\nconst store = createStore(reducer, initialState);\n```",
1010
"tasks": [
1111
{
12-
"description": "create a folder in your base directory called \"pokemon\" and add a file inside called \"index.js\"",
12+
"description": "install Redux.",
13+
"hints": [
14+
"Run `npm install --save redux`."
15+
],
16+
"actions": [
17+
"open('index.js')"
18+
],
1319
"tests": [
14-
"07/01"
20+
"02/01"
1521
]
1622
},
1723
{
18-
"description": "take your `VOTE_UP` action type from \"index.js\" and put it in \"pokemon/index.js\"",
19-
"tests": [
20-
"07/02"
24+
"description": "import `createStore` from the redux module.",
25+
"hints": [
26+
"Add `import { createStore } from 'redux';`"
2127
],
28+
"tests": [
29+
"02/02"
30+
]
31+
},
32+
{
33+
"description": "create your first store and call it `store`. Use a simple \"reducer\" function for now, let's say `state => state`.",
2234
"hints": [
23-
"\"pokemon/index.js\" should have `const VOTE_UP = 'VOTE_UP';`"
35+
"declare your store, `const store`",
36+
"call store with a simple reducer, `const store = createStore(state => state)`"
37+
],
38+
"tests": [
39+
"02/03"
2440
]
2541
},
2642
{
27-
"description": "take your `voteUp` action creator from \"index.js\" and put it in \"pokemon/index.js\". Export it as a [\"named\" export](https://developer.mozilla.org/en/docs/web/javascript/reference/statements/export).",
43+
"description": "log your store to the console and have a look.",
2844
"tests": [
29-
"07/03"
45+
"02/04"
3046
],
3147
"hints": [
32-
"move `voteUp` into \"pokemon/index.js\"",
33-
"\"pokemon/index.js\" should have `const voteUp = id => ({ type: VOTE_UP, payload: { id } });`"
48+
"console.log(store)"
3449
]
3550
},
3651
{
37-
"description": "take your `pokemon` reducer from \"index.js\" and put it in \"pokemon/index.js\". Export the reducer as a \"default\" export",
52+
"description": "log `store.getState()` to the console",
3853
"tests": [
39-
"07/04"
54+
"02/05"
55+
],
56+
"hints": [
57+
"console.log(store.getState())"
4058
]
4159
},
4260
{
43-
"description": "in your \"index.js\" file, import the action creators and reducer in one line of code.",
61+
"description": "move the initial state to the top of the file, and pass it in as a second param your `createStore`",
4462
"tests": [
45-
"07/05"
63+
"02/06"
4664
],
4765
"hints": [
48-
"Try this: `import { default as pokemon, voteUp } from './pokemon';`"
66+
"Move `initialState` above your `store`",
67+
"Pass in `initialState` as a second param to `createStore`"
68+
],
69+
"actions": [
70+
"insert('const initialState = {\n pokemon: [{\n id: 1,\n name: 'Luvdisc',\n description: 'This heart-shaped POKéMON earned its name by swimming after loving couples it spotted in the ocean’s waves.',\n votes: 3\n }, {\n id: 2,\n name: 'Trubbish',\n description: 'Wanting more garbage, they follow people who litter. They always belch poison gas.',\n votes: 2\n }, {\n id: 3,\n name: 'Stunfisk',\n description: 'Its skin is very hard, so it is unhurt even if stepped on by sumo wrestlers. It smiles when transmitting electricity.',\n votes: 0\n }]\n };\n')"
4971
]
5072
}
5173
],
52-
"onPageComplete": ""
74+
"onPageComplete": "As you can see, the store is just an object with various methods like \"dispatch\" and \"getState\". Let's see what these methods do in the next step."
5375
}
5476
]
5577
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
},
1515
"config": {
1616
"dir": "tutorial",
17-
"testSuffix": ".js",
17+
"edit": true,
1818
"language": "JS",
1919
"runner": "mocha-coderoad",
20-
"edit": true
20+
"testSuffix": ".js"
2121
},
2222
"dependencies": {
2323
"mocha-coderoad": "0.9.1"

tutorial/01/01.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var expect = require('chai').expect;
1+
const expect = require('chai').expect;
22

33
describe('01 setup', () => {
44

tutorial/02/01.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
var chai = require('chai');
2-
var spies = require('chai-spies');
3-
var expect = chai.expect;
1+
const chai = require('chai');
2+
const spies = require('chai-spies');
3+
const expect = chai.expect;
44
chai.use(spies);
55

6-
var spy = chai.spy.on(console, 'log');
6+
let spy = chai.spy.on(console, 'log');
77

8-
/// load('index.js')
8+
const index = require('BASE/index.js');
99

1010
describe('01 Redux', () => {
1111

tutorial/02/02.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
describe('02 createStore', () => {
22

3+
const createStore = index.__get__('createStore');
4+
35
it('isn\'t imported. `import { createStore } from "redux";`', () => {
46
expect(createStore).to.be.defined;
57
});

tutorial/02/03.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
describe('03 store', () => {
22

3+
const store = index.__get__('store');
4+
35
it('isn\'t defined. `const store`', () => {
46
expect(store).to.be.defined;
57
});

tutorial/02/06.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ describe('06 log initialState', () => {
33
it('isn\'t logged to the console.', () => {
44

55
const initialState = {
6-
pokemon: [{
7-
id: 1,
8-
name: 'Luvdisc',
9-
description: 'This heart-shaped POKéMON earned its name by swimming after loving couples it spotted in the ocean’s waves.',
10-
votes: 3
11-
}, {
12-
id: 2,
13-
name: 'Trubbish',
14-
description: 'Wanting more garbage, they follow people who litter. They always belch poison gas.',
15-
votes: 2
16-
}, {
17-
id: 3,
18-
name: 'Stunfisk',
19-
description: 'Its skin is very hard, so it is unhurt even if stepped on by sumo wrestlers. It smiles when transmitting electricity.',
20-
votes: 0
21-
}]
22-
};
6+
pokemon: [{
7+
id: 1,
8+
name: 'Luvdisc',
9+
description: 'This heart-shaped POKéMON earned its name by swimming after loving couples it spotted in the ocean’s waves.',
10+
votes: 3
11+
}, {
12+
id: 2,
13+
name: 'Trubbish',
14+
description: 'Wanting more garbage, they follow people who litter. They always belch poison gas.',
15+
votes: 2
16+
}, {
17+
id: 3,
18+
name: 'Stunfisk',
19+
description: 'Its skin is very hard, so it is unhurt even if stepped on by sumo wrestlers. It smiles when transmitting electricity.',
20+
votes: 0
21+
}]
22+
};
2323

2424
expect(spy).to.have.been.called.with(initialState);
2525
});

tutorial/03/01.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const expect = require('chai').expect;
22

3-
/// load('index.js')
3+
const index = require('BASE/index.js');
4+
5+
const voteUp = index.__get__('voteUp');
46

57
describe('01 voteUp Action', () => {
68

tutorial/03/04.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
describe('04 VOTE_UP action type', () => {
22

3+
const VOTE_UP = index.__get__('VOTE_UP');
4+
35
it('doesn\t exist', () => {
46
expect(VOTE_UP).to.be.defined;
57
});

tutorial/04/01.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
var chai = require('chai');
2-
var spies = require('chai-spies');
3-
var expect = chai.expect;
1+
const chai = require('chai');
2+
const spies = require('chai-spies');
3+
const expect = chai.expect;
44
chai.use(spies);
55

6-
var log = chai.spy.on(console, 'log');
6+
let log = chai.spy.on(console, 'log');
77

8-
/// load('index.js')
8+
const index = require('BASE/index.js');
9+
10+
const reducer = index.__get__('reducer');
911

1012
describe('01 reducer', () => {
1113

tutorial/05/01.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
var expect = require('chai').expect;
1+
const expect = require('chai').expect;
22

3-
/// load('index.js')
3+
const index = require('BASE/index.js');
4+
5+
const reducer = index.__get__('reducer');
46

57
describe('01 the pure reducer', () => {
68

tutorial/05/02.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
describe('02 initialState', () => {
22

3+
const initialState = index.__get__('initialState');
4+
35
it('should be frozen', () => {
46
expect(Object.isFrozen(initialState)).to.be.true;
57
});

tutorial/05/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const nextPokemon = state.pokemon.map(p => {
1818

1919
+ Return a new list of Pokemon after incrementing "votes" of the pokemon with the matching "id"
2020
@test('05/01')
21+
@action(open('index.js'))
2122

2223
+ Let's make a test to see that we are truly returning a new state. Call `Object.freeze()` on your `initialState`. `freeze` makes an object immutable - meaning the object can not be changed. And yet your reducer should still work, since it returns a new state each call.
2324
@test('05/02')

tutorial/06/01.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
var expect = require('chai').expect;
1+
const expect = require('chai').expect;
22

3-
/// load('index.js')
3+
const index = require('BASE/index.js');
4+
5+
const reducers = index.__get__('reducers');
6+
const store = index.__get__('store');
7+
const pokemon = index.__get__('pokemon');
8+
const defaultPokemon = index.__get__('defaultPokemon');
49

510
describe('01 reducers', () => {
611

tutorial/06/02.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
describe('02 "pokemon"', () => {
22

3-
43
it('should be the reducer new name', () => {
54
expect(pokemon).to.be.defined;
65
});

tutorial/06/03.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
describe('03 combineReducers', () => {
22

3+
const combineReducers = index.__get__('combineReducers');
4+
35
it('should be loaded', () => {
46
expect(combineReducers).to.be.defined;
57
});

tutorial/06/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Create modular, composable reducers with `combineReducers`.
55

66
+ create a new `const reducers` and set it equal to "reducer". Pass "reducers" into your store for now, instead of "reducer". We'll use combineReducers shortly, but let's not break the app yet.
77
@test('06/01')
8+
@action(open('index.js'))
89
@hint('First, try this: `const reducers = reducer;`')
910
@hint('Second, try this: `const store = createStore(reducers, initialState);`')
1011

tutorial/07/01.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
var expect = require('chai').expect;
2-
var { resolve } = require('path');
3-
var { readFileSync } = require('fs');
1+
const expect = require('chai').expect;
2+
const { resolve } = require('path');
3+
const { readFileSync } = require('fs');
44

5-
/// load('pokemon/index.js')
6-
7-
// read index.js path for regexing for import and moved files
8-
const indexJsPath = resolve(process.env.DIR, 'index.js');
9-
const indexJs = readFileSync(indexJsPath, 'utf8');
10-
11-
// read pokemon/index.js path for regexing for export
12-
const pokemonJsPath = resolve(process.env.DIR, 'pokemon', 'index.js');
13-
const pokemonJs = readFileSync(pokemonJsPath, 'utf8');
5+
const indexJs = require('BASE/index.js');
6+
const pokemonIndexJs = require('BASE/pokemon/index.js');
147

158
describe('01 "pokemon" folder', () => {
169

tutorial/07/02.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
describe('02 VOTE_UP', () => {
22

3+
// pokemon/index.js - VOTE_UP
4+
const VOTE_UP = pokemonIndexJs.__get__('VOTE_UP');
5+
36
it('should now be in "pokemon/index.js"', () => {
47
expect(VOTE_UP).to.be.defined;
58
expect(VOTE_UP).to.equal('VOTE_UP');
69
});
710

11+
// index.js - VOTE_UP
12+
const VOTE_UP_in_index = indexJs.__get__('VOTE_UP');
13+
814
it('should no longer be in the root "index.js" file', () => {
9-
const regex = /VOTE_UP\s?=/;
10-
expect(indexJs).to.not.match(regex);
15+
expect(VOTE_UP_in_index).to.not.be.defined;
1116
});
1217

1318
});

tutorial/07/03.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
describe('03 "voteUp"', () => {
22

33
it('should be in "pokemon/index.js"', () => {
4+
const voteUp = pokemonIndexJs.__get__('voteUp');
45
expect(voteUp).to.be.defined;
56
expect(typeof voteUp).to.equal('function');
67
});
78

8-
it('should no longer be in the root "index.js"', () => {
9-
const regex = /voteUp\s?=/;
10-
expect(indexJs).to.not.match(regex);
11-
});
9+
it('should be a named export', () => {
10+
const voteUp = require('BASE/pokemon/index.js').voteUp;
11+
expect(voteUp).to.be.defined;
12+
expect(typeof voteUp).to.equal('function');
13+
});
1214

13-
it('should be a named export', () => {
14-
const regex = /export (var|const|let|function)?\s?voteUp/;
15-
expect(pokemonJs).to.match(regex);
16-
});
15+
it('should no longer be in the root "index.js"', () => {
16+
const voteUp = indexJs.__get__('voteUp');
17+
expect(voteUp).not.to.be.defined;
18+
});
1719

1820
});

0 commit comments

Comments
 (0)