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
7 changes: 4 additions & 3 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ jobs:
run: node common/scripts/install-run-rush.js update --bypass-policy
- name: Install rush
run: node common/scripts/install-run-rush.js install --bypass-policy
- name: Source tests (without build artifacts)
run: node common/scripts/install-run-rush.js test --only tag:package
- run: node common/scripts/install-run-rush.js build --only tag:package
- name: Pre unit test
run: cd packages/vrender && node ../../common/scripts/install-run-rushx.js test && cd ../..
- run: node common/scripts/install-run-rush.js test --only tag:package
- name: Published artifact tests
run: node common/scripts/install-run-rush.js test:artifacts --only tag:package
9 changes: 9 additions & 0 deletions common/config/rush/command-line.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@
"ignoreDependencyOrder": true,
"allowWarningsInSuccessfulBuild": true
},
{
"name": "test:artifacts",
"summary": "Validate published artifacts after building packages",
"enableParallelism": false,
"commandKind": "bulk",
"ignoreMissingScript": true,
"ignoreDependencyOrder": true,
"allowWarningsInSuccessfulBuild": true
},
{
"name": "run",
"summary": "",
Expand Down
20 changes: 19 additions & 1 deletion docs/agent/VRENDER_TEST_AND_VERIFICATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- `rush compile -t @visactor/vrender-core`
- `rush test`
- `rush test -t @visactor/vrender`
- `rush test:artifacts --only tag:package`(先 build,再检查发布产物)
- `rush eslint`
- `rush lint-staged`
- `rush start`
Expand Down Expand Up @@ -41,6 +42,23 @@

## 单包 Test

`rush test`、各包 `rushx test` 和 pre-push 只运行源码测试:仓库内包通过
`share/jest-config/source-module-name-mapper.js` 解析到本地 `src`,不依赖 `es/cjs/dist`。
第三方 npm 依赖仍使用安装版本。CI 在 build 之前运行源码测试,避免旧产物掩盖源码问题。

构建产物断言位于各包 `__tests__/artifacts/`,默认单测和 Electron 测试不会收集它们。
`vrender-core`、`vrender-kits`、`vrender` 提供独立的 `rushx test:artifacts`;这些测试不启用源码映射,
并在缺少构建文件时失败。跨包产物检查需要先构建全部 package:

```bash
rush build --only tag:package
rush test:artifacts --only tag:package
```

新增测试时,运行时行为及源码/配置契约归入默认单测;读取构建输出或验证发布包入口的断言归入 artifacts。
同时包含两类断言的文件应拆分。验证源码测试独立性时,在没有各包 `es/cjs/dist` 的干净 worktree 中执行
`rush test --only tag:package`,不通过跳过失败用例或自动 build 消除依赖。

在对应 package 下:

- `cd packages/vrender-core && rushx test`
Expand Down Expand Up @@ -135,7 +153,7 @@ root:
- `packages/vrender/__tests__/unit/shared-browser-lite-entry.test.ts`
- `packages/vrender/__tests__/unit/app-bootstrap-binding.test.ts`
- `packages/vrender/__tests__/unit/node-app-runtime.test.ts`
- `packages/vrender/__tests__/unit/build-artifact-consistency.test.ts`
- 发布产物检查:`packages/vrender/__tests__/artifacts/*`

## Animate 测试

Expand Down
5 changes: 1 addition & 4 deletions packages/react-vrender-utils/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const path = require('path');
const { createStablePackageJestConfig } = require('../../share/jest-config/create-package-config');

module.exports = createStablePackageJestConfig({
Expand All @@ -22,7 +21,5 @@ module.exports = createStablePackageJestConfig({
'!**/interface.ts',
'!**/**.d.ts'
],
moduleNameMapper: {
'@visactor/react-vrender': path.resolve(__dirname, '../react-vrender/src/index.ts')
}
moduleNameMapper: require('../../share/jest-config/source-module-name-mapper')
});
9 changes: 1 addition & 8 deletions packages/react-vrender/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const path = require('path');
const { createStablePackageJestConfig } = require('../../share/jest-config/create-package-config');

module.exports = createStablePackageJestConfig({
Expand All @@ -22,11 +21,5 @@ module.exports = createStablePackageJestConfig({
'!**/interface.ts',
'!**/**.d.ts'
],
moduleNameMapper: {
'@visactor/vrender': path.resolve(__dirname, '../vrender/src/index.ts'),
'@visactor/vrender-core': path.resolve(__dirname, '../vrender-core/src/index.ts'),
'@visactor/vrender-kits': path.resolve(__dirname, '../vrender-kits/src/index.ts'),
'@visactor/vrender-animate': path.resolve(__dirname, '../vrender-animate/src/index.ts'),
'@visactor/vrender-components': path.resolve(__dirname, '../vrender-components/src/index.ts')
}
moduleNameMapper: require('../../share/jest-config/source-module-name-mapper')
});
15 changes: 1 addition & 14 deletions packages/vrender-animate/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const path = require('path');
const { createStablePackageJestConfig } = require('../../share/jest-config/create-package-config');

module.exports = createStablePackageJestConfig({
Expand All @@ -21,17 +20,5 @@ module.exports = createStablePackageJestConfig({
'!**/interface.ts',
'!**/**.d.ts'
],
moduleNameMapper: {
'^@visactor/vrender-core/event/constant$': path.resolve(__dirname, '../vrender-core/src/event/public-constant.ts'),
'^@visactor/vrender-core/render/draw-interceptor$': path.resolve(
__dirname,
'../vrender-core/src/render/contributions/render/draw-interceptor.ts'
),
'^@visactor/vrender-core/render/symbol$': path.resolve(
__dirname,
'../vrender-core/src/render/contributions/render/symbol.ts'
),
'^@visactor/vrender-core/(.*)$': path.resolve(__dirname, '../vrender-core/src/$1'),
'^@visactor/vrender-core$': path.resolve(__dirname, '../vrender-core/src/index.ts')
}
moduleNameMapper: require('../../share/jest-config/source-module-name-mapper')
});
22 changes: 1 addition & 21 deletions packages/vrender-components/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const path = require('path');
const { createStablePackageJestConfig } = require('../../share/jest-config/create-package-config');

module.exports = createStablePackageJestConfig({
Expand All @@ -10,24 +9,5 @@ module.exports = createStablePackageJestConfig({
tsconfig: './tsconfig.test.json',
collectCoverageFrom: ['src/**/*.ts', '!**/type/**'],
coveragePathIgnorePatterns: ['node_modules', '__tests__', 'interface.ts', '.d.ts', 'typings', 'type.ts'],
moduleNameMapper: {
'^@visactor/vrender-kits/(.*)$': path.resolve(__dirname, '../vrender-kits/src/$1'),
'^@visactor/vrender-kits$': path.resolve(__dirname, '../vrender-kits/src/index.ts'),
'^@visactor/vrender-core/event/constant$': path.resolve(__dirname, '../vrender-core/src/event/public-constant.ts'),
'^@visactor/vrender-core/render/draw-interceptor$': path.resolve(
__dirname,
'../vrender-core/src/render/contributions/render/draw-interceptor.ts'
),
'^@visactor/vrender-core/render/symbol$': path.resolve(
__dirname,
'../vrender-core/src/render/contributions/render/symbol.ts'
),
'^@visactor/vrender-core/(.*)$': path.resolve(__dirname, '../vrender-core/src/$1'),
'^@visactor/vrender-core$': path.resolve(__dirname, '../vrender-core/src/index.ts'),
'^@visactor/vrender/es/core$': path.resolve(__dirname, '../vrender/src/index.ts'),
'^@visactor/vrender/es/register$': path.resolve(__dirname, '../vrender/src/register.ts'),
'^@visactor/vrender/es/kits$': path.resolve(__dirname, '../vrender/src/kits.ts'),
'^@visactor/vrender-animate/(.*)$': path.resolve(__dirname, '../vrender-animate/src/$1'),
'^@visactor/vrender-animate$': path.resolve(__dirname, '../vrender-animate/src/index.ts')
}
moduleNameMapper: require('../../share/jest-config/source-module-name-mapper')
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
declare const require: any;
export {};

const fs = require('fs');
const path = require('path');
const process = require('process');
const packageRoot = process.cwd();

function readArtifact(relativePath: string) {
return fs.readFileSync(path.join(packageRoot, relativePath), 'utf8');
}

describe('vrender-core published container compatibility', () => {
test('es artifacts should expose legacy container compatibility surface', () => {
expect(readArtifact('es/modules.js')).toContain('export const container');
expect(readArtifact('es/modules.d.ts')).toContain('container');
expect(readArtifact('es/index.d.ts')).toContain("from './modules'");
expect(readArtifact('es/index.d.ts')).toContain('container');
});

test('cjs root export should expose container as the legacy binding context', () => {
const vrenderCore = require(path.join(packageRoot, 'cjs/index.js'));

expect(vrenderCore.container).toBe(vrenderCore.getLegacyBindingContext());
});
});
81 changes: 81 additions & 0 deletions packages/vrender-core/__tests__/artifacts/root-esm-exports.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* @jest-environment node
*/

declare const __dirname: string;
declare const require: any;
export {};

const fs = require('fs');
const path = require('path');
const packageRoot = path.resolve(__dirname, '../..');

describe('vrender-core published root exports', () => {
test('keeps BytePack-sensitive root runtime exports explicit in the ESM artifact', () => {
const artifact = fs.readFileSync(path.join(packageRoot, 'es/index.js'), 'utf8');
const explicitExports = new Set<string>();
const exportPattern = /export\s+\{([^}]+)\}/g;
let match: RegExpExecArray | null;

while ((match = exportPattern.exec(artifact))) {
match[1]
.split(',')
.map((item: string) => item.trim())
.filter(Boolean)
.forEach((specifier: string) => {
const exportedName = specifier.match(/\s+as\s+([A-Za-z0-9_$]+)$/)?.[1] ?? specifier;
explicitExports.add(exportedName.trim());
});
}

const expectedExplicitRuntimeExports = [
'CustomEvent',
'CustomPath2D',
'GradientParser',
'IContainPointMode',
'Symbol',
'builtInSymbolStrMap',
'builtinSymbols',
'builtinSymbolsMap',
'container',
'createArc',
'createArc3d',
'createArea',
'createGlyph',
'createGroup',
'createImage',
'createLine',
'createPath',
'createPolygon',
'createPyramid3d',
'createRect',
'createRect3d',
'createRichText',
'createSymbol',
'createText',
'getRichTextBounds',
'getTextBounds',
'graphicCreator',
'isBrowserEnv',
'mapToCanvasPointForCanvas',
'matrixAllocate',
'registerDirectionalLight',
'registerGlobalEventTransformer',
'registerHtmlAttributePlugin',
'registerOrthoCamera',
'registerReactAttributePlugin',
'registerViewTransform3dPlugin',
'registerWindowEventTransformer',
'transformPointForCanvas',
'vglobal',
'waitForAllSubLayers'
];

expect(expectedExplicitRuntimeExports.filter(name => !explicitExports.has(name))).toEqual([]);

expect(artifact).toContain('export { Symbol, createSymbol } from "./graphic/symbol"');
expect(artifact).toContain(
'export { builtInSymbolStrMap, builtinSymbols, builtinSymbolsMap } from "./graphic/builtin-symbol"'
);
});
});
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
declare const require: any;
export {};

const fs = require('fs');
const path = require('path');
const process = require('process');

const packageRoot = process.cwd();

function readArtifact(relativePath: string) {
return fs.readFileSync(path.join(packageRoot, relativePath), 'utf8');
}

describe('vrender-core container compatibility', () => {
test('application should use realm-level shared state for duplicated ESM entry evaluation', () => {
const { application } = require(path.join(packageRoot, 'src/application'));
Expand All @@ -19,17 +14,4 @@ describe('vrender-core container compatibility', () => {
expect(state).toBeDefined();
expect(state.application).toBe(application);
});

test('es artifacts should expose legacy container compatibility surface', () => {
expect(readArtifact('es/modules.js')).toContain('export const container');
expect(readArtifact('es/modules.d.ts')).toContain('container');
expect(readArtifact('es/index.d.ts')).toContain("from './modules'");
expect(readArtifact('es/index.d.ts')).toContain('container');
});

test('cjs root export should expose container as the legacy binding context', () => {
const vrenderCore = require(path.join(packageRoot, 'cjs/index.js'));

expect(vrenderCore.container).toBe(vrenderCore.getLegacyBindingContext());
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -77,72 +77,4 @@ describe('vrender-core public subpath exports', () => {

expect(packageJson.typesVersions?.['*']).toEqual(expectedTypesVersions);
});

test('keeps BytePack-sensitive root runtime exports explicit in the ESM artifact', () => {
const artifact = fs.readFileSync(path.join(packageRoot, 'es/index.js'), 'utf8');
const explicitExports = new Set<string>();
const exportPattern = /export\s+\{([^}]+)\}/g;
let match: RegExpExecArray | null;

while ((match = exportPattern.exec(artifact))) {
match[1]
.split(',')
.map((item: string) => item.trim())
.filter(Boolean)
.forEach((specifier: string) => {
const exportedName = specifier.match(/\s+as\s+([A-Za-z0-9_$]+)$/)?.[1] ?? specifier;
explicitExports.add(exportedName.trim());
});
}

const expectedExplicitRuntimeExports = [
'CustomEvent',
'CustomPath2D',
'GradientParser',
'IContainPointMode',
'Symbol',
'builtInSymbolStrMap',
'builtinSymbols',
'builtinSymbolsMap',
'container',
'createArc',
'createArc3d',
'createArea',
'createGlyph',
'createGroup',
'createImage',
'createLine',
'createPath',
'createPolygon',
'createPyramid3d',
'createRect',
'createRect3d',
'createRichText',
'createSymbol',
'createText',
'getRichTextBounds',
'getTextBounds',
'graphicCreator',
'isBrowserEnv',
'mapToCanvasPointForCanvas',
'matrixAllocate',
'registerDirectionalLight',
'registerGlobalEventTransformer',
'registerHtmlAttributePlugin',
'registerOrthoCamera',
'registerReactAttributePlugin',
'registerViewTransform3dPlugin',
'registerWindowEventTransformer',
'transformPointForCanvas',
'vglobal',
'waitForAllSubLayers'
];

expect(expectedExplicitRuntimeExports.filter(name => !explicitExports.has(name))).toEqual([]);

expect(artifact).toContain('export { Symbol, createSymbol } from "./graphic/symbol"');
expect(artifact).toContain(
'export { builtInSymbolStrMap, builtinSymbols, builtinSymbolsMap } from "./graphic/builtin-symbol"'
);
});
});
3 changes: 3 additions & 0 deletions packages/vrender-core/jest.artifacts.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { createArtifactPackageJestConfig } = require('../../share/jest-config/create-package-config');

module.exports = createArtifactPackageJestConfig();
Loading
Loading