Please as a first start, tell the community about your intent to develop a feature or fix a bug. Search for the associated issue if it exists or open one with steps to reproduce (for bugs) or a user story (for features).
To setup your environment, you would need to install the following dependencies:
- git
- nvm (recommended) or nodejs installed on your system
- Chromium to run the end-to-end tests
- Python (preferably Python 3.11, minimum 3.9) and virtualenv
$ git clone https://github.com/gristlabs/grist-coreAnd then, enter the grist-core root directory:
$ cd grist-core/You need to install the supported nodejs version as well as yarn. To do so, in the grist-core root directory, run the following command to install nodejs via nvm:
$ nvm installNow check that node is installed in the version specified in the .nvmrc file:
$ node --versionThen install yarn (the -g flag here means that yarn will be available globally):
$ npm install -g yarnNow each time you want to load nodejs and yarn in your environment, just run the following command at grist-core root directory:
$ nvm useYou can also use nodejs installed in your system. To prevent incompatibilities, ensure that the node --version command reports a version equal or greater to the one in .nvmrc.
Be sure to have Python and virtualenv installed. On debian-based Linux distributions, you can simply run the following command as root:
# apt install python3.11 python3.11-venvFirst install the nodejs dependencies:
$ yarn installThen prepare the virtual environment with all the python dependencies:
$ yarn install:pythonFinally run this to do an initial build:
$ yarn run buildJust run the following command:
$ yarn startEach time you change something, just reload the webpage in your browser.
Happy coding!
Lost on what you can do to help? If you are new to Grist, you may just pick one of the issues labelled good first issue:
https://github.com/gristlabs/grist-core/labels/good%20first%20issue
You can debug the NodeJS application using this command:
$ yarn start:debugAnd start using your nodejs debugger client (like the Chrome Devtools). See https://nodejs.org/en/docs/guides/debugging-getting-started#inspector-clients
The coding rules are enforced by the Eslint tool. You can run it using the
yarn lint command and you may run yarn lint:fix to make eslint try to
fix them for you (most of them can be fixed this way).
You may run the tests using one of these commands:
yarn testto run all the testsyarn test:debugto run the tests in debug mode, which will stop after first failure, not clean up after tests and will provide more detailed output (with screenshots) in the_build/test_outputdirectoryyarn test:smoketo run the minimal test checking Grist can open, create and edit a documentyarn test:nbrowserto run the end-to-end tests (⚠️ see warning below)yarn test:nbrowser:cito run the end-to-end tests in headless mode, suitable for continuous integration environmentsyarn test:nbrowser:debugto run the end-to-end tests in debug modeyarn test:clientto run the tests for the client librariesyarn test:commonto run the tests for the common libraries shared between the client and the serveryarn test:serverandyarn test:gen-serverto run the backend tests depending on where the feature you would like to test resides (respectivelyapp/serverorapp/gen-server)yarn test:dockerto run some end-to-end tests under dockeryarn test:pythonto run the data engine testsyarn test:stubsto run the end-to-end tests with stubs, which are simplified versions of the tests for faster execution
Also some options that may interest you, especially in order to troubleshoot:
GREP_TESTS="pattern"in order to filter the tests to run, for example:GREP_TESTS="Boot" yarn test:nbrowserVERBOSE=1in order to view logs when a server is spawned (especially useful to debug the end-to-end and backend tests)SERVER_NODE_OPTIONS="node options"in order to pass options to the server being tested, for example:SERVER_NODE_OPTIONS="--inspect --inspect-brk" GREP_TESTS="Boot" yarn test:nbrowserto run the tests with the debugger (you should close the debugger each time the node process should stop)MOCHA_WEBDRIVER_HEADLESS=1to run the end-to-end tests in headless mode, meaning a browser window won't be openedNO_CLEANUP=1to not restart/clean state after test ends, used withDEBUG=1DEBUG=1to keep the server running after the tests are done and to provide more detailed outputMOCHA_WEBDRIVER_LOGDIR=/tmp/grist-teststo specify the directory where the logs of the end-to-end tests will be stored (together with screenshots of the browser at the time of failure)TYPEORM_DATABASE=/path/to/test-database.sqlite(adapt the path to wherever you want the file to be created) in order to debug tests that work with a database. You may then inspect the database using thesqlite3command.TYPEORM_LOGGING=trueto print every SQL commands during the tests
End-to-end tests work by simulating user mouse clicks and keyboard inputs in an actual chrome browser. By default, running yarn test:nbrowser opens a new browser window where automated "user" interactions happen.
You can use the MOCHA_WEBDRIVER_HEADLESS env var to start the tests in headless mode, meaning a browser window won't be opened:
MOCHA_WEBDRIVER_HEADLESS=1 yarn run test:nbrowser
Running in headless mode allows you to run the tests in background, without the risk of automated tests catching window focus while you are doing something else.
Running in normal mode helps you understand better what happens when writing or debugging tests.
When you discover flakiness on the CI, these options are offered to you (which are non-exclusive):
- Run tests 20 times and stop at the first error:
# Example below for nbrowser tests
for i in {1..20}; do GREP_TESTS="^yourTestSuiteHere\b" yarn test:nbrowser:ci -- -- --bail || break; echo "✅ Step $i 🎉"; done- NB: You can also change the code to add a for-loop around a
describe()section in tests, that's recommended forprojectstests due to the build of the webpack assets
- Download the assets, check the snapshots when the errors occurred
- On Linux: Use systemd-run on Linux to make nodejs and the browser run slower
# Example below for projects tests
# You can adapt the value for --cpu-limit
for i in {1..20}; do GREP_TESTS="^yourTestSuiteHere\b" systemd-run --scope -p CPUQuota=50% --user yarn run test:nbrowser:ci -- -- --bail || break; echo "✅ Step $i 🎉"; doneEnd-to-end tests are run in the GitHub CI with a specific Chrome version that is known to run the tests smoothly.
If you don't have any tests randomly failing while running them locally: great! You can move on.
Otherwise, you should make sure that the local test suite uses Chrome v132 or Chrome v133, and not a Chrome for Testing variant.
In order to do that, you can use an env var to let the script know about a specific chrome binary to use. For example, if your Chrome (v132 or 133) path is /usr/bin/google-chrome:
TEST_CHROME_BINARY_PATH="/usr/bin/google-chrome" yarn run test:nbrowser
You might already have Chrome v134+ installed and feel stuck!
One solution is to build yourself a docker container matching what the GitHub actions does. Meaning, with node, python etc, an integrated Chrome v133 binary, and run tests inside that container.
Another solution on Linux, is to just install an old Chrome version on your system directly.
A simple trick is to install an old Chrome Beta binary, in order to not mess with your current Chrome install.
You can do the same as the buildtools/install_chrome_for_tests.sh script, but target an old version of Chrome Beta like this:
curl -sS -o /tmp/chrome.deb http://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-beta/google-chrome-beta_133.0.6943.35-1_amd64.deb \
&& sudo apt-get install --allow-downgrades -y /tmp/chrome.deb \
&& rm /tmp/chrome.deb \Open google-chrome-beta one time manually to confirm any first-loads modals that would prevent tests to run correctly.
Then run tests with:
SE_BROWSER_VERSION=133.0.6943.35 \
SE_DRIVER_VERSION=133.0.6943.141 \
TEST_CHROME_BINARY_PATH="/usr/bin/google-chrome-beta" \
yarn run test:nbrowser
Download the google-chrome-beta aur tarball matching the needed version and manually install it:
- download and extract this aur tarball (matching Chrome Beta v133)
cdin the extracted directory andmakepkg -si.
Open google-chrome-beta one time manually to confirm any first-loads modals that would prevent tests to run correctly.
Then run tests with:
SE_BROWSER_VERSION=133.0.6943.35 \
SE_DRIVER_VERSION=133.0.6943.141 \
TEST_CHROME_BINARY_PATH="/usr/bin/google-chrome-beta" \
yarn run test:nbrowser
Unfortunately there is no easy way in macOS to pin Chrome version without it auto-updating. If you absolutely need to run tests locally for now:
- create a docker image matching the GitHub CI environment in order to run the tests inside a Linux environment having a pinned Chrome version
- or… help us fix the tests (sorry)!
Note that tests are always run against pull requests and you can also rely on the GitHub CI instead.
Check out this repository: https://github.com/gristlabs/grist-widget#readme
Some documentation to help you starting developing:
- Overview of Grist Components
- The database
- GrainJS & Grist Front-End Libraries
- GrainJS Documentation (The library used to build the DOM)
- The user support documentation