Skip to content

Commit 57bf55f

Browse files
committed
Update / clean up tests
1 parent 63f0598 commit 57bf55f

6 files changed

+117
-118
lines changed

.eslintrc.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
module.exports = {
2-
'root': true,
3-
'env': {
4-
'node': true,
5-
'es6': true
2+
env: {
3+
node: true,
4+
es6: true
65
},
7-
'extends': [
6+
extends: [
87
'plugin:vue/essential',
98
'eslint:recommended'
109
],
11-
'parserOptions': {
12-
'ecmaVersion': 2018
10+
parserOptions: {
11+
ecmaVersion: 2018
1312
},
14-
'rules': {
13+
rules: {
1514
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
1615
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
17-
'semi': ['error', 'never'],
16+
semi: ['error', 'never'],
1817
// enable additional rules
1918
'linebreak-style': ['error', 'unix'],
2019
// node specific
@@ -31,7 +30,7 @@ module.exports = {
3130
'no-trailing-spaces': 'error',
3231
'no-unused-vars': ['error', { 'args': 'none' }]
3332
},
34-
'parserOptions': {
35-
'parser': 'babel-eslint'
33+
parserOptions: {
34+
parser: 'babel-eslint'
3635
}
3736
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"serve": "vue-cli-service serve",
99
"build": "vue-cli-service build",
1010
"lint": "eslint src --ignore-pattern node_modules --fix",
11-
"test": "cross-env NODE_ENV=testing tape test/*-test.js | tap-spec && vue-cli-service test:unit",
11+
"test": "cross-env NODE_ENV=testing PORT=6666 tape test/*-test.js test/**/*-test.js | tap-spec && vue-cli-service test:unit",
1212
"test:unit": "vue-cli-service test:unit"
1313
},
1414
"devDependencies": {

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# "Begin basic Vue app + API
22

3-
Vue's starter app, able to be extended by Begin-based API endpoints.
3+
[Vue](https://vuejs.org)'s starter app, extended by [Begin](https://begin.com)-based API endpoints.
44

55

66
## Getting started
77

8-
## Project setup
8+
### Project setup
99
```
1010
npm install
1111
```

test/00-html-test.js

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
let test = require('tape')
2+
let tiny = require('tiny-json-http')
3+
let sandbox = require('@architect/sandbox')
4+
let url = 'http://localhost:6666'
5+
6+
/**
7+
* Sandbox / http test
8+
* - Demonstrates execising basic web integration tests using the local dev server
9+
*/
10+
test('Set up env', t => {
11+
t.plan(1)
12+
t.ok(sandbox, 'sandbox loaded')
13+
})
14+
15+
let end // Saves a reference to be used later to shut down the sandbox
16+
test('Start sandbox', async t => {
17+
t.plan(1)
18+
end = await sandbox.start()
19+
t.ok(end, 'Sandbox started!')
20+
})
21+
22+
test('get / (continuation-passing style)', t => {
23+
t.plan(1)
24+
tiny.get({url},
25+
function win (err, result) {
26+
if (err) {
27+
t.fail(err)
28+
} else {
29+
t.ok(result, 'Got result', console.log(result.body.toString().substring(0,50) + '...'))
30+
}
31+
})
32+
})
33+
34+
test('get / (promise style)', t => {
35+
t.plan(1)
36+
tiny.get({url})
37+
.then(function win (result) {
38+
t.ok(result, 'Got result:', console.log(result.body.toString().substring(0,50) + '...'))
39+
})
40+
.catch(function fail (err) {
41+
t.fail(err)
42+
})
43+
})
44+
45+
test('get / (async/await style)', async t => {
46+
t.plan(1)
47+
try {
48+
let result = await tiny.get({url})
49+
t.ok(result, 'Got result:', console.log(result.body.toString().substring(0,50) + '...'))
50+
} catch (err) {
51+
t.fail(err)
52+
}
53+
})
54+
55+
test('Shut down sandbox', t=> {
56+
t.plan(1)
57+
end()
58+
tiny.get({url},
59+
function win (err, result) {
60+
if (err) {
61+
t.equal(err.code, 'ECONNREFUSED', 'Sandbox succssfully shut down')
62+
} else {
63+
t.fail('Sandbox did not shut down')
64+
}
65+
})
66+
})

test/01-data-test.js renamed to test/example/01-begin-data-example-test.js

Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,71 @@
11
let test = require('tape')
2-
let sandbox = require('@architect/sandbox')
32
let data = require('@begin/data')
3+
let sandbox = require('@architect/sandbox')
4+
let logJSON = i => console.log(JSON.stringify(i,null,2))
45

5-
test('env', t => {
6+
/**
7+
* Begin Data test
8+
* - Demonstrates basic usage of Begin Data, a fast, free, durable, wide-column persistence store already built into your app
9+
*/
10+
test('Set up env', t => {
611
t.plan(4)
7-
t.ok(data, 'data')
8-
t.ok(data.get, 'data')
9-
t.ok(data.set, 'data')
10-
t.ok(data.destroy, 'data')
12+
t.ok(data, 'Begin Data loaded')
13+
t.ok(data.get, 'data.get ready')
14+
t.ok(data.set, 'data.set ready')
15+
t.ok(data.destroy, 'data.destroy ready')
1116
})
1217

13-
/**
14-
* kick a sandbox up
15-
*/
16-
let end
17-
test('sandbox.start', async t=> {
18+
let end // Saves a reference to be used later to shut down the sandbox
19+
test('Start sandbox', async t=> {
1820
t.plan(1)
1921
end = await sandbox.start()
20-
t.ok(true, 'started sandbox')
22+
t.ok(end, 'Sandbox started!')
2123
})
2224

23-
/**
24-
* working with one document
25-
*
26-
* - set
27-
* - get
28-
* - destroy
29-
*/
30-
31-
test('data.set one document', async t => {
25+
test('data.set (one document)', async t => {
3226
t.plan(1)
3327
let result = await data.set({
3428
table: 'tasks',
3529
key: 'task1'
3630
})
37-
t.ok(result.key === 'task1', 'wrote document')
38-
console.log(result)
31+
t.ok(result.key === 'task1', 'Wrote document')
32+
logJSON(result,null,2)
3933
})
4034

41-
test('data.get one document', async t => {
35+
test('data.get (one document)', async t => {
4236
t.plan(1)
4337
let task = await data.get({
4438
table: 'tasks',
4539
key: 'task1'
4640
})
47-
t.ok(task.key === 'task1', 'read document')
48-
console.log(task)
41+
t.ok(task.key === 'task1', 'Read document')
42+
logJSON(task,null,2)
4943
})
5044

51-
test('data.del one document', async t => {
45+
test('data.destroy (one document)', async t => {
5246
t.plan(1)
5347
let result = await data.destroy({
5448
table: 'tasks',
5549
key: 'task1'
5650
})
57-
t.ok(result, 'deleted document')
58-
console.log(result)
51+
t.ok(result, 'Deleted document')
52+
logJSON(result,null,2)
5953
})
6054

6155
/**
62-
* if no key is supplied one is created
56+
* If no key is supplied, one is created automatically
6357
*/
64-
test('data.set generates a unique key if one is not supplied', async t => {
58+
test('data.set generates a unique key', async t => {
6559
t.plan(1)
6660
let result = await data.set({
6761
table: 'tasks'
6862
})
69-
t.ok(result.key, 'saved document has a key')
70-
console.log(result)
63+
t.ok(result.key, 'Saved document has a key')
64+
logJSON(result,null,2)
7165
})
7266

7367
/**
74-
* Any metadata is fine
68+
* Any (meta)data is allowed
7569
*/
7670
test('data.set allows for any JSON document; only table and key are reserved', async t => {
7771
t.plan(1)
@@ -81,8 +75,8 @@ test('data.set allows for any JSON document; only table and key are reserved', a
8175
complete: false,
8276
timeframe: new Date(Date.now()).toISOString()
8377
})
84-
t.ok(result.key, 'saved document is rich')
85-
console.log(result)
78+
t.ok(Object.getOwnPropertyNames(result.key).length > 2, 'Saved document has multiple properties')
79+
logJSON(result,null,2)
8680
})
8781

8882
/**
@@ -109,23 +103,23 @@ test('data.set accepts an array to batch save documents', async t => {
109103
timeframe: new Date(Date.now()).toISOString()
110104

111105
}])
112-
t.ok(result.length, 'saved batch')
113-
console.log(result)
106+
t.equal(result.length, 3, 'Saved document batch')
107+
logJSON(result,null,2)
114108
})
115109

110+
/**
111+
* Scan a table
112+
*/
116113
test('data.get can read an entire table', async t => {
117114
t.plan(1)
118115
let result = await data.get({
119116
table: 'tasks'
120117
})
121-
t.ok(result, 'got docs')
122-
console.log(result)
118+
t.ok(result.length > 1, 'Got docs')
119+
logJSON(result,null,2)
123120
})
124121

125-
/**
126-
* shut down the sandbox cleanly
127-
*/
128-
test('sandbox.end', async t=> {
122+
test('Shut down sandbox', async t=> {
129123
t.plan(1)
130124
end()
131125
t.ok(true, 'shutdown')

0 commit comments

Comments
 (0)