Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
Update documentation (#20)
Browse files Browse the repository at this point in the history
* Update documentation

* Fix wording

* Support local imports (#22)

* Create tests for import replacer

* Add jest packages. Bump version with beta release

* Update regexp to include local paths
  • Loading branch information
Maksim Daunarovich authored May 20, 2021
1 parent f3bde6f commit 9f300e7
Show file tree
Hide file tree
Showing 9 changed files with 6,566 additions and 2,436 deletions.
540 changes: 13 additions & 527 deletions README.md

Large diffs are not rendered by default.

437 changes: 437 additions & 0 deletions docs/api.md

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions docs/examples/basic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Basic usage
Before using any of the methods you need to `init` the framework, basically telling where you Cadence
code will live. In example below, we put all the Cadence code in the folder named `cadence` one level above the place
where your test script is located.

```javascript
const basePath = path.resolve(__dirname, "../cadence");
```

Let's create `deploy.test.js` file and write some basic test, which would create 4 accounts for us and output their addresses:

```javascript
import path from "path";

const basePath = path.resolve(__dirname, "../cadence");

beforeAll(() => {
init(basePath);
});

describe("Accounts", () => {
test("Create Accounts", async () => {
const Alice = await getAccountAddress("Alice");
const Bob = await getAccountAddress("Bob");
const Charlie = await getAccountAddress("Charlie");
const Dave = await getAccountAddress("Dave");

console.log("Four accounts were created with following addresses:\n", {
Alice,
Bob,
Charlie,
Dave,
});
});
});
```

Run emulator with `flow emulator -v` and then in another terminal run `jest`
45 changes: 45 additions & 0 deletions docs/examples/metadata.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Complex Arguments
In this example we will pass `{String:String}` dictionary and log it out.

```javascript
import path from "path";

const basePath = path.resolve(__dirname, "../cadence");

beforeAll(() => {
init(basePath);
});

describe("Accounts", () => {
test("log complex arguments", async () => {
const code = `
pub fun main(meta: {String: String}){
log("Display passed meta argument:")
log(meta)
}
`;

const args = [
[
// the following array contains key-value pairs for metadata
[
{ key: "a", value: "one" },
{ key: "b", value: "two" },
],

// Since our script expects {String: String} we need to define types for key and value
t.Dictionary({ key: t.String, value: t.String }),
],
];

const result = await executeScript({
code,
args,
});

console.log({ result });
});
});
```

Run emulator with `flow emulator -v` and then in another terminal run `jest`
37 changes: 37 additions & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Installation

You can get all packages by running following command in terminal
```
npm install flow-js-testing jest @babel/core @babel/preset-env babel-jest @onflow/types
```

### Jest Config

Add `jest.config.js` file in your test folder and populate it with:

```javascript
module.exports = {
testEnvironment: "node",
verbose: true,
coveragePathIgnorePatterns: ["/node_modules/"],
};
```

### Babel Config

Create `babel.config.json`. Copy and paste there following configuration:

```json
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
]
]
}
```
Loading

0 comments on commit 9f300e7

Please sign in to comment.