Skip to content

Commit

Permalink
fix: lint and test 修复
Browse files Browse the repository at this point in the history
  • Loading branch information
wjgogogo committed Jan 19, 2024
1 parent d604e3d commit 1d28d21
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 26 deletions.
12 changes: 11 additions & 1 deletion jest.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@ module.exports = {
transformIgnorePatterns: [],
testRegex: '/__tests__/*.*(-|\\.)spec\\.(tsx|ts|js|vue)?$',
transform: {
'\\.(t|j)sx?$': '@swc/jest',
'\\.(t|j)sx?$': [
'@swc/jest',
{
jsc: {
transform: {
// https://swc.rs/docs/configuration/compilation#jsctransformusedefineforclassfields
useDefineForClassFields: false,
},
},
},
],
'\\.vue$': 'vue-jest',
'\\.(less|css)$': 'jest-less-loader',
'\\.svg$': 'jest-raw-loader',
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@
"@size-limit/esbuild": "^11.0.0",
"@size-limit/esbuild-why": "^11.0.0",
"@size-limit/file": "^11.0.0",
"@swc/core": "^1.2.171",
"@swc/jest": "^0.2.20",
"@swc/core": "^1.3.95",
"@swc/jest": "^0.2.29",
"@types/jest": "^27.4.1",
"@types/lodash": "^4.14.182",
"@types/node": "^17.0.26",
Expand Down
9 changes: 4 additions & 5 deletions packages/s2-core/__tests__/unit/cell/col-cell-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ describe('Col Cell Tests', () => {

const colCell = new ColCell(node, s2, { ...headerConfig });
set(colCell, 'actualTextWidth', actualTextWidth); // 文字总长度

const getTextPosition = get(colCell, 'getTextPosition').bind(colCell);
expect(getTextPosition()).toEqual({
// @ts-ignore
expect(colCell.getTextPosition()).toEqual({
x: textX,
y: 15,
});
Expand Down Expand Up @@ -99,8 +98,8 @@ describe('Col Cell Tests', () => {
const colCell = new ColCell(node, s2, { ...headerConfig });
set(colCell, 'actualTextWidth', actualTextWidth); // 文字总长度

const getIconPosition = get(colCell, 'getIconPosition').bind(colCell);
expect(getIconPosition()).toEqual({
// @ts-ignore
expect(colCell.getIconPosition()).toEqual({
x: iconX,
y: 10,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ describe('test for corner text', () => {
mockSheet.render();

test('get correct default corner text when the corner label is empty.', () => {
const cornerCells = get(
mockSheet,
'facet.cornerBBox.facet.cornerHeader.cfg.children',
const cornerCells = (
get(mockSheet, 'facet.cornerBBox.facet.cornerHeader.cfg.children') as any
).filter((v) => v instanceof CornerCell);
expect(cornerCells[0].actualText).toEqual('指标');
expect(cornerCells[1].actualText).toEqual('type');
Expand All @@ -52,9 +51,8 @@ describe('test for corner text', () => {
test('get correct default corner text when set the cornerText.', () => {
mockSheet.setOptions({ ...options, cornerText: 'test' });
mockSheet.render();
const cornerCells = get(
mockSheet,
'facet.cornerBBox.facet.cornerHeader.cfg.children',
const cornerCells = (
get(mockSheet, 'facet.cornerBBox.facet.cornerHeader.cfg.children') as any
).filter((v) => v instanceof CornerCell);
expect(cornerCells[0].actualText).toEqual('test');
expect(cornerCells[1].actualText).toEqual('type');
Expand Down
4 changes: 2 additions & 2 deletions packages/s2-core/__tests__/unit/cell/data-cell-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('Data Cell Tests', () => {
// 宽度相当
const linkLength = maxX - minX;
expect(
Math.abs(linkLength - get(dataCell, 'actualTextWidth')),
Math.abs(linkLength - get(dataCell, 'actualTextWidth', 0)),
).toBeLessThanOrEqual(2);

// link shape 的中点坐标与 text 中点对齐
Expand Down Expand Up @@ -114,7 +114,7 @@ describe('Data Cell Tests', () => {
});

test('should return correct formatted value', () => {
const formatter: Formatter = (_, data) => `${get(data, 'value') * 10}`;
const formatter: Formatter = (_, data) => `${get(data, 'value', 0) * 10}`;
jest.spyOn(s2.dataSet, 'getFieldFormatter').mockReturnValue(formatter);
const dataCell = new DataCell(meta, s2);

Expand Down
2 changes: 1 addition & 1 deletion packages/s2-core/__tests__/unit/cell/row-cell-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('Row Cell Tests', () => {
// 宽度相当
const linkLength = maxX - minX;
expect(
Math.abs(linkLength - get(provinceCell, 'actualTextWidth')),
Math.abs(linkLength - get(provinceCell, 'actualTextWidth', 0)),
).toBeLessThanOrEqual(2);

// link shape 的中点坐标与 text 中点对齐
Expand Down
3 changes: 1 addition & 2 deletions packages/s2-core/src/facet/base-facet.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Event as GraphEvent } from '@antv/g-base';
import type { IElement, IGroup } from '@antv/g-canvas';
import type { IElement, IGroup, Event as GraphEvent } from '@antv/g-canvas';
import { Group } from '@antv/g-canvas';
import { Wheel, type GestureEvent } from '@antv/g-gesture';
import { interpolateArray } from 'd3-interpolate';
Expand Down
2 changes: 1 addition & 1 deletion packages/s2-core/src/ui/scrollbar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export class ScrollBar extends Group {

this.isMobile = isMobile;

const event: MouseEvent = this.isMobile ? get(e, 'touches.0', e) : e;
const event = (this.isMobile ? get(e, 'touches.0', e) : e) as MouseEvent;
const { clientX, clientY } = event;

// 将开始的点记录下来
Expand Down
8 changes: 2 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1d28d21

Please sign in to comment.