Skip to content

Commit 84c23ba

Browse files
authored
Add test watching and some unit tests (#7)
* Move lint after test and to separate workflow It can be annoying to have the tests not run just because linting fails so run it after tests instead (this is to make sure devs see it since failing to lint before pushing is common). Additionally make lint a separate step when in CI since otherwise a lint failure would make it look like a test failure. * Automatically fix linting issues after running tests It turns out having to manually run this is just kind of annoying. * Add watch command for tests from the CLI * Add tests for utils Also remove an unused function bubbleError. * Add tests for workspaces * Stub out extension tests * Add a way to directly set the coder binary path * Set command for coder on Windows It is failing to find the binary in the PATH.
1 parent e4c8417 commit 84c23ba

17 files changed

+447
-42
lines changed

.github/workflows/lint.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
on:
2+
push:
3+
branches:
4+
- master
5+
pull_request:
6+
branches:
7+
- master
8+
9+
name: Lint Extension
10+
11+
jobs:
12+
lint:
13+
runs-on: ubuntu-20.04
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
18+
- uses: actions/setup-node@v2
19+
with:
20+
node-version: '16'
21+
22+
- run: npm ci
23+
24+
- run: npm run lint

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535

3636
- run: npm ci
3737

38-
- run: npm run test
38+
- run: npm run test:ci
3939
env:
4040
# This tells the application on which display it should run. Set to
4141
# the display we started on Linux via Xvfb. The other platforms do not

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"outFiles": [
2525
"${workspaceFolder}/out/**/*.test.js"
2626
],
27-
"preLaunchTask": "npm: test:watch"
27+
"preLaunchTask": "npm: tsc:watch"
2828
}
2929
]
3030
}

.vscode/tasks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
{
2121
"type": "npm",
22-
"script": "test:watch",
22+
"script": "tsc:watch",
2323
"problemMatcher": "$tsc-watch",
2424
"isBackground": true,
2525
"presentation": {

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,20 @@
1313
From here you have a few choices:
1414

1515
- Run through VS Code:
16-
- `Run Extension` task
17-
- `Extension Tests` task
18-
- Run `npm run test` from the CLI
19-
- On Linux to run headless install and run `xvfb`
20-
- Refer to CI test workflow for more details
16+
- Launch `Run Extension` through the debug panel
17+
- Launch `Extension Tests` through the debug panel
18+
- Run `npm run test` or `npm run test:watch` from the CLI
19+
- On Linux to run a headless install use `xvfb`
20+
- Refer to CI test workflow for more details about `xvfb`
2121

2222
To fix automatically fixable linting issues run:
2323

2424
```shell
2525
npm run lint -- --fix
2626
```
2727

28+
Linting will be automatically fixed when you use `npm run test` or `npm run test:watch`.
29+
2830
## Known issues
2931

3032
- Context menu action `Show Logs` is blocking, and blocks until a rebuild completes

fixtures/coder

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
# Coder CLI mock
3+
4+
need_login() {
5+
echo "fatal: failed to read session credentials"
6+
echo " | hint: did you run \"coder login [https://coder.domain.com]\"?"
7+
exit 1
8+
}
9+
10+
workspaces() {
11+
cat ./workspaces.json
12+
exit 0
13+
}
14+
15+
main() {
16+
cd "$(dirname "${0}")"
17+
18+
# Use CODER_MOCK_STATE to force certain states.
19+
case "${CODER_MOCK_STATE-}" in
20+
"need_login") need_login ;;
21+
esac
22+
23+
# Mock the output based on the passed arguments.
24+
case "$*" in
25+
"envs ls --output json") workspaces ;;
26+
*) echo "$* is not mocked" ; exit 1 ;;
27+
esac
28+
}
29+
30+
main "$@"

fixtures/workspaces.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[
2+
{
3+
"id": "workspace-id",
4+
"name": "workspace-name",
5+
"cpu_cores": 1,
6+
"memory_gb": 2,
7+
"updated": false,
8+
"image_tag": "image-tag",
9+
"image_id": "image-id",
10+
"gpus": 4,
11+
"updating": false,
12+
"latest_stat": {
13+
"container_status": "ON"
14+
},
15+
"disk_gb": 5
16+
}
17+
]

0 commit comments

Comments
 (0)