@ package.json
"devDependencies": {
"babel-cli": "^6.16.0", // for production build
"babel-jest": "^16.0.0", // for Jest test with ES6
"babel-plugin-transform-runtime": "^6.15.0", // for Babel Register. Because babel only handle syntax translation, but not provide // missing APIs from old javascript like `Array.includes`.
// `Promise`, `Set`, `Map`, or instance methods like `String.repeat` or
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Conclusion: | |
// Each synchronous call blocks Node's event loop. All concurrent tasks are blocked, and the event loop sits idle, until the call completes. | |
// Another important note, async/await runs at 79% of the speed of bare callbacks. | |
// Full documentation: https://github.com/yortus/asyncawait | |
import { describe, it } from 'mocha'; | |
import { expect } from 'chai'; | |
describe('async/await', ()=> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Promise is triggered by `()`, not `.then()` | |
describe('promise trigger', () => { | |
it('flat promise is triggered by `()` even without .then', done => { | |
let result = [] | |
result.push(1) | |
function aFlatPromise(val) { | |
return new Promise(resolve => { | |
result.push(val) | |
resolve(val) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it('generator function works', () => { | |
function* anotherGenerator(i) { | |
yield i + 1 | |
yield i + 2 | |
yield i + 3 | |
} | |
function* generator(i){ | |
yield i | |
yield* anotherGenerator(i) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('neither sinon faker server respond nor ajax delays', () => { | |
let server | |
beforeEach('set up fake server', () => { | |
server = sinon.fakeServer.create() | |
server.respondWith("GET", 'hey/you', [200, { 'Content-Type': 'application/json' }, JSON.stringify({})]) | |
}) | |
afterEach(() => server.restore()) | |
context('when ajax is called', () => { | |
let result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import proxyquire from 'proxyquire' | |
import originalWebsocket from 'faye-websocket' | |
import FirebaseServer from 'firebase-server' | |
const localhostWS = { | |
'faye-websocket': { | |
'@global': true, | |
Client: url => { | |
const localhostUrl = url.replace(/dummy\d+\.firebaseio\.test/i, 'localhost') | |
return new originalWebsocket.Client(localhostUrl) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { expect } from 'chai' | |
import { setupDatabase, destroyDatabase } from './firebase-faker' | |
describe('Firebase fake server', () => { | |
let server, data, client | |
beforeEach(() => { | |
const port = 45001 | |
data = { | |
states: { | |
CA: 'California', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe.only('middleware 101', () => { | |
let store, stateHistory, dispatched | |
beforeEach(()=>{ | |
const defaultState = { text: 'initial state' } | |
function reducer(state = defaultState, action) { | |
switch (action.type) { | |
case 'SIDE_EFFECT_USER_FETCH': | |
return { text: 'THIS HAS FAILED TO BE ESCAPED!!!!'} | |
case 'say': |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// coordinator => saga => action => reducer => coordinator => ... | |
describe.only('Unidirectional back-end architechure', () => { | |
let store, stateHistory, dispatched | |
beforeEach(()=>{ | |
const defaultState = { text: 'initial state' } | |
function reducer(state = defaultState, action) { | |
switch (action.type) { | |
case 'UPDATE_NUMBER': |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @ package.json | |
{ | |
"scripts": { | |
"jest": "NODE_ENV=test DB_USER=ivan-wang ./node_modules/jest/bin/jest.js", | |
"jest-watch": "NODE_ENV=test DB_USER=ivan-wang ./node_modules/jest/bin/jest.js --watch --onlyChanged" | |
}, | |
"jest": { | |
"testEnvironment": "node", | |
"automock": true, | |
"rootDir": "", |
OlderNewer