This repository has been archived by the owner on Nov 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
9 changed files
with
6,566 additions
and
2,436 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,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` |
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,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` |
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,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" | ||
} | ||
} | ||
] | ||
] | ||
} | ||
``` |
Oops, something went wrong.