Skip to content

Commit eafe052

Browse files
authored
build: Add Dockerfile for easily updating snapshots (#1071)
- Updated README to include new instructions on how to update snapshots - Add snapshots for mac that weren't previously included - Tested on M1 MacBook Pro - Fixes #960
1 parent e15c125 commit eafe052

File tree

32 files changed

+165
-69
lines changed

32 files changed

+165
-69
lines changed

.dockerignore

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Just copy the .gitignore file for files we don't want to copy to the docker image
2+
3+
# dependencies
4+
/node_modules
5+
6+
# testing
7+
/coverage
8+
9+
# production
10+
/build
11+
/dist
12+
13+
# misc
14+
.vscode/*
15+
!.vscode/settings.json
16+
!.vscode/tasks.json
17+
!.vscode/launch.json
18+
!.vscode/extensions.json
19+
!.vscode/*.code-snippets
20+
.DS_Store
21+
.env.local
22+
.env.development.local
23+
.env.test.local
24+
.env.production.local
25+
.project
26+
.settings/
27+
.eslintcache
28+
.stylelintcache
29+
lerna-debug.log
30+
Lerna-Profile-*.json
31+
32+
/public/vs
33+
34+
npm-debug.log*
35+
yarn-debug.log*
36+
yarn-error.log*
37+
38+
src/**/*.css
39+
40+
tsconfig.tsbuildinfo
41+
packages/*/package-lock.json
42+
/test-results/
43+
/playwright-report/
44+
/playwright/.cache/
45+
46+
# Ignore Dockerfile as well, since we don't need to copy that into the snapshot container
47+
Dockerfile
48+
49+
# Tests are copied to the docker container, as it modifies them
50+
/tests

README.md

+2-41
Original file line numberDiff line numberDiff line change
@@ -114,45 +114,6 @@ npx source-map-explorer 'packages/code-studio/build/static/js/*.js'
114114

115115
## Updating Snapshots
116116

117-
Snapshots are used by end-to-end tests to visually verify the output. Sometimes changes are made requiring snapshots to be updated. Since snapshots are platform dependent, you may need to use a docker image to [update snapshots for CI](https://playwright.dev/docs/test-snapshots). You mount the current directory into a docker image and re-run the tests from there.
117+
Snapshots are used by end-to-end tests to visually verify the output. Sometimes changes are made requiring snapshots to be updated. Run snapshots locally to update first, by running `npm run e2e:update-snapshots`.
118118

119-
First start with a clean repo. `node_modules` and some other build output is platform dependent.
120-
121-
```
122-
npm run clean
123-
```
124-
125-
Next, start the docker image and open a bash shell inside of it:
126-
127-
```
128-
docker run --rm --network host -v $(pwd):/work/ -w /work/ -it mcr.microsoft.com/playwright:v1.28.1-focal /bin/bash
129-
```
130-
131-
Within the docker image shell, install some build tools that are not included with the image:
132-
133-
```
134-
apt-get update
135-
apt-get install build-essential --yes
136-
```
137-
138-
Next, use nvm to install and use the correct version of node:
139-
140-
```
141-
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash
142-
export NVM_DIR="$HOME/.nvm"
143-
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
144-
nvm install
145-
```
146-
147-
Install npm dependencies and build the production app, pointing to an API running on your machine:
148-
149-
```
150-
npm ci
151-
VITE_CORE_API_URL=http://host.docker.internal:10000/jsapi npm run build
152-
```
153-
154-
Next, run the tests and update the snapshots:
155-
156-
```
157-
npm run e2e:update-snapshots
158-
```
119+
Once you are satisfied with the snapshots and everything is passing locally, you need to use a docker image to [update snapshots for CI](https://playwright.dev/docs/test-snapshots) (unless you are running the same platform as CI (Ubuntu)). Run `npm run e2e:update-ci-snapshots` to mount the current directory into a docker image and re-run the tests from there. **Note:** You must have [Docker installed](https://docs.docker.com/get-docker/), and `deephaven-core` must already be running on port 10000 on your local machine.

package-lock.json

+24-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"npm": ">=8"
1111
},
1212
"scripts": {
13-
"postinstall": "run-s build:necessary",
13+
"postinstall": "node ./skip.js || run-s build:necessary",
1414
"clean:build": "rimraf packages/*/dist packages/*/build",
1515
"postclean:build": "npm run clean:types",
1616
"clean:cache": "run-s clean:cache:*",
@@ -49,7 +49,8 @@
4949
"e2e:codegen": "playwright codegen http://localhost:4000",
5050
"e2e:headed": "playwright test --project=chromium --headed --debug",
5151
"e2e:update-snapshots": "playwright test --update-snapshots",
52-
"version-bump": "lerna version --conventional-commits --create-release github"
52+
"version-bump": "lerna version --conventional-commits --create-release github",
53+
"e2e:update-ci-snapshots": "docker build --tag web-client-ui-ci-snapshots --file ./tests/update-ci-snapshots/Dockerfile . && docker run --rm --network host --volume $(pwd)/tests:/work/tests/ web-client-ui-ci-snapshots npm run e2e:update-snapshots -- --config=playwright-ci.config.ts"
5354
},
5455
"repository": "https://github.com/deephaven/web-client-ui",
5556
"devDependencies": {
@@ -67,7 +68,7 @@
6768
"@deephaven/stylelint-config": "file:../stylelint-config",
6869
"@deephaven/tsconfig": "file:../tsconfig",
6970
"@fortawesome/fontawesome-common-types": "^6.1.1",
70-
"@playwright/test": "^1.28.1",
71+
"@playwright/test": "^1.30.0",
7172
"@testing-library/jest-dom": "^5.16.4",
7273
"@testing-library/react": "^12.1.3",
7374
"@testing-library/user-event": "^14.4.3",
@@ -119,7 +120,7 @@
119120
"karma-jasmine": "~0.1.5",
120121
"lerna": "^6.4.1",
121122
"npm-run-all": "^4.1.5",
122-
"playwright": "^1.28.1",
123+
"playwright": "^1.30.0",
123124
"prettier": "2.2.1",
124125
"react": "^17.0.2",
125126
"react-dom": "^17.0.2",

playwright-ci.config.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import DefaultConfig from './playwright.config';
2+
3+
const config: PlaywrightTestConfig = {
4+
...DefaultConfig,
5+
snapshotDir: '/tests',
6+
};
7+
8+
export default config;

skip.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Script will skip the postinstall script if `SKIP_POSTINSTALL` env variable is set
2+
if (process.env.SKIP_POSTINSTALL) {
3+
process.exit(0);
4+
} else {
5+
process.exit(1);
6+
}
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

tests/update-ci-snapshots/Dockerfile

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# syntax=docker/dockerfile:1
2+
# Dockerfile for updating the snapshots.
3+
# Expects to be run with `web-client-ui` root dir mounted in the `/work/` directory, and with the `--network host` flag
4+
FROM mcr.microsoft.com/playwright:v1.30.0-focal
5+
WORKDIR /work/
6+
7+
# Update packages list and install some build tools
8+
RUN set -eux; \
9+
apt-get update; \
10+
apt-get install build-essential --yes;
11+
12+
# Copy just the .nvmrc first and install nvm/node/npm first as these will change the least often
13+
# https://docs.docker.com/build/cache/
14+
COPY .nvmrc .
15+
16+
# Set the default shell so the correct node/npm is used after install
17+
# https://stackoverflow.com/a/60137919
18+
SHELL ["/bin/bash", "--login", "-i", "-c"]
19+
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
20+
RUN source /root/.bashrc && nvm install
21+
SHELL ["/bin/bash", "--login", "-c"]
22+
23+
# Next copy just the package.json and package-lock.json files over so we can install dependencies and cache at this layer
24+
# Doesn't seem to be an easy way to copy it with a glob and retain the directory structure.
25+
# Will need to add new packages here when they are created.
26+
# https://stackoverflow.com/questions/49939960/docker-copy-files-using-glob-pattern#comment106088784_49940132
27+
COPY package.json package-lock.json skip.js .
28+
COPY packages/babel-preset/package.json packages/babel-preset/
29+
COPY packages/chart/package.json packages/chart/
30+
COPY packages/embed-chart/package.json packages/embed-chart/
31+
COPY packages/embed-grid/package.json packages/embed-grid/
32+
COPY packages/filters/package.json packages/filters/
33+
COPY packages/golden-layout/package.json packages/golden-layout/
34+
COPY packages/mocks/package.json packages/mocks/
35+
COPY packages/prettier-config/package.json packages/prettier-config/
36+
COPY packages/react-hooks/package.json packages/react-hooks/
37+
COPY packages/tsconfig/package.json packages/tsconfig/
38+
COPY packages/utils/package.json packages/utils/
39+
COPY packages/storage/package.json packages/storage/
40+
COPY packages/dashboard/package.json packages/dashboard/
41+
COPY packages/stylelint-config/package.json packages/stylelint-config/
42+
COPY packages/components/package.json packages/components/
43+
COPY packages/dashboard-core-plugins/package.json packages/dashboard-core-plugins/
44+
COPY packages/eslint-config/package.json packages/eslint-config/
45+
COPY packages/jsapi-shim/package.json packages/jsapi-shim/
46+
COPY packages/iris-grid/package.json packages/iris-grid/
47+
COPY packages/icons/package.json packages/icons/
48+
COPY packages/log/package.json packages/log/
49+
COPY packages/pouch-storage/package.json packages/pouch-storage/
50+
COPY packages/file-explorer/package.json packages/file-explorer/
51+
COPY packages/redux/package.json packages/redux/
52+
COPY packages/jsapi-components/package.json packages/jsapi-components/
53+
COPY packages/code-studio/package.json packages/code-studio/
54+
COPY packages/jsapi-utils/package.json packages/jsapi-utils/
55+
COPY packages/console/package.json packages/console/
56+
COPY packages/grid/package.json packages/grid/
57+
58+
# Disable the postinstall script, or npm ci will try and build and the files won't be there
59+
# We don't need the postinstall since we're going to rebuild right after
60+
# RUN npm pkg set scripts.postinstall="echo no-postinstall"
61+
RUN SKIP_POSTINSTALL=1 npm ci
62+
63+
# Copy the web-client-ui src folder to the docker image
64+
# We do this last because the source files are the most likely to change
65+
# This requires the Dockerfile to be built in the context of the root of the web-client-ui repository
66+
# https://stackoverflow.com/a/34300129
67+
COPY . .
68+
69+
# Now build the app. We only need the code-studio built for e2e tests.
70+
RUN VITE_CORE_API_URL=http://host.docker.internal:10000/jsapi npm run build:app

0 commit comments

Comments
 (0)