Skip to main content

Integration Tests

We place integration tests in JS in a separate directory at the same level as /src, called /integration-tests (read more), placing this folder within a /tests folder at root-level that contains the unit tests folder would also be plausible. Refer to this folder structure below:

โ”œโ”€โ”€ package.json                โŸต contains `dependencies` for contract and `devDependencies` for workspaces-js tests
โ”œโ”€โ”€ src
โ”‚ โ””โ”€โ”€ index.js โŸต contract code
โ”œโ”€โ”€ node_modules
โ””โ”€โ”€ integration-tests โŸต integration test directory
โ””โ”€โ”€ tests.js โŸต integration test file

A sample configuration for this project's package.json is shown below:

{
"name": "simple-example",
"version": "0.1.0",
"description": "Simple json file example",
"main": "index.js",
"type": "module",
"license": "MIT",
"directories": {
"test": "test"
},
"scripts": {
"build": "near-sdk-js build",
"test": "ava"
},
"dependencies": {
"near-sdk-js": "0.6.0"
},
"devDependencies": {
"ava": "^4.3.3",
"near-workspaces": "^3.2.2"
},
"ava": {
"files": [
"test/**/*.ava.js"
],
"require": [],
"failFast": false,
"timeout": "2m",
"failWithoutAssertions": true,
"environmentVariables": {},
"verbose": true,
"nodeArguments": []
}
}

The tests.js file above will contain the integration tests. These can be run with the following command from the same level as the test package.json file:

npm test

Was this page helpful?