Skip to content

Commit

Permalink
Merge pull request #3 from D-Sketon/test
Browse files Browse the repository at this point in the history
test: 接入单元测试
  • Loading branch information
D-Sketon authored Jul 15, 2024
2 parents 35e1cff + f536164 commit 642a6df
Show file tree
Hide file tree
Showing 14 changed files with 682 additions and 177 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/tester.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Tester

on:
push:
branches:
- "main"
paths:
- "src/**"
- "test/**"
- "package.json"
- "tsconfig.json"
- ".github/workflows/tester.yml"
pull_request:
paths:
- "src/**"
- "test/**"
- "package.json"
- "tsconfig.json"
- ".github/workflows/tester.yml"

permissions:
contents: read

jobs:
tester:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
node-version: ["18.x"]
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install Dependencies
run: npm install
- name: Test
run: npm test
env:
CI: true
coverage:
permissions:
checks: write # for coverallsapp/github-action to create new checks
contents: read # for actions/checkout to fetch code
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
node-version: ["18.x"]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install Dependencies
run: npm install
- name: Coverage
run: npm run test-cov
env:
CI: true
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ github.token }}
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,3 @@ coverage/
/dist

pnpm-lock.yaml

/test
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<img alt="NPM Bundle Size" src="https://img.shields.io/bundlephobia/minzip/mouse-firework">
<img alt="NPM Downloads" src="https://img.shields.io/npm/dm/mouse-firework">
<img alt="jsDelivr hits (npm)" src="https://img.shields.io/jsdelivr/npm/hm/mouse-firework">
<a href='https://coveralls.io/github/D-Sketon/mouse-firework?branch=main'><img src='https://coveralls.io/repos/github/D-Sketon/mouse-firework/badge.svg?branch=main' alt='Coverage Status' /></a>

[Demo](https://d-sketon.github.io/mouse-firework)
</div>
Expand All @@ -27,7 +28,7 @@ npm i mouse-firework --save
or just use it in your browser

```html
<script src="https://www.unpkg.com/mouse-firework@latest/dist/index.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/mouse-firework@latest/dist/index.umd.js"></script>
```

### Basic Usage
Expand All @@ -47,7 +48,7 @@ e.g.
particles: [
{
shape: "circle",
move: "emit",
move: ["emit"],
easing: "easeOutExpo",
colors: [
"rgba(255,182,185,.9)",
Expand Down
17 changes: 15 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"types": "dist/index.d.ts",
"scripts": {
"build": "rollup -c",
"build:umd": "rollup -c umd.config.mjs"
"build:umd": "rollup -c umd.config.mjs",
"test": "mocha -r ts-node/register 'test/**/*.ts'",
"test-cov": "c8 --reporter=lcov --reporter=text-summary npm test"
},
"author": "D-Sketon",
"license": "MIT",
Expand All @@ -17,12 +19,23 @@
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.5",
"@types/chai": "^4.3.16",
"@types/jsdom": "^21.1.7",
"@types/mocha": "^10.0.7",
"@types/node": "^20.10.6",
"@types/sinon": "^17.0.3",
"c8": "^10.1.2",
"chai": "^4.4.1",
"jsdom": "^24.1.0",
"mocha": "^10.6.0",
"rollup": "^4.9.2",
"sinon": "^18.0.0",
"ts-node": "^10.9.2",
"tslib": "^2.6.3",
"typescript": "^5.3.3"
},
"dependencies": {
"theme-shokax-anime": "^0.0.6"
"theme-shokax-anime": "^0.0.7"
},
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions src/anime/Anime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class Anime {
tl: Timeline;
isPlay: boolean;
constructor(options: AnimeOptions = defaultOptions) {
options = Object.assign({}, defaultOptions, options);
options = { ...defaultOptions, ...options };
const {
targets,
duration,
Expand All @@ -42,7 +42,7 @@ export default class Anime {
}

timeline() {
if (this.tl === null) {
if (!this.tl) {
this.tl = new Timeline();
}
return this.tl;
Expand Down
29 changes: 12 additions & 17 deletions src/anime/lib/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,9 @@ export default (anime: Anime) => {
if (!Array.isArray(dest)) {
// 不支持keyframe模式
// 支持nest模式 {value: 1, duration: 500, easing: 'linear'}
const { value, duration, easing } = dest;
const { value, duration, easing = anime.easing } = dest;
if (current <= start + duration) {
elapsed = penner()[easing ? easing : anime.easing]()(
(current - start) / duration
);
elapsed = penner()[easing]()((current - start) / duration);
change(target, origin, elapsed, value, key);
} else if (final) {
change(target, origin, elapsed, value, key, final);
Expand All @@ -82,21 +80,18 @@ export default (anime: Anime) => {
// 数据回正
changeAll(1, current, true);
anime.isPlay = false;
return;
}
// 还未开始,继续delay
if (current < start) {
} else {
if (current >= start) {
const elapsed = penner()[anime.easing]()(
(current - start) / anime.duration
);
isValid && changeAll(elapsed, current);
// 调用更新回调
typeof anime.update == "function" &&
anime.update(anime.targets as object[]);
}
requestAnimationFrame(step);
return;
}
const elapsed = penner()[anime.easing]()(
(current - start) / anime.duration
);
isValid && changeAll(elapsed, current);
// 调用更新回调
typeof anime.update == "function" &&
anime.update(anime.targets as object[]);
requestAnimationFrame(step);
};

initTarget();
Expand Down
5 changes: 2 additions & 3 deletions src/anime/lib/penner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default (): EasingFunctions => {

const functionEasings = {
Sine: () => (t: number) => 1 - Math.cos((t * Math.PI) / 2),
Expo: () => (t: number) => (t ? Math.pow(2, 10 * t - 10) : 0),
Circ: () => (t: number) => 1 - Math.sqrt(1 - t * t),
Back: () => (t: number) => t * t * (3 * t - 2),
Bounce: () => (t: number) => {
Expand All @@ -20,9 +21,7 @@ export default (): EasingFunctions => {
},
};

const baseEasings = ["Quad", "Cubic", "Quart", "Quint", "Expo"];

baseEasings.forEach((name, i) => {
["Quad", "Cubic", "Quart", "Quint"].forEach((name, i) => {
functionEasings[name] = () => (t: number) => Math.pow(t, i + 2);
});

Expand Down
1 change: 1 addition & 0 deletions src/entity/Circle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export default class Circle extends BaseEntity {
paint(): void {
this.ctx.beginPath();
this.ctx.arc(0, 0, this.radius, 0, 2 * Math.PI);
this.ctx.closePath();
}
}
3 changes: 2 additions & 1 deletion src/entity/Star.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class Star extends BaseEntity {
paint(): void {
const { ctx, spikes, radius } = this;
ctx.beginPath();
ctx.moveTo(0, 0 - radius);
ctx.moveTo(0, -radius);
for (let i = 0; i < spikes * 2; i++) {
const angle = (i * Math.PI) / spikes - Math.PI / 2;
const length = i % 2 === 0 ? radius : radius * 0.5;
Expand All @@ -30,3 +30,4 @@ export default class Star extends BaseEntity {
ctx.closePath();
}
}

Loading

0 comments on commit 642a6df

Please sign in to comment.