-
Notifications
You must be signed in to change notification settings - Fork 603
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add e2e test * feat: 升级到 G2 正式版 * feat: add tests base url * fix: web server command * chore: update snapshots for release version * feat: ChatGPT cr
- Loading branch information
Showing
74 changed files
with
250 additions
and
5,906 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Code Review | ||
|
||
permissions: | ||
contents: read | ||
pull-requests: write | ||
|
||
on: | ||
pull_request: | ||
types: [opened, reopened, synchronize] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: anc95/ChatGPT-CodeReview@main | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | ||
# Optional | ||
LANGUAGE: Chinese | ||
MODEL: | ||
top_p: 1 | ||
temperature: 1 |
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,27 @@ | ||
name: Playwright Tests | ||
on: | ||
push: | ||
branches: [ main, master ] | ||
pull_request: | ||
branches: [ main, master ] | ||
jobs: | ||
test: | ||
timeout-minutes: 60 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16 | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Install Playwright Browsers | ||
run: npx playwright install --with-deps | ||
- name: Run Playwright tests | ||
run: npx playwright test | ||
- uses: actions/upload-artifact@v3 | ||
if: always() | ||
with: | ||
name: playwright-report | ||
path: playwright-report/ | ||
retention-days: 30 |
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 |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
|
||
npm run lint-staged | ||
npm run lint | ||
# npm run test |
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,4 +1,5 @@ | ||
auto-install-peers=true | ||
strict-peer-dependencies=false | ||
scripts-prepend-node-path=true | ||
public-hoist-pattern[]=@antv/* | ||
public-hoist-pattern[]=d3-* |
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
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Diff not rendered.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# e2e snapshots dir | ||
SNAPSHOTS_DIR=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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import path from 'path'; | ||
import { test, expect } from '@playwright/test'; | ||
import { createDiff, getSnapshotName, toHump, sleep } from '../utils'; | ||
|
||
const IMG_DIR = path.resolve(__dirname, '..', process.env.SNAPSHOTS_DIR as string); | ||
|
||
const files = getSnapshotName(); | ||
|
||
test.afterAll(() => { | ||
createDiff(); | ||
}); | ||
|
||
test('Plot snapshots', async ({ page }) => { | ||
for (const filename of files) { | ||
const [name] = filename.split('.'); | ||
await page.goto(`/?name=${toHump(name)}`); | ||
await sleep(1000); | ||
await page.locator('.container').screenshot({ path: `${IMG_DIR}/${name}.png` }); | ||
} | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { createDiff } from './create-diff'; | ||
export { getSnapshotName } from './get-snapshot-name'; | ||
export { toHump } from './to-hump'; | ||
export { sleep } from './sleep'; |
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,58 @@ | ||
import * as fs from 'fs'; | ||
import path from 'path'; | ||
import { PNG } from 'pngjs'; | ||
import pixelmatch from 'pixelmatch'; | ||
|
||
const STABLE = 'stable'; | ||
|
||
const DIFF = 'diff'; | ||
|
||
const maxError = 0; | ||
|
||
const IMG_DIR = path.resolve(__dirname, `../${process.env.SNAPSHOTS_DIR}`); | ||
|
||
export const createDiff = async () => { | ||
const files = fs.readdirSync(IMG_DIR); | ||
files.forEach((filename) => { | ||
if (filename.endsWith(`${STABLE}.png`) || filename.endsWith(`${DIFF}.png`)) return; | ||
diffFile(IMG_DIR, filename); | ||
}); | ||
}; | ||
|
||
/** | ||
* diff between PNGs | ||
*/ | ||
const diffFile = (filePath: string, filename: string) => { | ||
const [name, type] = filename.split('.'); | ||
// 当前截图生成的图片 | ||
const testSnapshotFile = `${filePath}/${filename}`; | ||
// 用于下次比对的图片 | ||
const stableFile = `${filePath}/${name}-${STABLE}.${type}`; | ||
// diff 文件 | ||
const diffFile = `${filePath}/${name}-${DIFF}.${type}`; | ||
// 不存在时直接写入 | ||
if (!fs.existsSync(stableFile)) { | ||
fs.copyFileSync(testSnapshotFile, stableFile); | ||
return; | ||
} | ||
|
||
const snap = PNG.sync.read(fs.readFileSync(testSnapshotFile)); | ||
const stable = PNG.sync.read(fs.readFileSync(stableFile)); | ||
const { width, height } = snap; | ||
|
||
const diff = new PNG({ width, height }); | ||
|
||
// @see https://github.com/mapbox/pixelmatch#pixelmatchimg1-img2-output-width-height-options | ||
const mismatch = pixelmatch(snap.data, stable.data, diff.data, width, height, { | ||
threshold: 0.1, | ||
}); | ||
|
||
if (mismatch > maxError) { | ||
fs.writeFileSync(diffFile, PNG.sync.write(diff)); | ||
} else { | ||
try { | ||
fs.unlinkSync(diffFile); | ||
// eslint-disable-next-line no-empty | ||
} catch (err) {} | ||
} | ||
}; |
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,9 @@ | ||
import * as fs from 'fs'; | ||
import path from 'path'; | ||
|
||
const DEMO_DIR = path.resolve(__dirname, `../../__tests__/integration/plots`); | ||
|
||
export const getSnapshotName = () => { | ||
const files = fs.readdirSync(DEMO_DIR); | ||
return files.filter((filename) => filename !== 'index.ts'); | ||
}; |
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 @@ | ||
export const sleep = (n: number) => { | ||
return new Promise((resolve) => { | ||
setTimeout(resolve, n); | ||
}); | ||
}; |
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 @@ | ||
export const toHump = (name = '') => { | ||
return name.replace(/-(\w)/g, (all, letter) => { | ||
return letter.toUpperCase(); | ||
}); | ||
}; |
Oops, something went wrong.