Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add e2e test #1656

Merged
merged 40 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
90b62d8
feat: add animator e2e
luzhuang Jul 20, 2023
f795a65
feat: opt code
luzhuang Jul 20, 2023
b216f0b
feat: update e2e test
luzhuang Jul 20, 2023
fce451c
feat: update e2e test
luzhuang Jul 20, 2023
78cda5e
feat: opt code
luzhuang Jul 20, 2023
d544f39
feat: update e2e test
luzhuang Jul 20, 2023
c0e1999
feat: update e2e test
luzhuang Jul 20, 2023
9bddf8a
feat: update e2e test
luzhuang Jul 20, 2023
e507e59
feat: update e2e test
luzhuang Jul 20, 2023
d03b124
feat: update e2e test
luzhuang Jul 20, 2023
d79c12f
feat: update e2e test
luzhuang Jul 20, 2023
a0e9dd8
feat: update e2e test
luzhuang Jul 20, 2023
9520f16
feat: update e2e test
luzhuang Jul 20, 2023
d5d7c9c
feat: update e2e test
luzhuang Jul 20, 2023
344e74e
feat: update e2e test
luzhuang Jul 20, 2023
7c770ea
feat: update e2e test
luzhuang Jul 20, 2023
6307249
feat: update e2e test
luzhuang Jul 20, 2023
67fbefc
feat: update e2e test
luzhuang Jul 20, 2023
5a558d7
feat: update e2e test
luzhuang Jul 20, 2023
78bff16
feat: opt code
luzhuang Jul 21, 2023
c8e4cde
feat: opt code
luzhuang Dec 20, 2023
dd88113
Merge branch main of github.com:oasis-engine/engine into feat/e2e
luzhuang Dec 20, 2023
203d3d8
feat: opt code
luzhuang Dec 20, 2023
34f8b2b
feat: opt code
luzhuang Dec 20, 2023
86dafac
feat: fix ci
luzhuang Dec 20, 2023
92f85f8
feat: fix ci
luzhuang Dec 20, 2023
292ea69
feat: update origin image
luzhuang Dec 21, 2023
bfe1a30
feat: opt code
luzhuang Dec 21, 2023
2f3c8d3
feat: opt code
luzhuang Dec 21, 2023
815bbc9
feat: opt code
luzhuang Dec 21, 2023
4ae3298
feat: opt code
luzhuang Dec 21, 2023
90cda23
feat: opt code
luzhuang Dec 21, 2023
e37e0e8
feat: opt code
luzhuang Dec 21, 2023
a0d31cc
feat: opt code
luzhuang Dec 21, 2023
00569bf
feat: opt code
luzhuang Dec 21, 2023
6eed48c
feat: opt code
luzhuang Dec 21, 2023
cead4fc
feat: opt code
luzhuang Dec 21, 2023
89addda
feat: update readme
luzhuang Dec 21, 2023
42aa61a
feat: update readme
luzhuang Dec 21, 2023
cc504bf
feat: update readme
luzhuang Dec 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# We'll let Git's auto-detection algorithm infer if a file is text. If it is,
# enforce LF line endings regardless of OS or git configurations.
* text=auto eol=lf
* text=auto eol=lf
e2e/fixtures/** filter=lfs diff=lfs merge=lfs -text
53 changes: 53 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: End-to-end tests
on: [push]

jobs:
e2e:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x]

steps:
- uses: actions/checkout@v3
with:
lfs: true
- name: Install pnpm
uses: pnpm/action-setup@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: pnpm
- name: Install dependencies
run: pnpm i
- name: Build
run: npm run build

- name: Run Cypress Tests
uses: cypress-io/github-action@v5
with:
start: npm run e2e:demo
wait-on: 'http://localhost:5175'
wait-on-timeout: 120
browser: chrome
- name: Upload Diff
if: failure()
uses: actions/upload-artifact@v3
with:
name: cypress-diff
path: e2e/diff/
- name: Upload Origin
if: failure()
uses: actions/upload-artifact@v3
with:
name: cypress-origin
path: e2e/fixtures/originImage
- name: Upload Screenshots
if: failure()
uses: actions/upload-artifact@v3
with:
name: cypress-screenshots
path: e2e/screenshots/
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ tmp
/packages/*/types
/packages/*/doc
/tests/node_modules
/e2e/node_modules
/playground/node_modules
types
/packages/*/test/fixtures/**/node_modules
Expand All @@ -25,3 +26,7 @@ stats.html
tsconfig.tsbuildinfo
api
yarn.lock
e2e/videos/*
e2e/screenshots/*
e2e/diff/*
e2e/.dev/mpa
3 changes: 3 additions & 0 deletions .husky/post-checkout
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting '.git/hooks/post-checkout'.\n"; exit 2; }
git lfs post-checkout "$@"
3 changes: 3 additions & 0 deletions .husky/post-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting '.git/hooks/post-commit'.\n"; exit 2; }
git lfs post-commit "$@"
3 changes: 3 additions & 0 deletions .husky/post-merge
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting '.git/hooks/post-merge'.\n"; exit 2; }
git lfs post-merge "$@"
3 changes: 3 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting '.git/hooks/pre-push'.\n"; exit 2; }
git lfs pre-push "$@"
71 changes: 71 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { defineConfig } from "cypress";
import { compare } from "odiff-bin";

const path = require("path");
const fs = require("fs-extra");

const downloadDirectory = path.join(__dirname, "e2e/downloads");
let isRunningInCommandLine = false;
export default defineConfig({
e2e: {
viewportWidth: 1200,
viewportHeight: 800,
baseUrl: "http://localhost:5175",
defaultCommandTimeout: 60000,
fileServerFolder: "e2e",
supportFile: "e2e/support/e2e.ts",
fixturesFolder: "e2e/fixtures",
screenshotsFolder: "e2e/screenshots",
videosFolder: "e2e/videos",
specPattern: "e2e/tests/*.cy.ts",
setupNodeEvents(on, config) {
// implement node event listeners here
on("before:browser:launch", (browser, launchOptions) => {
console.log("launching browser %s is headless? %s", browser.name, browser.isHeadless);
// supply the absolute path to an unpacked extension's folder
// NOTE: extensions cannot be loaded in headless Chrome
if (fs.existsSync("e2e/diff")) {
fs.rmdirSync("e2e/diff", { recursive: true });
}
if (browser.name === "chrome") {
launchOptions.preferences.default["download"] = {
default_directory: downloadDirectory
};
}
if (browser.isHeadless) {
isRunningInCommandLine = true;
}
launchOptions.args.push("--force-device-scale-factor=1");
return launchOptions;
}),
on("task", {
async compare({ fileName, options }) {
fileName += ".png";
const baseFolder = "e2e/fixtures/originImage/";
const newFolder = path.join("e2e/screenshots", isRunningInCommandLine ? options.specFolder : "");
const diffFolder = path.join("e2e/diff", options.specFolder);
if (!fs.existsSync(diffFolder)) {
fs.mkdirSync(diffFolder, { recursive: true });
}
const baseImage = path.join(baseFolder, fileName);
const newImage = path.join(newFolder, fileName);
const diffImage = path.join(diffFolder, fileName);
console.log("comparing base image %s to the new image %s", baseImage, newImage);
if (options) {
console.log("odiff options %o", options);
}
const started = +new Date();

const result = await compare(baseImage, newImage, diffImage, options);
const finished = +new Date();
const elapsed = finished - started;
console.log("odiff took %dms", elapsed);

console.log(result);
return result;
}
});
}
},
chromeWebSecurity: false
});
Binary file added e2e/.dev/AlibabaSans.ttf
Binary file not shown.
39 changes: 39 additions & 0 deletions e2e/.dev/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Galacean Demo</title>
</head>

<body>
<div class="container">
<div class="header">
<a class="logo" href="https://galacean.antgroup.com/" target="Home">
<img
src="https://mdn.alipayobjects.com/huamei_qbugvr/afts/img/A*ppQsSphM7uUAAAAAAAAAAAAADtKFAQ/original"
alt=""
/>
<span> Galacean </span>
</a>
</div>
<input
placeholder="search..."
class="search-bar"
id="searchBar"
autocorrect="off"
autocapitalize="off"
spellcheck="false"
/>
<div class="nav-left">
<div class="item-list" id="itemList"></div>
</div>

<div class="nav-right">
<iframe id="iframe" allowfullscreen src="" frameborder="0"></iframe>
</div>
</div>

<script type="module" src="./index.js"></script>
</body>
</html>
76 changes: 76 additions & 0 deletions e2e/.dev/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import './index.sass';
import demoList from './mpa/.demoList.json';
const itemListDOM = document.getElementById('itemList');
const searchBarDOM = document.getElementById('searchBar');
const iframe = document.getElementById('iframe');
const items = []; // itemDOM,label

Object.keys(demoList).forEach((group) => {
const demos = demoList[group];
const groupDOM = document.createElement('div');
const demosDOM = document.createElement('ul');
itemListDOM.appendChild(groupDOM);
groupDOM.appendChild(demosDOM);

demos.forEach((item) => {
const { label, src } = item;
const itemDOM = document.createElement('a');

itemDOM.innerHTML = src;
itemDOM.title = `${src}`;
itemDOM.onclick = function () {
clickItem(itemDOM);
};
demosDOM.appendChild(itemDOM);

items.push({
itemDOM,
label,
src,
});
});
});

searchBarDOM.oninput = () => {
updateFilter(searchBar.value);
};

function updateFilter(value) {
const reg = new RegExp(value, 'i');

items.forEach(({ itemDOM, label, src }) => {
reg.lastIndex = 0;
if (reg.test(label) || reg.test(src)) {
itemDOM.classList.remove('hide');
} else {
itemDOM.classList.add('hide');
}
});
}

function clickItem(itemDOM) {
window.location.hash = `#mpa/${itemDOM.title}`;
}

function onHashChange() {
const hashPath = window.location.hash.split('#')[1];
if (!hashPath) {
clickItem(items[0].itemDOM);
return;
}
iframe.src = hashPath + '.html';

items.forEach(({ itemDOM }) => {
const itemPath = `mpa/${itemDOM.title}`;
if (itemPath === hashPath) {
itemDOM.classList.add('active');
} else {
itemDOM.classList.remove('active');
}
});
}

window.onhashchange = onHashChange;

// init
onHashChange();
97 changes: 97 additions & 0 deletions e2e/.dev/index.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
$header-height: 3.5rem
$header-padding: 1rem
$container-gap: 2rem
$transition-duration: 0.5s

*
box-sizing: border-box

html, body
margin: 0
width: 100%
height: 100%
overflow: hidden

body
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif
font-size: 16px

a
text-decoration: none
color: inherit
display: inline-block

.container
display: flex
height: 100%
user-select: none
.header
position: absolute
top: 0
left: 0
height: $header-height
padding: $header-padding $container-gap
.logo
height: $header-height - 2 * $header-padding
display: flex
align-items: center
img
height: 100%
span
font-weight: bold
padding-left: 10px
font-size: 1.2em
.search-bar
position: absolute
top: $header-height
left: 1rem
padding: $header-padding $container-gap
background: #fff url("//gw-office.alipayobjects.com/basement_prod/225a73b9-1281-4388-9555-1e671899bc25.svg") .6rem .55rem no-repeat
cursor: text
width: 10rem
height: 2rem
color: #666
display: inline-block
border: 1px solid #ccc
border-radius: 2rem
font-size: .9rem
line-height: 2rem
outline: none
.nav-left
display: flex
flex-direction: column
overflow: auto
padding: 1rem $container-gap
margin-top: $header-height + 2rem

.item-list
.hide
height: 0
ul
padding-left: 20px
margin: 0
.title
font-weight: bold
cursor: default
font-size: 1.2em
a
height: 2rem
line-height: 2rem
cursor: pointer
transition-property: color,height
transition-duration: $transition-duration
overflow: hidden
display: block
&.active
text-decoration: underline
color: #096dd9
&:hover
color: #096dd9

.nav-right
flex: 1
box-shadow: rgb(125 121 121) -2px 0px 8px

iframe
width: 100%
height: 100%
Loading