For documentation changes, you can just edit and make a pull request. Ignore the instructions below.
If you are not already in contact with us, you can join the #assembly-line-test channel in the docassemble Slack or make a new issue and mention @niharikasingh to let us know you're interested.
- Asking to join as a contributor is simplest. You can fork, but you will have to change lines in your
.env
file and may have to set GitHub secrets in your repository. You have to talk to us either way. - Clone the repository locally:
git clone git@github.com:SuffolkLITLab/ALKiln.git
- Run
npm install
- Create your
.env
file at the root of the project. - Contact @niharikasingh to get important information for your
.env
file. - Run
npm run setup
Advanced contributors: If you're going to work on our docassemble internal testing interviews, do so as a contributor on this repository. Avoid forking if you can. The reasons are complex. If you feel a need to fork, reach out to us.
Before making a pull request
- Search issues to see if what you are thinking of has been discussed yet.
- Make an issue about the change you are thinking of.
- Assign yourself to an issue.
- Make a new branch.
- Make your edits. Feel free to run tests as you go.
- When you're ready to push
- Run
npm run test
to make sure your code passes all our tests. - Make an entry in the
CHANGELOG.md
describing your change. - AVOID changing the version number. We'll do that after merging your changes.
- If needed, update the
README.md
(e.g. the cheat sheet section) and/orCONTRIBUTING.md
docs. Changes to our architecture might require editingCONTRIBUTING.md
.
- Run
- Push to GitHub.
- Wait for the GitHub tests to pass. You may have to re-run failing tests—server restarts or race conditions may interfere with them. We have reduced them greatly, but some are impossible to avoid.
- Make your pull request. Work in progress pull requests are great too. A pull request must be reviewed before it can be merged.
You need to make your own .env
file. It contains sensitive variables, like passwords. We use them for our internal tests. The file should look something like the below:
# For everyone
DOCASSEMBLE_DEVELOPER_API_KEY=<ask @niharikasingh>
SERVER_URL=https://apps-dev.suffolklitlab.org
REPO_URL=https://github.com/SuffolkLITLab/alkiln
SERVER_RELOAD_TIMEOUT_SECONDS=
MAX_SECONDS_FOR_SETUP=
# For internal tests
# Set DEBUG to 1 to run in non-headless mode and see the test run live
DEBUG=
# If you edit interview files (.yml files), you should push to a new
# branch and update BRANCH_PATH to that branch name
BRANCH_PATH=v4
USER1_EMAIL=<ask @niharikasingh>
USER1_PASSWORD=<ask @niharikasingh>
SECRET_VAR1=secret-var1-value
SECRET_VAR2=secret-var2-value
SECRET_FOR_MISSING_FIELD=secret for missing field
SECRET_INVALID_THERE_IS_ANOTHER=invalid value for there_is_another
Only run this the first time you run tests in this repository to make the code available to test on the docassemble server:
npm run setup
If you run takedown
, you will then have to run setup
again.
Use the syntax below to trigger all tests (cucumber and unit tests):
npm run test
Run only cucumber tests:
npm run cucumber
# To test Features or Scenarios specific tags:
npm run cucumber -- "--tags" "@tagname"
To run the unit tests in isolation:
npm run unit
If you or someone else changes the interview code in ./docassemble
, you have to clean up the old data on the server before running setup
again:
npm run takedown
Our tests require the user/developer to have a docassemble server on which they host these interviews (online forms) and at least one developer account. With our help, our users set up the tests to run when they commit new code or to run manually. When GitHub runs the tests, it does the following:
- Sets up on the docassemble server. In a given developer account:
- Creates a new interview for this particular branch of the repository.
- Pulls in the code from that branch into the docassemble server.
- Runs the tests
- Pretends to be an anonymous account that comes to the form and inputs answers.
- Writes up reports and possibly takes screenshots to show to the developer.
- Cleans up by deleting the interview it created
When the developer commits code to GitHub, their account triggers our code, passing along variables that our code needs, like their GitHub secret of the API key for their docassemble server developer account.
Sometimes you will have to add dependencies to ALKiln. You can do so by adding the dependency in the package.json
"dependencies" section, specifying an exact version. Then, run npm install
to update npm-shrinkwrap.json
to have the new dependency.
If you have to update an existing dependency, you can change the version in package.json
, and run npm install
to update npm-shrankwrap.json
.
An honest look at our current project architecture—some of our files and folders, what they do, and how they interact.
ALKiln uses cucumber[^1] with Gherkin syntax, puppeteer, and chai.
The .feature
files are written in Gherkin, a syntax cucumber uses. The "code" in there relies on the functions set up in ./lib/steps.js
.
// The test_something.feature file step
Then I sign
// relies on the code in steps.js
Then('I sign', { timeout: -1 }, async () => {
return wrapPromiseWithTimeout(
scope.steps.sign( scope ),
scope.timeout
);
});
./lib/steps.js
defines all the Gherkin sentences that our users (the developers) can write. See cucumber documentation on defining steps. We sometimes use "cucumber expressions" and, but often use regular expressions as we often want to be more flexible about the user's input.
The file handles things like:
- Creating state
- Defining steps for the users/developers
- Defining steps for internal testing, like testing for appropriate errors and error messages
- Finishing a Scenario
- Finishing all tests
./lib/steps.js
makes heavy use of ./lib/scope.js
, where most of the action happens. We have decided to mostly keep it in one file to avoid bouncing back and forth between files.
Many ./lib/steps.js
steps make use of the scope.steps
object. It is there to avoid duplicating code between steps.
The file handles things like:
- Finding form fields on a page
- Filling out form fields
- Generating random data for form fields
- Waiting for pages to load
- Checking for server restarts
- Generating test report content
./lib/utils/log.js
takes care of logging information of various kinds (normal, debug, error) to the command line in ways we hope are useful. We should probably find a logging library instead, but this is what we have for now. An important feature is that it ensures the messages clearly belong to ALKiln and not to some other process.
The ./lib/utils/session_var.js
file keeps track of what you might otherwise think of as environment variables. We like to think of them as constants, but some of them do need to go through functions, so for consistency we get them all through functions. Also because it was easier to test them when they are functions.
All of the setup and takedown logic is in the ./lib/docassemble
directory. It is named after the docassemble API code that is in there. Also, setup and takedown interact very closely with docassemble and the docassemble server.
Other files also use the docassemble API functions, so this folder is in a bit of a messy position.
When you npm run
the scripts in our ./package.json
you can setup, run, or takedown tests. We are working on converting this to a command line tool to avoid some complexity in GitHub actions, increase security, and align more with what this framework has grown into. (TODO: Define this better)
Our ./action.yml
is a composite action. The users/developers let it do most of the work for them. It installs npm, installs our repo, then uses our repo to set up the tests, run the tests, generate and save reports, errors, and screenshots, and clean up the tests.
We have our own docassemble package in our repo to test our own end-to-end tests. Most of what the package needs is in ./docassemble
. That docassemble package is what the test setup pulls into the docassemble server. Our internal end-to-end cucumber tests are .feature
files that are stored in ./docassemble/ALKilnTests/data/sources
. The interview (online form) .yml
files that those .feature
files use are also deep in the ./docassemble
package. You probably won't be touching the interview files. If you get curious, feel free to ask us.
There are other files the docassemble package needs, like ./setup.py
, so if you see them around, don't worry about them.
Our unit tests are in ./tests/unit_tests
and their filenames end in .test.js
. Like the cucumber tests, they use chai for assertions. The fixtures for the tests are also contained in that folder and end in .fixtures.js
.
If you want to know the commands, you can go to the instructions for running tests.
index.js
and world.js
are short files that cucumber needs.
[1] To be clear, our framework is a misuse of cucumberjs. cucumberjs is geared towards behavior driven development. We try to make BDD available to our developers, but it's not always possible and not necessarily our goal.