Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0d3a5c
commit 74efc1b
Showing
13 changed files
with
6,114 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
dist/ | ||
node_modules/ | ||
target/ | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
dist | ||
test | ||
bundle.json | ||
README.md |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
``` |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
}) |
Oops, something went wrong.