Technology that brings transparency to complex systems
Harvard Sq, WTC NYC
source: http://www.citiconstruction.net/apps/blog/show/43096160-citi-scaffolding-pte-ltd-
source: http://www.citiconstruction.net/apps/blog/show/43096160-citi-scaffolding-pte-ltd-
source: http://www.citiconstruction.net/apps/blog/show/43096160-citi-scaffolding-pte-ltd-
source: http://www.citiconstruction.net/apps/blog/show/43096160-citi-scaffolding-pte-ltd-
unit tests, unit tests, unit tests, unit tests, unit tests, unit tests
integration tests, integration tests
end to end tests
linter, unit tests, unit tests, unit tests, crash reporting
integration tests, integration tests
end to end tests
linter, unit tests, unit tests, unit tests, crash reporting
integration tests, integration tests
end to end tests
describe('something', () => {
it('does this', () => {
})
})
https://glebbahmutov.com/blog/unit-test-node-code-in-10-seconds/
const actual = ...
assert.equals(actual, expected)
describe('API feature', () => {
it('returns items', () => {
return get(url)
.then(list => {
assert.equals(list, expected)
})
})
})
https://glebbahmutov.com/blog/rest-api-testing-made-easy/
where does the expected value come from?
describe('API feature', () => {
it('returns items', () => {
return get(url)
.then(list => {
assert.equals(list, expected)
})
})
})
boilerplate!
let expected
if (firstTime) {
save('returns-items.json', list)
expected = list
} else {
expected = load('returns-items.json')
}
describe('API feature', () => {
test('returns items', () => {
return get(url)
.then(list => {
expect(list).toMatchSnapshot()
})
})
})
https://facebook.github.io/jest/blog/2016/07/27/jest-14.html
// __snapshots__/test.snapshot.js
exports[`returns items 1`] = `
['foo', 'bar', 'baz']
`
https://facebook.github.io/jest/blog/2016/07/27/jest-14.html
https://github.com/avajs/ava/releases/tag/v0.18.0
https://github.com/facebook/jest/issues/2497
https://www.javascripting.com/view/mocha
https://github.com/bahmutov/snap-shot
const snapshot = require('snap-shot')
it('is 42', () => {
snapshot(42)
})
Any testing framework, async, transpiled code, multiple snapshots per test, anonymous tests
it('compares objects', () => {
const o = {
inner: {
a: 10,
b: 20
},
foo: 'foo (changed)',
newProperty: 'here'
}
snapshot(o)
})
changed value
new value
it('compares multi line strings', () => {
snapshot(`
this is a line
and a second line (changed)
with number 42
`)
})
changed line
const snapshot = require('snap-shot')
it('is 42', () => {
snapshot(42)
})
// snap-shot/index.js
function snapshot(what) {
// hmm, which test called me?
}
const snapshot = require('snap-shot')
it('is 42', () => {
snapshot(42)
})
// other frameworks
function snapshot(what) {
const testName = this.currentText.name
}
const snapshot = require('snap-shot')
it('is 42', () => {
snapshot(42)
})
// snap-shot/index.js
function snapshot(what) {
const stack = (new Error('')).stack
// snapshot (node_modules/snap-shot/index.js:20:10)
// anonymous (my-spec.js:3:2)
// ...
}
use any name!
location around
call to "snapshot"
const falafel = require('falafel')
const callLocation = {line: 3}
falafel(source, options, node => {
if (node.type === 'CallExpression') {
// if node is around callLocation
// found it!
}
})
Different uses of Abstract Syntax Tree in "real world" https://glebbahmutov.com/blog/tags/ast/
Parsing and traversing AST is simple with https://github.com/substack/node-falafel
Saving / loading /diffing values is simple
const snapShot = require('snap-shot-core')
const what // my object / value
const out = snapShot({
what,
file: __filename,
specName: 'my test',
store,
compare: compareFn,
ext: '.test'
})
const snapshot = require('snap-shot')
it('returns most popular item', () => {
const top = api.getMostPopularItem()
snapshot(top)
})
does not work 😩
const snapshot = require('schema-shot')
it('returns most popular item', () => {
const top = api.getMostPopularItem()
snapshot(top)
})
works 🤗 !
Schema-shot - snapshot testing for dynamic data
schemaShot({id: 'd13ef'})
exports['returns most popular item 1'] = {
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"id": {
"type": "string",
"required": true
}
},
"additionalProperties": false
}
Schema-shot - snapshot testing for dynamic data
schemaShot({id: '7fe101'})
Schema-shot - snapshot testing for dynamic data
Error: schema difference data has additional properties data.id: is required
schemaShot({uuid: '66635'})
✅
Help wanted ...