Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Connoropolous committed Oct 29, 2018
1 parent a0d3a5c commit 74efc1b
Show file tree
Hide file tree
Showing 13 changed files with 6,114 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
dist/
node_modules/
target/

4 changes: 4 additions & 0 deletions .hcignore
@@ -0,0 +1,4 @@
dist
test
bundle.json
README.md
14 changes: 14 additions & 0 deletions app.json
@@ -0,0 +1,14 @@
{
"name": "Tasktaskic",
"description": "A little todo app",
"authors": [
{
"indentifier": "Connor Turland <connor.turland@holo.host>",
"public_key_source": "",
"signature": ""
}
],
"version": "0.1.0",
"dht": {},
"properties": null
}
31 changes: 31 additions & 0 deletions test/README.md
@@ -0,0 +1,31 @@
# js-tests-scaffold

This is a recommended configuration for developing tests for Holochain DNA packages. The point of these files are to write tests that can successfully run within the [`hcshell`](https://github.com/holochain/holosqape#hcshell) Holochain container environment.

It currently includes webpack in its configuration because the javascript execution environment in the [`hcshell`](https://github.com/holochain/holosqape#hcshell) container does not support full ES6 Javascript.
In terms of syntax, ES5 is safe, but check the [QJSEngine documentation](http://doc.qt.io/qt-5/qtqml-javascript-functionlist.html) to be completely sure of syntax compatibility.

To get proper assertions and formatted output we want to use existing JS scripting frameworks. The configuration currently uses [tape](https://github.com/substack/tape) as a testing framework. We chose Tape for now because of its minimal footprint.

These files are included into the `test` folder of any new DNA source code that is started using `hc init`.

Dependencies are installed by running `npm install`.

Javascript build step is done by running `npm run build`. This places a new file called `bundle.js` within a `dist` folder, within this folder.

Note that those steps are performed automatically by `hc test`.

**Note about default configuration with TAPE testing**: If you use this default configuration with Tape for testing, to get an improved CLI visual output (with colors! and accurate exit codes), we recommend adjusting the command you use to run tests as follows:
```
hc test | test/node_modules/faucet/bin/cmd.js
```

## Webpack config
If you create your own testing project and you want to use Webpack for bundling make sure to set the following node parameters to have the output run in `hcshell` JS engine:

```
node: {
fs: 'empty',
setImmediate: false
}
```
30 changes: 30 additions & 0 deletions test/index.js
@@ -0,0 +1,30 @@
// This test file uses the tape testing framework.
// To learn more, go here: https://github.com/substack/tape
const test = require('tape');

// instantiate an app from the DNA JSON bundle
const app = Container.loadAndInstantiate("dist/bundle.json")

// activate the new instance
app.start()

test('can create a task', (t) => {
t.plan(1)
const input = JSON.stringify({
text: "my first thing to do"
})
const result = app.call("tasks", "main", "create_task", input)
t.equal(result, JSON.stringify({ address: "QmSHW6f4xnePuBf55kWwBFc5srtNGv98k9LuMB8xBoRq5Z" }))
})

test('can list tasks', (t) => {
t.plan(1)
const input = JSON.stringify({})
const result = app.call("tasks", "main", "list_tasks", input)
const parsed = JSON.parse(result)
const expected = {
text: "my first thing to do",
complete: false
}
t.deepEqual(parsed[0], expected)
})

0 comments on commit 74efc1b

Please sign in to comment.