-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: storybook test-runner visual tests (#96)
* test: add screenshot test runner * test: fix jest typing * ci: update docker compose npm scripts * test: add Dockerfile for playwright testing image * test: added storybook snapshots * test: update snapshots * ci: update github workflow * ci: install docker-compose * ci: run apt-get with sudo * test: run storybook tests with ci flag * ci: make /app dir writable in docker * ci: change working dir * ci: test as root on github * ci: add maptiler key environment variable for tests * ci: fix docker compose syntax * ci: set maptiler key on storybook container * ci: increase visual test poll interval * docs: add npm keywords * refactor: apply lint conditions * test: increase test timeout to 60 s * test: use run command for docker-compose tests * test: increase story test timeout * test: skip Hill Layer tests * test: disable GpxSatteliteTerrain story visual tests * test: disable visual tests for TripLayer * test: disable some more visual tests * test: delete stale visual test snapshots * test: update snapshots * test: disable more visual tests
- Loading branch information
Showing
40 changed files
with
417 additions
and
886 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ README.md | |
dist | ||
storybook-static | ||
package-lock.json | ||
__snapshots__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const { getJestConfig } = require("@storybook/test-runner"); | ||
|
||
// The default Jest configuration comes from @storybook/test-runner | ||
const testRunnerConfig = getJestConfig(); | ||
|
||
/** | ||
* @type {import('@jest/types').Config.InitialOptions} | ||
*/ | ||
module.exports = { | ||
...testRunnerConfig, | ||
testTimeout: 120000, | ||
maxWorkers: process.env.CI ? 4 : 8, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { toMatchImageSnapshot } from "jest-image-snapshot"; | ||
|
||
import { getStoryContext, type TestRunnerConfig } from "@storybook/test-runner"; | ||
|
||
const customSnapshotsDir = `${process.cwd()}/__snapshots__`; | ||
|
||
const screenshotTest = async (page, context) => { | ||
let previousScreenshot: Buffer = Buffer.from(""); | ||
|
||
let stable = false; | ||
|
||
const pollInterval = 20000; | ||
|
||
while (!stable) { | ||
const currentScreenshot = await page.screenshot(); | ||
if (currentScreenshot.equals(previousScreenshot)) { | ||
stable = true; | ||
} else { | ||
previousScreenshot = currentScreenshot; | ||
} | ||
|
||
if (!stable) { | ||
await page.waitForTimeout(pollInterval); | ||
} | ||
} | ||
|
||
// @ts-expect-error TS2551 | ||
expect(previousScreenshot).toMatchImageSnapshot({ | ||
customSnapshotsDir, | ||
customSnapshotIdentifier: context.id, | ||
}); | ||
}; | ||
|
||
const config: TestRunnerConfig = { | ||
setup() { | ||
jest.retryTimes(3); | ||
|
||
expect.extend({ toMatchImageSnapshot }); | ||
}, | ||
|
||
async postVisit(page, context) { | ||
const storyContext = await getStoryContext(page, context); | ||
|
||
if (storyContext.tags.includes("no-test")) { | ||
return; | ||
} | ||
|
||
if (!storyContext.tags.includes("no-visual-test")) { | ||
await screenshotTest(page, context); | ||
} | ||
}, | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FROM mcr.microsoft.com/playwright:v1.48.2-noble | ||
|
||
RUN mkdir /app | ||
WORKDIR /app | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,56 @@ | ||
version: "3" | ||
services: | ||
storybook: | ||
image: velo.gl | ||
image: velo.gl-storybook | ||
build: . | ||
environment: | ||
- MAPTILER_API_KEY | ||
volumes: | ||
- ".:/app:rw" | ||
ports: | ||
- "6006:6006" | ||
healthcheck: | ||
test: curl --fail http://localhost:6006/ | ||
command: > | ||
sh -c "npm run storybook -- --no-open" | ||
test-storybook: | ||
image: velo.gl-test-storybook | ||
build: ./config/test-storybook | ||
volumes: | ||
- ".:/app:ro" | ||
- "./__snapshots__:/app/__snapshots__:rw" | ||
working_dir: /app | ||
user: ubuntu | ||
depends_on: | ||
storybook: | ||
condition: service_healthy | ||
command: > | ||
sh -c "npm run test:storybook -- --ci --url http://storybook:6006/" | ||
test-storybook-update: | ||
image: velo.gl-test-storybook | ||
build: ./config/test-storybook | ||
volumes: | ||
- ".:/app:ro" | ||
- "./__snapshots__:/app/__snapshots__:rw" | ||
working_dir: /app | ||
user: ubuntu | ||
depends_on: | ||
storybook: | ||
condition: service_healthy | ||
command: > | ||
sh -c "npm run test:storybook -- --updateSnapshot --url http://storybook:6006/" | ||
test-storybook-github: | ||
image: velo.gl-test-storybook | ||
build: ./config/test-storybook | ||
volumes: | ||
- ".:/app:rw" | ||
working_dir: /app | ||
user: root | ||
depends_on: | ||
storybook: | ||
condition: service_healthy | ||
command: > | ||
sh -c "npm run test:storybook -- --ci --url http://storybook:6006/" |
Oops, something went wrong.