mirror of
https://github.com/idrawjs/idraw
synced 2026-05-24 01:58:27 +00:00
chore: update testing
This commit is contained in:
parent
5dd5bc0797
commit
eeef932be8
9 changed files with 141 additions and 127 deletions
1
.github/workflows/node.js.yml
vendored
1
.github/workflows/node.js.yml
vendored
|
|
@ -26,4 +26,5 @@ jobs:
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node-version }}
|
node-version: ${{ matrix.node-version }}
|
||||||
- run: npm install
|
- run: npm install
|
||||||
|
- run: npm run beforetest
|
||||||
- run: npm run test
|
- run: npm run test
|
||||||
|
|
|
||||||
|
|
@ -15,11 +15,12 @@ const { PNG } = pngjs;
|
||||||
async function diff() {
|
async function diff() {
|
||||||
const middlewares = [];
|
const middlewares = [];
|
||||||
const diffRateList = [];
|
const diffRateList = [];
|
||||||
pageList.forEach((p) => {
|
pageList.forEach((p, i) => {
|
||||||
middlewares.push(async (ctx = {}, next) => {
|
middlewares.push(async (ctx = {}, next) => {
|
||||||
const { page, port } = ctx;
|
const { page, port } = ctx;
|
||||||
const width = p.w;
|
const width = p.w;
|
||||||
const height = p.h;
|
const height = p.h;
|
||||||
|
console.log(`[${i+1}/${pageList.length}] E2E Testing: ${p.path}`)
|
||||||
await page.setViewport( { width: p.w, height: p.h } );
|
await page.setViewport( { width: p.w, height: p.h } );
|
||||||
const pageUrl = `http://127.0.0.1:${port}/packages/${p.path || ''}`;
|
const pageUrl = `http://127.0.0.1:${port}/packages/${p.path || ''}`;
|
||||||
await page.goto(pageUrl);
|
await page.goto(pageUrl);
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,13 @@
|
||||||
"init": "lerna bootstrap --npm-client=cnpm",
|
"init": "lerna bootstrap --npm-client=cnpm",
|
||||||
"clear": "rm -rf ./packages/*/dist/ & rm -rf ./packages/*/node_modules/",
|
"clear": "rm -rf ./packages/*/dist/ & rm -rf ./packages/*/node_modules/",
|
||||||
"jest": "jest --config jest.config.js",
|
"jest": "jest --config jest.config.js",
|
||||||
"test": "lerna bootstrap --no-ci && npm run build && npm run jest && npm run e2e",
|
"beforetest": "lerna bootstrap --no-ci && npm run build",
|
||||||
|
"test": "npm run e2e && npm run jest",
|
||||||
"serve": "http-server ./",
|
"serve": "http-server ./",
|
||||||
"lint": "eslint --fix --ext .ts packages/*/src/**",
|
"lint": "eslint --fix --ext .ts packages/*/src/**",
|
||||||
"precommit": "npm run lint",
|
"precommit": "npm run lint",
|
||||||
"prepush": "npm run lint"
|
"prepush": "npm run lint",
|
||||||
|
"clear:jest": "rm -rf ./packages/*/__tests__/__snapshots__"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.13.14",
|
"@babel/core": "^7.13.14",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`@idraw/board: context 1`] = `
|
exports[`@idraw/board context 1`] = `
|
||||||
Array [
|
Array [
|
||||||
Object {
|
Object {
|
||||||
"props": Object {
|
"props": Object {
|
||||||
|
|
@ -64,7 +64,7 @@ Array [
|
||||||
]
|
]
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`@idraw/board: context 2`] = `
|
exports[`@idraw/board context 2`] = `
|
||||||
Array [
|
Array [
|
||||||
Object {
|
Object {
|
||||||
"props": Object {
|
"props": Object {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`@idraw/board: scroll 1`] = `
|
exports[`@idraw/board scale 1`] = `
|
||||||
Array [
|
Array [
|
||||||
Object {
|
Object {
|
||||||
"props": Object {
|
"props": Object {
|
||||||
|
|
@ -64,7 +64,7 @@ Array [
|
||||||
]
|
]
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`@idraw/board: scroll 2`] = `
|
exports[`@idraw/board scale 2`] = `
|
||||||
Array [
|
Array [
|
||||||
Object {
|
Object {
|
||||||
"props": Object {
|
"props": Object {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`@idraw/board: scroll 1`] = `
|
exports[`@idraw/board scroll 1`] = `
|
||||||
Array [
|
Array [
|
||||||
Object {
|
Object {
|
||||||
"props": Object {
|
"props": Object {
|
||||||
|
|
@ -64,7 +64,7 @@ Array [
|
||||||
]
|
]
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`@idraw/board: scroll 2`] = `
|
exports[`@idraw/board scroll 2`] = `
|
||||||
Array [
|
Array [
|
||||||
Object {
|
Object {
|
||||||
"props": Object {
|
"props": Object {
|
||||||
|
|
|
||||||
|
|
@ -1,41 +1,45 @@
|
||||||
import Board from './../src';
|
import Board from './../src';
|
||||||
import { getData } from './data';
|
import { getData } from './data';
|
||||||
|
|
||||||
test('@idraw/board: context', async () => {
|
|
||||||
document.body.innerHTML = `
|
|
||||||
<div id="mount"></div>
|
|
||||||
`;
|
|
||||||
const opts = {
|
|
||||||
width: 600,
|
|
||||||
height: 400,
|
|
||||||
contextWidth: 600,
|
|
||||||
contextHeight: 400,
|
|
||||||
devicePixelRatio: 4
|
|
||||||
}
|
|
||||||
const mount = document.querySelector('#mount') as HTMLDivElement;
|
|
||||||
const board = new Board(mount, opts);
|
|
||||||
|
|
||||||
const ctx = board.getContext();
|
describe('@idraw/board', () => {
|
||||||
const data = getData();
|
test('context', async () => {
|
||||||
|
document.body.innerHTML = `
|
||||||
|
<div id="mount"></div>
|
||||||
|
`;
|
||||||
|
const opts = {
|
||||||
|
width: 600,
|
||||||
|
height: 400,
|
||||||
|
contextWidth: 600,
|
||||||
|
contextHeight: 400,
|
||||||
|
devicePixelRatio: 4
|
||||||
|
}
|
||||||
|
const mount = document.querySelector('#mount') as HTMLDivElement;
|
||||||
|
const board = new Board(mount, opts);
|
||||||
|
|
||||||
|
const ctx = board.getContext();
|
||||||
|
const data = getData();
|
||||||
|
|
||||||
|
board.clear();
|
||||||
|
ctx.clearRect(0, 0, opts.width, opts.height);
|
||||||
|
ctx.setFillStyle('#ffffff');
|
||||||
|
ctx.fillRect(0, 0, opts.width, opts.height);
|
||||||
|
data.elements.forEach(ele => {
|
||||||
|
ctx.setFillStyle(ele.desc.color);
|
||||||
|
ctx.fillRect(ele.x, ele.y, ele.w, ele.h);
|
||||||
|
});
|
||||||
|
board.draw();
|
||||||
|
|
||||||
|
const originCtx = board.getOriginContext();
|
||||||
|
// @ts-ignore;
|
||||||
|
const originCalls = originCtx.__getDrawCalls();
|
||||||
|
expect(originCalls).toMatchSnapshot();
|
||||||
|
|
||||||
|
const displayCtx = board.getDisplayContext();
|
||||||
|
// @ts-ignore;
|
||||||
|
const displayCalls = displayCtx.__getDrawCalls();
|
||||||
|
expect(displayCalls).toMatchSnapshot();
|
||||||
|
|
||||||
board.clear();
|
|
||||||
ctx.clearRect(0, 0, opts.width, opts.height);
|
|
||||||
ctx.setFillStyle('#ffffff');
|
|
||||||
ctx.fillRect(0, 0, opts.width, opts.height);
|
|
||||||
data.elements.forEach(ele => {
|
|
||||||
ctx.setFillStyle(ele.desc.color);
|
|
||||||
ctx.fillRect(ele.x, ele.y, ele.w, ele.h);
|
|
||||||
});
|
});
|
||||||
board.draw();
|
})
|
||||||
|
|
||||||
const originCtx = board.getOriginContext();
|
|
||||||
// @ts-ignore;
|
|
||||||
const originCalls = originCtx.__getDrawCalls();
|
|
||||||
expect(originCalls).toMatchSnapshot();
|
|
||||||
|
|
||||||
const displayCtx = board.getDisplayContext();
|
|
||||||
// @ts-ignore;
|
|
||||||
const displayCalls = displayCtx.__getDrawCalls();
|
|
||||||
expect(displayCalls).toMatchSnapshot();
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
@ -1,44 +1,47 @@
|
||||||
import Board from '../src';
|
import Board from '../src';
|
||||||
import { getData } from './data';
|
import { getData } from './data';
|
||||||
|
|
||||||
test('@idraw/board: scroll', async () => {
|
describe('@idraw/board', () => {
|
||||||
document.body.innerHTML = `
|
|
||||||
<div id="mount"></div>
|
|
||||||
`;
|
|
||||||
const opts = {
|
|
||||||
width: 600,
|
|
||||||
height: 400,
|
|
||||||
contextWidth: 600,
|
|
||||||
contextHeight: 400,
|
|
||||||
devicePixelRatio: 4
|
|
||||||
}
|
|
||||||
const mount = document.querySelector('#mount') as HTMLDivElement;
|
|
||||||
const board = new Board(mount, opts);
|
|
||||||
|
|
||||||
const ctx = board.getContext();
|
test('scale', async () => {
|
||||||
const data = getData();
|
document.body.innerHTML = `
|
||||||
|
<div id="mount"></div>
|
||||||
|
`;
|
||||||
|
const opts = {
|
||||||
|
width: 600,
|
||||||
|
height: 400,
|
||||||
|
contextWidth: 600,
|
||||||
|
contextHeight: 400,
|
||||||
|
devicePixelRatio: 4
|
||||||
|
}
|
||||||
|
const mount = document.querySelector('#mount') as HTMLDivElement;
|
||||||
|
const board = new Board(mount, opts);
|
||||||
|
|
||||||
|
const ctx = board.getContext();
|
||||||
|
const data = getData();
|
||||||
|
|
||||||
|
board.clear();
|
||||||
|
ctx.clearRect(0, 0, opts.width, opts.height);
|
||||||
|
ctx.setFillStyle('#ffffff');
|
||||||
|
ctx.fillRect(0, 0, opts.width, opts.height);
|
||||||
|
data.elements.forEach(ele => {
|
||||||
|
ctx.setFillStyle(ele.desc.color);
|
||||||
|
ctx.fillRect(ele.x, ele.y, ele.w, ele.h);
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = board.scale(0.5);
|
||||||
|
expect(result).toStrictEqual({"position":{"top":150,"bottom":100,"left":100,"right":150},"size":{"x":75,"y":50,"w":300,"h":200}})
|
||||||
|
board.draw();
|
||||||
|
|
||||||
|
const originCtx = board.getOriginContext();
|
||||||
|
// @ts-ignore;
|
||||||
|
const originCalls = originCtx.__getDrawCalls();
|
||||||
|
expect(originCalls).toMatchSnapshot();
|
||||||
|
|
||||||
|
const displayCtx = board.getDisplayContext();
|
||||||
|
// @ts-ignore;
|
||||||
|
const displayCalls = displayCtx.__getDrawCalls();
|
||||||
|
expect(displayCalls).toMatchSnapshot();
|
||||||
|
|
||||||
board.clear();
|
|
||||||
ctx.clearRect(0, 0, opts.width, opts.height);
|
|
||||||
ctx.setFillStyle('#ffffff');
|
|
||||||
ctx.fillRect(0, 0, opts.width, opts.height);
|
|
||||||
data.elements.forEach(ele => {
|
|
||||||
ctx.setFillStyle(ele.desc.color);
|
|
||||||
ctx.fillRect(ele.x, ele.y, ele.w, ele.h);
|
|
||||||
});
|
});
|
||||||
|
})
|
||||||
const result = board.scale(0.5);
|
|
||||||
expect(result).toStrictEqual({"position":{"top":150,"bottom":100,"left":100,"right":150},"size":{"x":75,"y":50,"w":300,"h":200}})
|
|
||||||
board.draw();
|
|
||||||
|
|
||||||
const originCtx = board.getOriginContext();
|
|
||||||
// @ts-ignore;
|
|
||||||
const originCalls = originCtx.__getDrawCalls();
|
|
||||||
expect(originCalls).toMatchSnapshot();
|
|
||||||
|
|
||||||
const displayCtx = board.getDisplayContext();
|
|
||||||
// @ts-ignore;
|
|
||||||
const displayCalls = displayCtx.__getDrawCalls();
|
|
||||||
expect(displayCalls).toMatchSnapshot();
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
|
||||||
|
|
@ -1,49 +1,52 @@
|
||||||
import Board from '../src';
|
import Board from '../src';
|
||||||
import { getData } from './data';
|
import { getData } from './data';
|
||||||
|
|
||||||
test('@idraw/board: scroll', async () => {
|
describe('@idraw/board', () => {
|
||||||
document.body.innerHTML = `
|
test('scroll', async () => {
|
||||||
<div id="mount"></div>
|
document.body.innerHTML = `
|
||||||
`;
|
<div id="mount"></div>
|
||||||
const opts = {
|
`;
|
||||||
width: 600,
|
const opts = {
|
||||||
height: 400,
|
width: 600,
|
||||||
contextWidth: 600,
|
height: 400,
|
||||||
contextHeight: 400,
|
contextWidth: 600,
|
||||||
devicePixelRatio: 4
|
contextHeight: 400,
|
||||||
}
|
devicePixelRatio: 4
|
||||||
const mount = document.querySelector('#mount') as HTMLDivElement;
|
}
|
||||||
const board = new Board(mount, opts);
|
const mount = document.querySelector('#mount') as HTMLDivElement;
|
||||||
|
const board = new Board(mount, opts);
|
||||||
|
|
||||||
const ctx = board.getContext();
|
const ctx = board.getContext();
|
||||||
const data = getData();
|
const data = getData();
|
||||||
board.clear();
|
board.clear();
|
||||||
ctx.clearRect(0, 0, opts.width, opts.height);
|
ctx.clearRect(0, 0, opts.width, opts.height);
|
||||||
ctx.setFillStyle('#ffffff');
|
ctx.setFillStyle('#ffffff');
|
||||||
ctx.fillRect(0, 0, opts.width, opts.height);
|
ctx.fillRect(0, 0, opts.width, opts.height);
|
||||||
data.elements.forEach(ele => {
|
data.elements.forEach(ele => {
|
||||||
ctx.setFillStyle(ele.desc.color);
|
ctx.setFillStyle(ele.desc.color);
|
||||||
ctx.fillRect(ele.x, ele.y, ele.w, ele.h);
|
ctx.fillRect(ele.x, ele.y, ele.w, ele.h);
|
||||||
|
});
|
||||||
|
|
||||||
|
const resultScale =board.scale(2);
|
||||||
|
expect(resultScale).toStrictEqual({"position":{"top":0,"bottom":-400,"left":0,"right":-600},"size":{"x":0,"y":0,"w":1200,"h":800}})
|
||||||
|
|
||||||
|
const resultX =board.scrollX(-600);
|
||||||
|
expect(resultX).toStrictEqual({"position":{"top":-600,"bottom":-400,"left":0,"right":0},"size":{"x":-1200,"y":0,"w":1200,"h":800}})
|
||||||
|
|
||||||
|
const resultY =board.scrollY(-400);
|
||||||
|
expect(resultY).toStrictEqual({"position":{"top":-600,"bottom":0,"left":-400,"right":0},"size":{"x":-1200,"y":-800,"w":1200,"h":800}})
|
||||||
|
|
||||||
|
board.draw();
|
||||||
|
|
||||||
|
const originCtx = board.getOriginContext();
|
||||||
|
// @ts-ignore;
|
||||||
|
const originCalls = originCtx.__getDrawCalls();
|
||||||
|
expect(originCalls).toMatchSnapshot();
|
||||||
|
|
||||||
|
const displayCtx = board.getDisplayContext();
|
||||||
|
// @ts-ignore;
|
||||||
|
const displayCalls = displayCtx.__getDrawCalls();
|
||||||
|
expect(displayCalls).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
const resultScale =board.scale(2);
|
|
||||||
expect(resultScale).toStrictEqual({"position":{"top":0,"bottom":-400,"left":0,"right":-600},"size":{"x":0,"y":0,"w":1200,"h":800}})
|
|
||||||
|
|
||||||
const resultX =board.scrollX(-600);
|
|
||||||
expect(resultX).toStrictEqual({"position":{"top":-600,"bottom":-400,"left":0,"right":0},"size":{"x":-1200,"y":0,"w":1200,"h":800}})
|
|
||||||
|
|
||||||
const resultY =board.scrollY(-400);
|
|
||||||
expect(resultY).toStrictEqual({"position":{"top":-600,"bottom":0,"left":-400,"right":0},"size":{"x":-1200,"y":-800,"w":1200,"h":800}})
|
|
||||||
|
|
||||||
board.draw();
|
|
||||||
|
|
||||||
const originCtx = board.getOriginContext();
|
|
||||||
// @ts-ignore;
|
|
||||||
const originCalls = originCtx.__getDrawCalls();
|
|
||||||
expect(originCalls).toMatchSnapshot();
|
|
||||||
|
|
||||||
const displayCtx = board.getDisplayContext();
|
|
||||||
// @ts-ignore;
|
|
||||||
const displayCalls = displayCtx.__getDrawCalls();
|
|
||||||
expect(displayCalls).toMatchSnapshot();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue