Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,32 @@ You can run the Liquid Tests of a reconciliation using the following command:
silverfin run-test --handle <handle>
```

#### Run a specific test

To run a specific test by name:

```bash
silverfin run-test --handle <handle> --test <test-name>
```

#### Run batch tests (pattern matching)

To run all tests that contain a specific batch identifier, use the `--batch` option. This is useful when you want to test a group of related tests without running all tests:

```bash
silverfin run-test --handle <handle> --batch <batch>
```

For example, if you have tests named `unit_3_test_1`, `unit_3_test_2`, `unit_3_test_3`, `unit_4_test_1`, etc., you can run only the tests for unit 3:

```bash
silverfin run-test --handle <handle> --batch "unit_3_"
```

This will run all tests that contain the string "unit_3_" in their name (i.e., `unit_3_test_1`, `unit_3_test_2`, and `unit_3_test_3`).

**Note:** You cannot use both `--test` and `--batch` options at the same time.

### Updating the CLI

Whenever a new version of the CLI is available, you should see a message in your terminal informing it, so you can keep it always up to date. To update the CLI to the latest version, you can run the following command:
Expand All @@ -259,6 +285,12 @@ There are two different ways to use the `development-mode`:
silverfin development-mode --handle <handle>
```

You can also use the `--batch` option with development mode to run only tests matching a specific batch identifier:

```bash
silverfin development-mode --handle <handle> --batch "unit_3_"
```

- Using the `--update-templates` flag. This will listen for changes in liquid files. Every time a change is saved to a liquid file of a reconciliation or shared part, it will be updated in Silverfin. **Note that this will not run any liquid test, and it will replace the liquid code of your template in Silverfin.** (equivalent to use: `silverfin update-reconciliation --handle <handle>` or `silverfin update-shared-part --shared-part <name>`)

```bash
Expand Down
20 changes: 16 additions & 4 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ program
.option("-h, --handle <handle>", "Specify the reconciliation to be used (mandatory)")
.option("-at, --account-template <name>", "Specify the account template to be used (mandatory)")
.option("-t, --test <test-name>", "Specify the name of the test to be run (optional)", "")
.option("-b, --batch <batch>", "Run all tests that contain this batch identifier (optional)", "")
.option("--html-input", "Get a static html of the input-view of the template generated with the Liquid Test data (optional)", false)
.option("--html-preview", "Get a static html of the export-view of the template generated with the Liquid Test data (optional)", false)
.option("--preview-only", "Skip the checking of the results of the Liquid Test in case you only want to generate a preview template (optional)", false)
Expand All @@ -465,17 +466,22 @@ program
process.exit(1);
}

if (options.test && options.batch) {
consola.error("You cannot use both --test and --batch options at the same time");
process.exit(1);
}

const templateType = options.handle ? "reconciliationText" : "accountTemplate";
const templateName = options.handle ? options.handle : options.accountTemplate;

if (options.status) {
liquidTestRunner.runTestsStatusOnly(options.firm, templateType, templateName, options.test);
liquidTestRunner.runTestsStatusOnly(options.firm, templateType, templateName, options.test, options.batch);
} else {
if (options.previewOnly && !options.htmlInput && !options.htmlPreview) {
consola.info(`When using "--preview-only" you need to specify at least one of the following options: "--html-input", "--html-preview"`);
process.exit(1);
}
liquidTestRunner.runTestsWithOutput(options.firm, templateType, templateName, options.test, options.previewOnly, options.htmlInput, options.htmlPreview);
liquidTestRunner.runTestsWithOutput(options.firm, templateType, templateName, options.test, options.previewOnly, options.htmlInput, options.htmlPreview, options.batch);
}
});

Expand Down Expand Up @@ -675,22 +681,28 @@ program
.option("-at, --account-template <name>", "Watch for changes in liquid and yaml files related to the account template mentioned. Run a new Liquid Test on each save")
.option("-u, --update-templates", "Watch for changes in any liquid file. Publish the new code of the template into the Platform on each save")
.option("-t, --test <test-name>", `Specify the name of the test to be run (optional). It has to be used together with "--handle"`, "")
.option("-b, --batch <batch>", `Run all tests that contain this batch identifier (optional). It has to be used together with "--handle" or "--account-template"`, "")
.option("--html", `Get a html file of the template's input-view generated with the Liquid Test information (optional). It has to be used together with "--handle"`, false)
.option("--yes", "Skip the prompt confirmation (optional)")
.action((options) => {
cliUtils.checkDefaultFirm(options.firm, firmIdDefault);
cliUtils.checkUniqueOption(["handle", "updateTemplates", "accountTemplate"], options);

if (options.test && options.batch) {
consola.error("You cannot use both --test and --batch options at the same time");
process.exit(1);
}

if (options.updateTemplates && !options.yes) {
cliUtils.promptConfirmation();
}

if (options.accountTemplate) {
devMode.watchLiquidTest(options.firm, options.accountTemplate, options.test, options.html, "accountTemplate");
devMode.watchLiquidTest(options.firm, options.accountTemplate, options.test, options.html, "accountTemplate", options.batch);
}

if (options.handle) {
devMode.watchLiquidTest(options.firm, options.handle, options.test, options.html, "reconciliationText");
devMode.watchLiquidTest(options.firm, options.handle, options.test, options.html, "reconciliationText", options.batch);
}
if (options.updateTemplates) {
devMode.watchLiquidFiles(options.firm);
Expand Down
7 changes: 4 additions & 3 deletions lib/cli/devMode.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ const chokidar = require("chokidar");
* @param {String} testName - Test name (empty string to run all tests)
* @param {boolean} renderInput - Open browser and show the HTML from input view
* @param {String} templateType - Template type (reconciliationText, accountTemplate)
* @param {String} batch - Batch identifier to filter tests (empty string to run all tests)
*/
async function watchLiquidTest(firmId, handle, testName, renderInput, templateType) {
async function watchLiquidTest(firmId, handle, testName, renderInput, templateType, batch = "") {
if (templateType !== "reconciliationText" && templateType !== "accountTemplate") {
consola.error(`Template type is missing or invalid`);
process.exit(1);
Expand All @@ -33,15 +34,15 @@ async function watchLiquidTest(firmId, handle, testName, renderInput, templateTy
// Watch YAML
chokidar.watch(filePath).on("change", async () => {
// Run test
await liquidTestRunner.runTestsWithOutput(firmId, templateType, handle, testName, false, renderInput);
await liquidTestRunner.runTestsWithOutput(firmId, templateType, handle, testName, false, renderInput, false, batch);
});

// Watch liquid files
const liquidFiles = fsUtils.listExistingRelatedLiquidFiles(firmId, handle, templateType);
for (const filePath of liquidFiles) {
chokidar.watch(filePath).on("change", async () => {
// Run test
await liquidTestRunner.runTestsWithOutput(firmId, templateType, handle, testName, false, renderInput);
await liquidTestRunner.runTestsWithOutput(firmId, templateType, handle, testName, false, renderInput, false, batch);
});
}
}
Expand Down
Loading
Loading