You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -88,7 +88,24 @@ Since we have already written a pure evaluation script that runs and finally wri
88
88
The full path of the script is made available at run-time with another environment variable called `TEST_FILE_NAME`. Therefore, all we have to do is write the following in the evaluation script area:
yarn vitest run --config=/home/damner/code/__labtests/config.js --threads=false --reporter=json --outputFile=/home/damner/code/__labtests/payload.json ||true
136
+
yarn vitest run --config=/home/damner/code/.labtests/config.js --threads=false --reporter=json --outputFile=/home/damner/code/.labtests/payload.json ||true
137
137
138
138
139
139
# Write results to UNIT_TEST_OUTPUT_FILE to communicate to frontend
140
-
node /home/damner/code/__labtests/process.js
140
+
node /home/damner/code/.labtests/process.js
141
141
```
142
142
143
143
Let's understand what the above evaluation script is doing:
144
144
145
145
- We navigate to users' default code directory and install `vitest` and `vite`. We do this because we'll use `vitest` as the test runner.
146
-
- We then move the cloned test file (more on this in the next step) inside `__labtests` folder. This folder is hidden from the user in the GUI while test is running.
146
+
- We then move the cloned test file (more on this in the next step) inside `.labtests` folder. This folder is hidden from the user in the GUI while test is running.
147
147
- We create a custom configuration for vite which would be read by vitest for testing.
148
148
- We then create a `process.js` file that would read the results written by vitest and process them to write them on a file inside `$UNIT_TEST_OUTPUT_FILE` environment variable. This is important because this file is read by the playground to evaluate whether the challenges passed or failed.
149
149
- Whatever your mapping of final JSON boolean array written in `process.env.UNIT_TEST_OUTPUT_FILE` is, it is matched exactly to the results on the playground. For example, if the array written is `[true, false, true, true]`, the following would be the output on playground:
You might need to have a little understanding of bash scripting. Let us understand how the evaluation bash script is working:
152
152
153
153
- With `set -e 1` we effectively say that the script should stop on any errors
154
154
- You can install additional packages here if you want. They would only be installed the first time user runs the test. On subsequent runs, it can reuse the installed packages (since they are not removed at the end of testing)
155
-
- Then we create a `__labtests` folder inside of the `/home/damner/code` user code directory. Note that `__labtests` is a special folder that can be used to place your test code. This folder will not be visible in the file explorer user sees, and the files placed in this folder are not "backed up to cloud" for user.
156
-
- We move the test file you wrote earlier (in last step) to `/home/damner/code/__labtests/pytest.py`.
157
-
- We then create another setup file `/home/damner/code/__labtests/processPythonResults.js`. This is because we need to parse the results outputted by the Python testing utility to reflect it on the playgrounds. You may as well create this file in python (reading the JSON report and outputting a boolean array in a file stored in env `$UNIT_TEST_OUTPUT_FILE`)
155
+
- Then we create a `.labtests` folder inside of the `/home/damner/code` user code directory. Note that `.labtests` is a special folder that can be used to place your test code. This folder will not be visible in the file explorer user sees, and the files placed in this folder are not "backed up to cloud" for user.
156
+
- We move the test file you wrote earlier (in last step) to `/home/damner/code/.labtests/pytest.py`.
157
+
- We then create another setup file `/home/damner/code/.labtests/processPythonResults.js`. This is because we need to parse the results outputted by the Python testing utility to reflect it on the playgrounds. You may as well create this file in python (reading the JSON report and outputting a boolean array in a file stored in env `$UNIT_TEST_OUTPUT_FILE`)
158
158
- This is important because on the playground page, the way challenges work, is that they get green or red based on a JSON boolean array written inside the file in environment variable: `$UNIT_TEST_OUTPUT_FILE`
159
159
- For example, once the test run succeeds, and if you write `[true,false,true,true]` inside `$UNIT_TEST_OUTPUT_FILE`, it would reflect as PASS, FAIL, PASS for 3 challenges available inside codedamn playground UI (as shown below)
yarn vitest run --config=/home/damner/code/__labtests/config.js --threads=false --reporter=json --outputFile=/home/damner/code/__labtests/payload.json ||true
193
+
yarn vitest run --config=/home/damner/code/.labtests/config.js --threads=false --reporter=json --outputFile=/home/damner/code/.labtests/payload.json ||true
194
194
195
195
# Write results to UNIT_TEST_OUTPUT_FILE to communicate to frontend
196
-
node /home/damner/code/__labtests/process.js
196
+
node /home/damner/code/.labtests/process.js
197
197
```
198
198
199
199
You might need to have a little understanding of bash scripting. Let us understand how the evaluation bash script is working:
200
200
201
201
- With `set -e 1` we effectively say that the script should stop on any errors
202
202
- We then navigate to user default directory `/home/damner/code` and then install the required NPM packages. Note that this assumes we already have `vite` installed. If you're using a different react setup (like `create-react-app`), you might have to install `vite` as well.
203
203
- You can install additional packages here if you want. They would only be installed the first time user runs the test. On subsequent runs, it can reuse the installed packages (since they are not removed at the end of testing)
204
-
- Then we create a `__labtests` folder inside of the `/home/damner/code` user code directory. Note that `__labtests` is a special folder that can be used to place your test code. This folder will not be visible in the file explorer user sees, and the files placed in this folder are not "backed up to cloud" for user.
205
-
- We move the test file you wrote earlier (in last step) to `/home/damner/code/__labtests/reactcheck.test.jsx`. Note that it is important to give it an extension of `.test.jsx` for vitest to pick it as a JSX test file.
206
-
- We then create another setup file `/home/damner/code/__labtests/setup.js` with just `jsdom` as the import. This is because vitest can then use JSDOM to parse the DOM without browser. More information about this [setup file can be found in vitest docs here](https://vitest.dev/config/#setupfiles).
204
+
- Then we create a `.labtests` folder inside of the `/home/damner/code` user code directory. Note that `.labtests` is a special folder that can be used to place your test code. This folder will not be visible in the file explorer user sees, and the files placed in this folder are not "backed up to cloud" for user.
205
+
- We move the test file you wrote earlier (in last step) to `/home/damner/code/.labtests/reactcheck.test.jsx`. Note that it is important to give it an extension of `.test.jsx` for vitest to pick it as a JSX test file.
206
+
- We then create another setup file `/home/damner/code/.labtests/setup.js` with just `jsdom` as the import. This is because vitest can then use JSDOM to parse the DOM without browser. More information about this [setup file can be found in vitest docs here](https://vitest.dev/config/#setupfiles).
207
207
- We then also create a custom vite config file as `config.js`. This is because we don't want to override your (or users') custom `vite.config.js` file if present. This file only loads `jsdom` and marks the `globals: true` hence importing `describe`, `test`, etc. automatically available without importing. More information about the configuration can be found here in [vitest docs](https://vitest.dev/config/#globals).
208
208
- We then create a `process.js` file that can be used to process our results into a single file of boolean values. This is important because on the playground page, the way challenges work, is that they get green or red based on a JSON boolean array written inside the file in environment variable: `$UNIT_TEST_OUTPUT_FILE`
209
209
- For example, once the test run succeeds, and if you write `[true,false,true,true]` inside `$UNIT_TEST_OUTPUT_FILE`, it would reflect as PASS, FAIL, PASS for 3 challenges available inside codedamn playground UI (as shown below)
0 commit comments