|
| 1 | +--- |
| 2 | +id: contributing |
| 3 | +title: Contributing |
| 4 | +--- |
| 5 | + |
| 6 | +When contributing to this repository, please first discuss the change you wish to make via [`ts-jest` GitHub discussion](https://github.com/kulshekhar/ts-jest/discussions) or [issue](https://github.com/kulshekhar/ts-jest/issues) with the owners of this repository before making a change. |
| 7 | + |
| 8 | +Please note we have a code of conduct, please follow it in all your interactions with the project. |
| 9 | + |
| 10 | +## Pull Request Process |
| 11 | + |
| 12 | +1. Ensure the tests are passing and that you have latest `main` branch merged in. |
| 13 | +2. Update the `docs/` with details of your changes if required. |
| 14 | +3. If possible, squash your commits. There must be only one commit in your PR (until a review). Then after each review requesting changes, DO NOT squash your commits with the one before the review, so that we can see intermediate modifications. |
| 15 | +4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you. |
| 16 | + |
| 17 | +_These are internal technical documents. If you're not a contributor to `ts-jest`, but simply trying to use the library you'll find nothing of value here_ |
| 18 | + |
| 19 | +## E2E Testing |
| 20 | + |
| 21 | +### Preparing |
| 22 | + |
| 23 | +The preparation of E2E test directory is done in `scripts/e2e.js`. Here is the process: |
| 24 | + |
| 25 | +```plantuml |
| 26 | +start |
| 27 | +
|
| 28 | +:bundle ts-jest; |
| 29 | +note right |
| 30 | +will build ts-jest before creating the bundle |
| 31 | +end note |
| 32 | +
|
| 33 | +:create temp work dir; |
| 34 | +note right |
| 35 | +`e2e/~__workdir_symlink__` links to it |
| 36 | +except on CI environments |
| 37 | +end note |
| 38 | +
|
| 39 | +while (for each template) |
| 40 | +note right |
| 41 | +templates are in `e2e/~__templates__/` |
| 42 | +end note |
| 43 | +
|
| 44 | +if (template's build directory) then (exists) |
| 45 | +:wipe but `node_modules` dir; |
| 46 | +else (not exists) |
| 47 | +:create; |
| 48 | +endif |
| 49 | +
|
| 50 | +:copy files from template's dir to its build dir; |
| 51 | +
|
| 52 | +if (package lock file) then (exists) |
| 53 | +:read metadata; |
| 54 | +
|
| 55 | + if (package lock file) then (has changed) |
| 56 | + :remove `node_modules` dir; |
| 57 | +
|
| 58 | + :npm install (or ci); |
| 59 | +
|
| 60 | + :npm install ts-jest bundle; |
| 61 | +
|
| 62 | + else if (ts-jest bundle) then (has changed) |
| 63 | + :npm install ts-jest bundle; |
| 64 | +
|
| 65 | + else (hasn't changed) |
| 66 | + endif |
| 67 | + :write updated metadata; |
| 68 | +
|
| 69 | +else (not exists) |
| 70 | +endif |
| 71 | +
|
| 72 | +endwhile (done) |
| 73 | +
|
| 74 | +:all templates ready; |
| 75 | +
|
| 76 | +stop |
| 77 | +``` |
| 78 | + |
| 79 | +### Running |
| 80 | + |
| 81 | +When a test-case needs to be run with a given template within tests, here is what's happening (in `e2e/__helpers__/test-case/runtime.ts`): |
| 82 | + |
| 83 | +```plantuml |
| 84 | +start |
| 85 | +
|
| 86 | +:create work dir; |
| 87 | +note right |
| 88 | +It'll be different per test-case |
| 89 | +and per template basis. |
| 90 | +end note |
| 91 | +-> e2e/~__workdir_symlink__/{template}/{test-case}; |
| 92 | +
|
| 93 | +if (has a node_modules dir?) then (yes) |
| 94 | +:symlink node_modules; |
| 95 | +note left |
| 96 | +avoid re-running npm install |
| 97 | +for each test case and template; |
| 98 | +end note |
| 99 | +else (no) |
| 100 | +endif |
| 101 | +
|
| 102 | +:copy files from template; |
| 103 | +note right |
| 104 | +all files in template dir are |
| 105 | +copied to test case work dir |
| 106 | +except `node_modules` and |
| 107 | +`package-lock.json` |
| 108 | +end note |
| 109 | +
|
| 110 | +while (for each file in test case dir) |
| 111 | +if (is snapshot dir) then (yes) |
| 112 | +:symlink dir; |
| 113 | +note left |
| 114 | +snapshots directories are symlinked |
| 115 | +to test case source dir so that |
| 116 | +updating them would update in the |
| 117 | +source folder |
| 118 | +end note |
| 119 | +
|
| 120 | +else if (is jest.config.js) then (yes) |
| 121 | +if (jest.config.js is function?) then (yes) |
| 122 | +:call with parent content; |
| 123 | +note left |
| 124 | +allows for |
| 125 | +extending |
| 126 | +end note |
| 127 | +else (no) |
| 128 | +endif |
| 129 | +
|
| 130 | +else (others) |
| 131 | +:copy; |
| 132 | +note right |
| 133 | +all files in test case source |
| 134 | +dir are copied to the work dir |
| 135 | +except `node_modules` and |
| 136 | +`package-lock.json` |
| 137 | +end note |
| 138 | +
|
| 139 | +endif |
| 140 | +endwhile |
| 141 | +
|
| 142 | +:create special files; |
| 143 | +note right |
| 144 | +some special files are created |
| 145 | +to handle hooks for example and |
| 146 | +grab `process()` IO for later |
| 147 | +expectations |
| 148 | +end note |
| 149 | +
|
| 150 | +:update package.json; |
| 151 | +note right |
| 152 | +set a custom but fixed name |
| 153 | +and version in package.json |
| 154 | +which is specific to the |
| 155 | +test case + template |
| 156 | +end note |
| 157 | +
|
| 158 | +#tomato:run tests; |
| 159 | +
|
| 160 | +while (for each snapshot) is (missing in test case) |
| 161 | +:copy; |
| 162 | +note right |
| 163 | +while we symlinked each snapshots |
| 164 | +directory, newly created snapshots |
| 165 | +in non existing dir will need to |
| 166 | +be copied over into |
| 167 | +e2e/~__cases__/{test-case} |
| 168 | +end note |
| 169 | +endwhile |
| 170 | +
|
| 171 | +:return results; |
| 172 | +
|
| 173 | +stop |
| 174 | +``` |
0 commit comments