Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,15 @@ describe('Auto Limit', () => {
});
stage.defaultLayer.add(axis as unknown as IGraphic);
stage.render();
expect((axis.getElementsByName('axis-label')[0] as IText).clipedText).toBe('form等');
const firstLabel = axis.getElementsByName('axis-label')[0] as IText;
const firstClippedText = firstLabel.clipedText as string;
expect(firstClippedText).not.toBe(firstLabel.attribute.text);
expect(firstClippedText.endsWith('等')).toBe(true);

axis.setAttribute('verticalLimitSize', 60);
expect((axis.getElementsByName('axis-label')[0] as IText).clipedText).toBe('for等');
const updatedClippedText = (axis.getElementsByName('axis-label')[0] as IText).clipedText as string;
expect(updatedClippedText.endsWith('等')).toBe(true);
expect(updatedClippedText.length).toBeLessThan(firstClippedText.length);
});

it('should ignore when the ceil of label size is not bigger than limitSize', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ describe('Legend focus layout', () => {
stage.defaultLayer.add(legend as unknown as IGraphic);
stage.render();
expect(legend.getElementsByName(LEGEND_ELEMENT_NAME.focus).length).toBe(4);
expect((legend.getElementsByName(LEGEND_ELEMENT_NAME.focus)[0] as ISymbol).attribute.x).toBe(41);
const firstItem = getLegendItems(legend)[0];
const firstLabel = firstItem.getElementsByName(LEGEND_ELEMENT_NAME.itemLabel)[0] as IText;
const firstFocus = firstItem.getElementsByName(LEGEND_ELEMENT_NAME.focus)[0] as ISymbol;
expect(firstFocus.attribute.x - firstLabel.attribute.x).toBeCloseTo(firstLabel.AABBBounds.width() + 6);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,10 @@ describe('DiscreteLegend', () => {
stage.defaultLayer.add(legend as unknown as IGraphic);
stage.render();

expect(legend.AABBBounds.width()).toBe(76);
const legendItems = legend.getElementsByName('legendItem') as IGroup[];
expect(legendItems).toHaveLength(2);
expect(legend.AABBBounds.width()).toBeCloseTo(Math.max(...legendItems.map(item => item.AABBBounds.width())));
expect(legend.AABBBounds.width()).toBeLessThan(1000);
});

it("should omit when label's width exceeds item's width", () => {
Expand Down
9 changes: 6 additions & 3 deletions packages/vrender-components/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ const path = require('path');

module.exports = {
preset: 'ts-jest',
runner: 'jest-electron/runner',
testEnvironment: 'jest-electron/environment',
testEnvironment: path.resolve(__dirname, '../../share/jest-config/jest-environment-jsdom-26.js'),
testEnvironmentOptions: {
pretendToBeVisual: true
},
testRegex: '/__tests__/.*\\.test\\.(js|ts)$',
silent: true,
useStderr: false,
globals: {
'ts-jest': {
resolveJsonModule: true,
Expand All @@ -19,7 +22,7 @@ module.exports = {
collectCoverage: false,
collectCoverageFrom: ['src/**/*.ts', '!**/type/**'],
coverageReporters: ['json-summary', 'lcov', 'text'],
setupFiles: ['./setup-mock.js'],
setupFiles: [path.resolve(__dirname, '../../share/jest-config/setup-jsdom-canvas.js'), './setup-mock.js'],
coveragePathIgnorePatterns: ['node_modules', '__tests__', 'interface.ts', '.d.ts', 'typings', 'type.ts'],
moduleNameMapper: {
'@visactor/vrender-kits': path.resolve(__dirname, '../vrender-kits/src/index.ts'),
Expand Down
2 changes: 1 addition & 1 deletion packages/vrender-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"build": "cross-env DEBUG='Bundler*' bundle",
"dev": "cross-env DEBUG='Bundler*' bundle --clean -f es -w",
"start": "vite ./__tests__/browser",
"test": "jest",
"test": "jest 2>&1",
"test-cov": "jest --coverage",
"test-live": "npm run test-watch __tests__/unit/",
"test-watch": "cross-env DEBUG_MODE=1 jest --watch",
Expand Down
1 change: 1 addition & 0 deletions packages/vrender-components/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"sourceMap": true,
"paths": {
"@visactor/vrender": ["../vrender/src"],
"@visactor/vrender-core": ["../vrender-core/src"],
Expand Down
12 changes: 8 additions & 4 deletions packages/vrender-core/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
module.exports = {
runner: 'jest-electron/runner',
testEnvironment: 'jest-electron/environment',
testEnvironment: '../../share/jest-config/jest-environment-jsdom-26.js',
testEnvironmentOptions: {
pretendToBeVisual: true
},
Comment on lines 1 to +5
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this config, testEnvironment / setupFiles are specified as relative paths (e.g. ../../share/...) whereas other package configs use path.resolve(__dirname, ...). Using absolute paths here avoids surprises if rootDir is customized or Jest is invoked from a different working directory, and keeps the configs consistent across packages.

Copilot uses AI. Check for mistakes.
testTimeout: 30000,
testRegex: '/__tests__/.*test\\.ts?$',
moduleFileExtensions: ['ts', 'js', 'json'],
setupFilesAfterEnv: ['jest-extended/all'],
preset: 'ts-jest',
silent: true,
useStderr: false,
globals: {
'ts-jest': {
tsconfig: {
resolveJsonModule: true,
esModuleInterop: true,
experimentalDecorators: true,
module: 'ESNext'
module: 'ESNext',
sourceMap: true
}
},
__DEV__: true
},
setupFiles: ['./setup-mock.js'],
setupFiles: ['../../share/jest-config/setup-jsdom-canvas.js', './setup-mock.js'],
verbose: true,
coverageReporters: ['json-summary', 'lcov', 'text'],
coveragePathIgnorePatterns: ['node_modules', '__tests__', 'interface.ts', '.d.ts', 'typings'],
Expand Down
2 changes: 1 addition & 1 deletion packages/vrender-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"build-umd": "cross-env DEBUG='Bundler*' bundle --clean -f umd",
"dev": "cross-env DEBUG='Bundler*' bundle --clean -f es -w",
"start": "vite ./__tests__/browser",
"test": "jest",
"test": "jest 2>&1",
"test-live": "npm run test-watch __tests__/unit/theme/line.test.ts",
"test-watch": "cross-env DEBUG_MODE=1 jest --watch",
"test-cov": "jest -w 16 --coverage",
Expand Down
2 changes: 2 additions & 0 deletions packages/vrender/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ module.exports = {
runner: 'jest-electron/runner',
testEnvironment: 'jest-electron/environment',
testTimeout: 30000,
maxWorkers: 1,
testRegex: '/__tests__/.*test\\.ts?$',
moduleFileExtensions: ['ts', 'js', 'json'],
setupFilesAfterEnv: ['jest-extended/all'],
preset: 'ts-jest',
silent: true,
useStderr: false,
globals: {
'ts-jest': {
resolveJsonModule: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/vrender/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"build-umd": "cross-env DEBUG='Bundler*' bundle --clean -f umd",
"dev": "cross-env DEBUG='Bundler*' bundle --clean -f es -w",
"start": "vite ./__tests__/browser --host",
"test": "jest",
"test": "jest 2>&1",
"test-cov": "jest -w 16 --coverage",
"test-live": "npm run test-watch __tests__/unit/theme/line.test.ts",
"test-watch": "cross-env DEBUG_MODE=1 jest --watch"
Expand Down
19 changes: 19 additions & 0 deletions share/jest-config/jest-environment-jsdom-26.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const fs = require('fs');
const path = require('path');

function resolveJestEnvironmentJsdom26() {
const pnpmDir = path.resolve(__dirname, '../../common/temp/node_modules/.pnpm');
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fs.readdirSync(pnpmDir) will throw an unhandled ENOENT if common/temp/node_modules/.pnpm doesn’t exist (e.g., tests run before rush install, or in a different install layout). Add an existence check (or catch the error) and rethrow a clearer message indicating the expected install step/location.

Suggested change
const pnpmDir = path.resolve(__dirname, '../../common/temp/node_modules/.pnpm');
const pnpmDir = path.resolve(__dirname, '../../common/temp/node_modules/.pnpm');
if (!fs.existsSync(pnpmDir)) {
throw new Error(
'Unable to locate PNPM directory at "common/temp/node_modules/.pnpm". ' +
'Ensure that dependencies have been installed (for example, by running "rush install" in the repo root).'
);
}

Copilot uses AI. Check for mistakes.
const entry = fs
.readdirSync(pnpmDir)
.find(name => name.startsWith('jest-environment-jsdom@26.6.2'));

if (!entry) {
throw new Error('Unable to resolve jest-environment-jsdom@26.6.2 from common/temp/node_modules/.pnpm');
}

return path.join(pnpmDir, entry, 'node_modules/jest-environment-jsdom/build/index.js');
Comment on lines +1 to +14
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This environment resolver relies on pnpm’s internal virtual store layout (common/temp/node_modules/.pnpm) and directory naming to locate jest-environment-jsdom@26.6.2. This is brittle and makes the test environment sensitive to pnpm implementation details. A more robust approach is to use require.resolve('jest-environment-jsdom/build/index.js', { paths: [path.resolve(__dirname, '../../common/temp/node_modules')] }) (or similar) so Node’s resolver finds the correct installed copy without scanning .pnpm.

Suggested change
const fs = require('fs');
const path = require('path');
function resolveJestEnvironmentJsdom26() {
const pnpmDir = path.resolve(__dirname, '../../common/temp/node_modules/.pnpm');
const entry = fs
.readdirSync(pnpmDir)
.find(name => name.startsWith('jest-environment-jsdom@26.6.2'));
if (!entry) {
throw new Error('Unable to resolve jest-environment-jsdom@26.6.2 from common/temp/node_modules/.pnpm');
}
return path.join(pnpmDir, entry, 'node_modules/jest-environment-jsdom/build/index.js');
const path = require('path');
function resolveJestEnvironmentJsdom26() {
const baseNodeModulesDir = path.resolve(__dirname, '../../common/temp/node_modules');
try {
return require.resolve('jest-environment-jsdom/build/index.js', {
paths: [baseNodeModulesDir],
});
} catch (error) {
throw new Error(
'Unable to resolve jest-environment-jsdom@26.6.2 from ' + baseNodeModulesDir
);
}

Copilot uses AI. Check for mistakes.
}

const environmentModule = require(resolveJestEnvironmentJsdom26());

module.exports = environmentModule.default || environmentModule;
Loading
Loading