Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command/Context API to Let External Concerns Manipulate Counterfact #730

Open
dethell opened this issue Jan 18, 2024 · 2 comments
Open

Command/Context API to Let External Concerns Manipulate Counterfact #730

dethell opened this issue Jan 18, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@dethell
Copy link
Collaborator

dethell commented Jan 18, 2024

Presently we can use the REPL to work with a specific context and toggle various settings, alter data, etc, while running our UI against the mock server so we can test various alternating scenarios. Think of an authentication endpoint that might have 3 or 4 different response types (invalid password, password change required, etc).

Ideally we could have a set of API calls to the Counterfact server that have nothing to do with the Open API spec, but are specific to controlling Counterfact. In a Playwright test I could have a UI test that exercises all the various paths of an auth scenario (see above) without having to "bake" into the mock logic special hardcoded values such as different usernames that exercise the various response paths. Instead we could just have our mock context expose functions that let us easily toggle back and forth between the various response states. Our E2E test could run a set of test, then hit the Counterfact command API to switch the response state, rerun the tests and have it exercise the other paths.

@pmcelhaney pmcelhaney added the enhancement New feature or request label Jan 18, 2024
@pmcelhaney
Copy link
Owner

Theoretically, this can be done today.

import { counterfact } from "counterfact/dist/server/app.js";

const {
        contextRegistry,
        koaApp,
        koaMiddleware: middleware,
        registry,
        start,
} = await counterfact({ /* config values */ });

We need to add an exports property to package.json so the import will look like this:

import { counterfact } from "counterfact";

And we need to document the API.

@pmcelhaney
Copy link
Owner

We also need to break out the REPL server so it doesn't automatically start when we call counterfact(). We shouls configure and run the REPL server from the outside looking in, in ./bin/counterfact.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants