Skip to content

Commit

Permalink
feat: make test runner fast by default (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
fahad19 committed May 9, 2024
1 parent 2a66f33 commit 6ed5d0c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 37 deletions.
10 changes: 1 addition & 9 deletions docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,7 @@ $ npx featurevisor test --onlyFailures

### `fast`

By default, Featurevisor's test runner would generate a datafile for your feature against the desired environment for each assertion.

If you have a lot of tests, this can be time-consuming. You can use the `--fast` option to generate datafiles for each environment early packing all the features in the project together, and then run the assertions:

```
$ npx featurevisor test --fast
```

**Note**: This approach is memory intensive and therefore not the default behaviour yet.
This option has been deprecated, because test runner is now fast by default.

## NPM scripts

Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ async function main() {
assertionPattern: options.assertionPattern,
verbose: options.verbose || false,
showDatafile: options.showDatafile || false,
fast: options.fast || false,
onlyFailures: options.onlyFailures || false,
};

Expand Down
11 changes: 1 addition & 10 deletions packages/core/src/tester/testFeature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { createInstance, MAX_BUCKETED_NUMBER } from "@featurevisor/sdk";

import { Datasource } from "../datasource";
import { ProjectConfig } from "../config";
import { getCustomDatafile } from "../builder";

import { checkIfArraysAreEqual } from "./checkIfArraysAreEqual";
import { checkIfObjectsAreEqual } from "./checkIfObjectsAreEqual";
Expand Down Expand Up @@ -55,15 +54,7 @@ export async function testFeature(
continue;
}

const datafileContent =
typeof datafileContentByEnvironment[assertion.environment] !== "undefined"
? datafileContentByEnvironment[assertion.environment]
: await getCustomDatafile({
featureKey: test.feature,
environment: assertion.environment,
projectConfig,
datasource,
});
const datafileContent = datafileContentByEnvironment[assertion.environment];

if (options.showDatafile) {
console.log("");
Expand Down
32 changes: 15 additions & 17 deletions packages/core/src/tester/testProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export interface TestProjectOptions {
verbose?: boolean;
showDatafile?: boolean;
onlyFailures?: boolean;
fast?: boolean;
}

export interface TestPatterns {
Expand Down Expand Up @@ -150,22 +149,21 @@ export async function testProject(
let failedAssertionsCount = 0;

const datafileContentByEnvironment: DatafileContentByEnvironment = {};
if (options.fast) {
for (const environment of projectConfig.environments) {
const existingState = await datasource.readState(environment);
const datafileContent = await buildDatafile(
projectConfig,
datasource,
{
schemaVersion: SCHEMA_VERSION,
revision: "include-all-features",
environment: environment,
},
existingState,
);

datafileContentByEnvironment[environment] = datafileContent;
}

for (const environment of projectConfig.environments) {
const existingState = await datasource.readState(environment);
const datafileContent = await buildDatafile(
projectConfig,
datasource,
{
schemaVersion: SCHEMA_VERSION,
revision: "include-all-features",
environment: environment,
},
existingState,
);

datafileContentByEnvironment[environment] = datafileContent;
}

for (const testFile of testFiles) {
Expand Down

0 comments on commit 6ed5d0c

Please sign in to comment.