Skip to content

Commit

Permalink
Simplify testing setup.
Browse files Browse the repository at this point in the history
- We can now specify manifestPath
- Still need to convert from js to yaml
  • Loading branch information
0xjocke committed Jun 29, 2022
1 parent d0b5e92 commit 5788c09
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
1 change: 1 addition & 0 deletions matchstick.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
manifestPath: subgraphs/main.yaml
28 changes: 6 additions & 22 deletions scripts/testSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,25 @@ const fs = require('fs');
const yaml = require('js-yaml');

/**
* Currently matchstick (the testing framework) have no way of providing a different path to the subgraph configuration file,
* it requires it to be in the root folder.
* It also requires the configuration to be in yaml.
* Currently matchstick (the testing framework), requires the configuration to be in yaml.
* 1. This function reads the main subgraph configuration file.
* 2. Updates paths to be relative to the root level
* 3. Convert to yaml
* 4. Writes out the yaml file with required "subgraph.yaml" in the root level.
* 2. Convert to yaml
* 3. Writes out the yaml file with required "main.yaml" in the root level.
*
* The function below `afterTests` will remove this file.
*
* When matchstick add support config file with different name, non root path and non yaml we can remove this workaround
* When matchstick add support for non yaml configs we can remove this workaround
*
*/
const prepareTests = () => {
const main = require('../subgraphs/main.js');
main.schema.file = main.schema.file.replace('./', './subgraphs/');
main.dataSources.forEach((dataSource) => {
dataSource.mapping.file = dataSource.mapping.file.replace('../', './');
dataSource.mapping.abis.forEach((abi) => {
abi.file = abi.file.replace('../', './');
});
});
main.templates.forEach((template) => {
template.mapping.file = template.mapping.file.replace('../', './');
template.mapping.abis.forEach((abi) => {
abi.file = abi.file.replace('../', './');
});
});
const yamlContent = yaml.dump(main);
fs.writeFileSync(path.join(__dirname, '../subgraph.yaml'), yamlContent);
fs.writeFileSync(path.join(__dirname, '../subgraphs/main.yaml'), yamlContent);
};

const afterTests = () => {
try {
fs.rmSync(path.join(__dirname, '../subgraph.yaml'));
fs.rmSync(path.join(__dirname, '../subgraphs/main.yaml'));
} catch (error) {
console.log(error);
}
Expand Down

0 comments on commit 5788c09

Please sign in to comment.