We're excited for your interest in Greenwood, and maybe even your contribution!
Please make sure to have the following prepared (where applicable)
- High Level Overview
- For bugs, please provide steps to reproduce
- Code Sample
- Links / references
Pull requests are the best! To best help facililate contributions to the project, here are some requests:
- We generally we prefer an issue be opened first, to help faciliate general discussion outside of the code review process itself and align on the ask and any expections. However, for typos in docs and minor "chore" like tasks a PR is usually sufficient. When in doubt, open an issue.
- For bugs, please consider reviewing the issue tracker.
- For branching, we generally follow the convention
<issue-label>/issue-<number>-<issue-title>
, e.g. bug/issue-12-fixed-bug-with-yada-yada-yada - To test the CI build scripts locally, run the
yarn
commands mentioned in the below section on CI.
Greenwood makes active use of testing tools like GitHub Actions and Netlify deploy previews as part of the workflow. Each time a PR is opened, a sequence of build steps defined .github/workflows/ci..yml are run:
- Linting:
yarn lint
- Running unit tests:
yarn test
- Building the Greenwood website:
yarn build
A preview is also made available within the status checks section of the PR in GitHub and can be used to validate work in a live environment before having to merge.
To develop for the project, you'll want to follow these steps:
- Have NodeJS LTS installed (>= 10.x) and Yarn
- Clone the repository
- Run
yarn install
- Run
yarn lerna bootstrap
The Greenwood website is currently built by Greenwood itself, and all files for it are located in this repository in the www/ directory. In addition to unit tests, you will want to verify all changes by running the website locally.
Below are the development tasks available for working on this project:
yarn develop
- Develop for the website locally using the dev server atlocalhost:1984
in your browser.yarn build
- Builds the website for production.yarn serve
- Builds the website for production and runs it on a local webserver atlocalhost:8000
Greenwood is organized into packages as a monorepo, managed by Lerna and Yarn Workspaces. You can find all of these in the packages/ directory. Each package will manage its own:
- Dependencies
- README
- Test Cases
Lerna (specifically lerna publish
) will be used to release all packagess under a single version. Lerna configuration can be found in lerna.json.
To yarn add
/ yarn remove
packages from anything in packages/ or www/, please make sure you cd
into the directory with the package.json first.
For example
$ cd packages/cli
$ yarn add <package>
Yarn workspaces will automatically handle installing node_modules in the appropriate directory.
TDD is the recommended approach for developing for Greenwood and for the style of test writing we use BDD style testing; "cases". Cases are used to capture the various configurations and expected outputs of Greenwood when running its commands, in a way that is closer to how a user would be expecting Greenwood to work.
To run tests in watch mode, use:
$ yarn test:tdd
To verify compliance with coverage and watermark thresholds (what CI server runs), use:
$ yarn test
Below are some tips to help with running / debugging tests:
describe.only
/it.only
: only runs this blockxdescribe
/xit
: dont run this block- Uncomment
setup.teardownTestBed()
in a case to see the build output without it getting cleaned up post test run - Use
new TestBed(true)
get debug output from Greenwood when running tests
PLEASE DO NOT COMMIT ANY OF THESE ABOVE CHANGES THOUGH
Cases follow a convention starting with the command (e.g. build
) and and the capability and features being tested, like configuration with a particular option (e.g. publicPath
):
<command>.<capability>.<feature>.spec.js
Examples:
- build.default.spec.js - Would test
greenwood build
with no config and no workspace. - build.config.workspace-custom.spec.js - Would test
greenwood build
with a config that had a customworkspace
- build.config.workspace-public-path.spec.js - Would test
greenwood build
with a config that had a customworkspace
andpublicPath
set.
Here are some thigns to keep in mind while writing your tests, due to the asynchronous nature of Greenwwood:
- Make sure to wrap all calls to
TestBed
withasync
- All usages of
JSDOM
should be wrapped inasync
- Avoid arrow functions in mocha tests (e.g.
() =>
) as this can cause unexpected behaviors.. Just usefunction
instead.
For situations that require testing Internet Explorer or Edge browser, Microsoft provides Virtual Machines for various combinations of Windows and Internet Explorer versions. VirtualBox is a good platform to use for these VMs.
To test from a VM, you can
- Run
yarn serve
- From the VM, open
http://10.0.2.2:8000
in the browser
You can disable plugins in webpack.config.prod.js to remove production optimizations for testing purposes.
A Docker container is available within the project to use as a development environment if you like. It is configured to use the same image that runs as part of the project's Continuous Integration environment.
First make sure you have Docker installed.
Then from the root of this repository do the following:
- Build the container:
$ docker build -t nodejs-dev .
- Connect to the container:
$ docker run --name greenwood -v $(pwd):/workspace -i -t nodejs-dev
- Now you can run all the usual commands, e.g.
$ yarn install
$ yarn build
$ yarn test
This will create a 2 way binding between your host and the container, so file changes will go both ways between the host and container.
When you're done with the container:
- Exit the container:
$ exit
- Destroy the container:
$ docker rm greenwood
Note: If you have issues running tests due to timeouts, you can increase the setting in package.json