Use ava for tests

js-version
Anton Medvedev 6 years ago
parent 97664caa65
commit 6270bdb8a9

@ -12,7 +12,7 @@
"index.js"
],
"scripts": {
"test": "bash test.sh"
"test": "ava"
},
"keywords": [
"json",
@ -25,5 +25,8 @@
"cardinal": "^1.0.0",
"get-stdin": "^5.0.1",
"meow": "^4.0.0"
},
"devDependencies": {
"ava": "^0.24.0"
}
}

@ -0,0 +1,28 @@
'use strict'
const test = require('ava')
const {execSync} = require('child_process')
function fx(json, code = '') {
const output = execSync(`echo '${JSON.stringify(json)}' | node index.js ${code}`).toString('utf8')
return JSON.parse(output)
}
test('pass', t => {
t.deepEqual(fx([{"greeting": "hello world"}]), [{"greeting": "hello world"}])
})
test('anon func', t => {
t.deepEqual(fx({"key": "value"}, "'x => x.key'"), 'value')
})
test('this bind', t => {
t.deepEqual(fx([1, 2, 3, 4, 5], "'this.map(x => x * this.length)'"), [5, 10, 15, 20, 25])
})
test('generator', t => {
t.deepEqual(fx([1, 2, 3, 4, 5], "'for (let i of this) if (i % 2 == 0) yield i'"), [2, 4])
})
test('chain', t => {
t.deepEqual(fx({"items": ["foo", "bar"]}, "'this.items' 'yield* this' 'x => x[1]'"), 'bar')
})

@ -1,9 +0,0 @@
#!/usr/bin/env bash
set -euxo pipefail
readonly fx='node index.js'
echo '[{"greeting": "hello world"}]' | $fx
echo '{"key": "value"}' | $fx "x => x.key"
echo '[1, 2, 3, 4, 5]' | $fx "this.map(x => x * this.length)"
echo '[1, 2, 3, 4, 5]' | $fx "for (let i of this) if (i % 2 == 0) yield i"
echo '{"items": ["foo", "bar"]}' | $fx "this.items" "yield* this; yield 'baz'"
Loading…
Cancel
Save